Skip to content

Commit befc54a

Browse files
authored
Merge branch 'dev' into feature/add-github-actions
2 parents 2a92a48 + d5e9166 commit befc54a

File tree

4 files changed

+125
-6
lines changed

4 files changed

+125
-6
lines changed

.pre-commit-config.yaml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ repos:
88
- id: trailing-whitespace
99
- id: end-of-file-fixer
1010
- id: check-yaml
11+
- id: check-merge-conflict
12+
- id: debug-statements
1113

1214
- repo: https://github.com/asottile/pyupgrade
1315
rev: v3.17.0
@@ -37,14 +39,41 @@ repos:
3739
hooks:
3840
- id: mypy
3941
args: ["--strict"]
40-
# ignoring everything for now
41-
exclude: .
42-
additional_dependencies: [django-stubs, celery, django-environ, django-extensions, django-crispy-forms,
43-
crispy-bootstrap5, django-allauth, django-celery-beat, djangorestframework, djangorestframework-datatables,
44-
django-debug-toolbar, psycopg2-binary, python-slugify, xmltodict, PyGithub, boto3, scrapy, types-requests]
42+
exclude: "."
43+
additional_dependencies:
44+
- django-stubs
45+
- celery
46+
- django-environ
47+
- django-extensions
48+
- django-crispy-forms
49+
- crispy-bootstrap5
50+
- django-allauth
51+
- django-celery-beat
52+
- djangorestframework
53+
- djangorestframework-datatables
54+
- django-debug-toolbar
55+
- psycopg2-binary
56+
- python-slugify
57+
- xmltodict
58+
- PyGithub
59+
- boto3
60+
- scrapy
61+
- types-requests
62+
63+
- repo: https://github.com/PyCQA/bandit
64+
rev: '1.7.0'
65+
hooks:
66+
- id: bandit
67+
args: ['-r', '--configfile=bandit-config.yml']
68+
69+
- repo: https://github.com/zricethezav/gitleaks
70+
rev: 'v8.0.4'
71+
hooks:
72+
- id: gitleaks
73+
args: ['--config=gitleaks-config.toml']
74+
4575

4676

47-
# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
4877
ci:
4978
autoupdate_schedule: weekly
5079
skip: []

CODE_STANDARDS.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Coding Standards and Conventions for COSMOS
2+
3+
## Overview
4+
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.
5+
6+
## Coding Standards
7+
8+
### Formatting Standards
9+
- **Line Length**: Maximum of 120 characters per line to ensure readability across various environments.
10+
- **Code Formatting**: Utilize tools like Black for Python code to ensure consistent formatting across the entire codebase.
11+
- **Import Ordering**: Follow a consistent import order:
12+
- Standard library imports.
13+
- Third-party imports.
14+
- Application-specific imports.
15+
16+
### Naming Conventions
17+
- **Variables and Functions**: Use `snake_case`.
18+
- **Classes and Exceptions**: Use `CamelCase`.
19+
- **Constants**: Use `UPPER_CASE`.
20+
21+
### Commenting
22+
- Inline comments should be used sparingly and only when necessary to explain "why" something is done, not "what" is done.
23+
- All public methods, classes, and modules should include docstrings that follow the [Google style guide](https://google.github.io/styleguide/pyguide.html).
24+
25+
### Error Handling
26+
- Explicit is better than implicit. Raise exceptions rather than returning None or any error codes.
27+
- Use custom exceptions over generic exceptions when possible to make error handling more predictive.
28+
29+
## Tool Configurations and Pre-commit Hooks
30+
31+
To automate and enforce these standards, the following tools are configured with pre-commit hooks in our development process:
32+
33+
### Pre-commit Hooks Setup
34+
35+
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:
36+
37+
```bash
38+
pip install pre-commit
39+
pre-commit install
40+
pre-commit run --all-files
41+
```
42+
43+
The following pre-commit hooks are configured:
44+
45+
- trailing-whitespace, end-of-file-fixer, check-yaml, check-merge-conflict, debug-statements: Checks for common formatting issues.
46+
- pyupgrade: Automatically upgrades syntax for newer versions of the language.
47+
- black: Formats Python code to ensure consistent styling.
48+
- isort: Sorts imports alphabetically and automatically separated into sections.
49+
- flake8: Lints code to catch styling errors and potential bugs.
50+
- mypy: Checks type annotations to catch potential bugs.
51+
- bandit: Scans code for common security issues.
52+
- gitleaks: Prevents secrets from being committed to the repository.
53+
- hadolint: Lints Dockerfiles to ensure best practices and common conventions are followed.
54+
55+
## Continuous Integration (CI)
56+
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.
57+
58+
## Quality Standards Enforcement
59+
- PRs must pass all checks from the configured pre-commit hooks and CI pipeline to be eligible for merging.
60+
- Code reviews additionally focus on logical errors and code quality beyond what automated tools can detect.
61+
62+
## Conclusion
63+
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.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ $ pip install pre-commit
225225
$ pre-commit install
226226
$ pre-commit run --all-files
227227
```
228+
For detailed information on the coding standards and conventions we enforce, please see our [Coding Standards and Conventions](CODE_STANDARDS.md).
228229

229230
### Sentry Setup
230231

bandit-config.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# bandit-config.yml
2+
skips:
3+
- B101 # Skip assert used (often used in tests)
4+
- B403 # Skip import from the pickle module
5+
6+
exclude:
7+
- ./tests/ # Exclude test directories
8+
- ./migrations/ # Exclude migration directories
9+
- ./venv/ # Exclude virtual environment
10+
11+
tests:
12+
- B105 # Include test for hardcoded password strings
13+
- B602 # Include test for subprocess call with shell equals true
14+
15+
profiles:
16+
default:
17+
include:
18+
- B403 # Include test for dangerous default argument
19+
exclude:
20+
- B401 # Exclude test for import telnetlib
21+
22+
# Set the severity level to focus on higher-risk issues
23+
severity: 'HIGH'
24+
25+
# Set the confidence level to ensure that reported issues are likely true positives
26+
confidence: 'HIGH'

0 commit comments

Comments
 (0)