You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Create additional users through the admin interface (/admin).
71
+
## Database Backup and Restore
72
+
73
+
COSMOS provides dedicated management commands for backing up and restoring your PostgreSQL database. These commands handle both compressed and uncompressed backups and work seamlessly in both local and production environments using Docker.
72
74
73
-
### Loading Fixtures
75
+
### Backup Directory Structure
74
76
75
-
To load collections:
77
+
All backups are stored in the `/backups` directory at the root of your project. This directory is mounted as a volume in both local and production Docker configurations, making it easy to manage backups across different environments.
$ docker-compose -f local.yml run --rm django python manage.py shell
107
-
>>> from django.contrib.contenttypes.models import ContentType
108
-
>>> ContentType.objects.all().delete()
109
-
>>> exit()
148
+
docker-compose -f local.yml run --rm django python manage.py database_restore backups/backup_name.sql.gz
110
149
```
111
150
112
-
3. Load your backup database:
151
+
### Alternative Methods
152
+
153
+
While the database_backup and database_restore commands are the recommended approach, you can also use Django's built-in fixtures for smaller datasets:
docker-compose -f local.yml run --rm django python manage.py loaddata backups/backup_name.json
118
165
```
119
-
### Restoring the Database from a SQL Dump
120
-
If the JSON file is particularly large (>1.5GB), Docker might struggle with this method. In such cases, you can use SQL dump and restore commands as an alternative, as described [here](./SQLDumpRestoration.md).
121
-
122
166
167
+
Note: For large databases (>1.5GB), the database_backup and database_restore commands are strongly recommended over JSON fixtures as they handle large datasets more efficiently.
123
168
124
169
## Additional Commands
125
170
@@ -180,6 +225,7 @@ $ pip install pre-commit
180
225
$ pre-commit install
181
226
$ pre-commit run --all-files
182
227
```
228
+
For detailed information on the coding standards and conventions we enforce, please see our [Coding Standards and Conventions](CODE_STANDARDS.md).
183
229
184
230
### Sentry Setup
185
231
@@ -208,3 +254,24 @@ Eventually, job creation will be done seamlessly by the webapp. Until then, edit
208
254
- JavaScript: `/sde_indexing_helper/static/js`
209
255
- CSS: `/sde_indexing_helper/static/css`
210
256
- Images: `/sde_indexing_helper/static/images`
257
+
258
+
259
+
## Running Long Scripts on the Server
260
+
```shell
261
+
tmux new -s docker_django
262
+
```
263
+
Once you are inside, you can run dmshell or for example a managment command:
264
+
265
+
```shell
266
+
docker-compose -f production.yml run --rm django python manage.py deduplicate_urls
0 commit comments