Skip to content

Commit

Permalink
Commit-01
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 22, 2025
1 parent 99a72f4 commit 8392231
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 6 deletions.
47 changes: 41 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-merge-conflict
- id: debug-statements

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
Expand Down Expand Up @@ -37,14 +39,47 @@ repos:
hooks:
- id: mypy
args: ["--strict"]
# ignoring everything for now
exclude: .
additional_dependencies: [django-stubs, celery, django-environ, django-extensions, django-crispy-forms,
crispy-bootstrap5, django-allauth, django-celery-beat, djangorestframework, djangorestframework-datatables,
django-debug-toolbar, psycopg2-binary, python-slugify, xmltodict, PyGithub, boto3, scrapy, types-requests]
exclude: "."
additional_dependencies:
- django-stubs
- celery
- django-environ
- django-extensions
- django-crispy-forms
- crispy-bootstrap5
- django-allauth
- django-celery-beat
- djangorestframework
- djangorestframework-datatables
- django-debug-toolbar
- psycopg2-binary
- python-slugify
- xmltodict
- PyGithub
- boto3
- scrapy
- types-requests

- repo: https://github.com/PyCQA/bandit
rev: '1.7.0'
hooks:
- id: bandit
args: ['-r', '--configfile=bandit-config.yml']

- repo: https://github.com/zricethezav/gitleaks
rev: 'v8.0.4'
hooks:
- id: gitleaks
args: ['--config=gitleaks-config.toml']

- repo: local
hooks:
- id: hadolint
name: Lint Dockerfiles
entry: bash -c "docker run --rm -i hadolint/hadolint < /dev/stdin"
language: system
types: [dockerfile]

# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
ci:
autoupdate_schedule: weekly
skip: []
Expand Down
63 changes: 63 additions & 0 deletions CODE_STANDARDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Coding Standards and Conventions for COSMOS

## Overview
To maintain high-quality code and ensure consistency across the entire COSMOS project, we have established coding standards and conventions. This document outlines the key standards and practices that all contributors are expected to follow. Adhering to these guidelines helps us to achieve a codebase that appears as if it were written by a single entity, regardless of the number of contributors.

## Coding Standards

### Formatting Standards
- **Line Length**: Maximum of 120 characters per line to ensure readability across various environments.
- **Code Formatting**: Utilize tools like Black for Python code to ensure consistent formatting across the entire codebase.
- **Import Ordering**: Follow a consistent import order:
- Standard library imports.
- Third-party imports.
- Application-specific imports.

### Naming Conventions
- **Variables and Functions**: Use `snake_case`.
- **Classes and Exceptions**: Use `CamelCase`.
- **Constants**: Use `UPPER_CASE`.

### Commenting
- Inline comments should be used sparingly and only when necessary to explain "why" something is done, not "what" is done.
- All public methods, classes, and modules should include docstrings that follow the [Google style guide](https://google.github.io/styleguide/pyguide.html).

### Error Handling
- Explicit is better than implicit. Raise exceptions rather than returning None or any error codes.
- Use custom exceptions over generic exceptions when possible to make error handling more predictive.

## Tool Configurations and Pre-commit Hooks

To automate and enforce these standards, the following tools are configured with pre-commit hooks in our development process:

### Pre-commit Hooks Setup

To ensure that these tools are run automatically on every commit, contributors must set up pre-commit hooks locally. Run the following commands to install and configure pre-commit hooks:

```bash
pip install pre-commit
pre-commit install
pre-commit run --all-files
```

The following pre-commit hooks are configured:

- trailing-whitespace, end-of-file-fixer, check-yaml, check-merge-conflict, debug-statements: Checks for common formatting issues.
- pyupgrade: Automatically upgrades syntax for newer versions of the language.
- black: Formats Python code to ensure consistent styling.
- isort: Sorts imports alphabetically and automatically separated into sections.
- flake8: Lints code to catch styling errors and potential bugs.
- mypy: Checks type annotations to catch potential bugs.
- bandit: Scans code for common security issues.
- gitleaks: Prevents secrets from being committed to the repository.
- hadolint: Lints Dockerfiles to ensure best practices and common conventions are followed.

## Continuous Integration (CI)
When a commit is pushed to a branch that is part of a Pull Request, our Continuous Integration (CI) pipeline automatically runs specified tools to check code quality, style, security and other standards. If these checks fail, the PR cannot be merged until all issues are resolved.

## Quality Standards Enforcement
- PRs must pass all checks from the configured pre-commit hooks and CI pipeline to be eligible for merging.
- Code reviews additionally focus on logical errors and code quality beyond what automated tools can detect.

## Conclusion
By adhering to these standards and utilizing the tools set up, we maintain the high quality and consistency of our codebase, making it easier for developers to collaborate effectively.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ $ pip install pre-commit
$ pre-commit install
$ pre-commit run --all-files
```
For detailed information on the coding standards and conventions we enforce, please see our [Coding Standards and Conventions](CODE_STANDARDS.md).

### Sentry Setup

Expand Down
27 changes: 27 additions & 0 deletions bandit-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# bandit-config.yml
skips:
- B101 # Skip assert used (often used in tests)
- B403 # Skip import from the pickle module

exclude:
- ./tests/ # Exclude test directories
- ./migrations/ # Exclude migration directories
- ./venv/ # Exclude virtual environment

tests:
- B105 # Include test for hardcoded password strings
- B602 # Include test for subprocess call with shell equals true

profiles:
default:
include:
- B301 # Include test for pickle
- B403 # Include test for dangerous default argument
exclude:
- B401 # Exclude test for import telnetlib

# Set the severity level to focus on higher-risk issues
severity: 'HIGH'

# Set the confidence level to ensure that reported issues are likely true positives
confidence: 'HIGH'

0 comments on commit 8392231

Please sign in to comment.