docs: package rules in code style — README, api, Django modules
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ddadcbd1a9
commit
06647e39c3
2 files changed
+48
No files matched your search
@@ -113,3 +113,27 @@ I leave code cleaner than I found it. There's no need to rewrite everything at o
|
||||
- Commit messages in the conventional commits format: `feat:`, `fix:`, `refactor:`, `docs:`, `chore:`.
|
||||
- Code that doesn't pass the linter and tests doesn't get into the main branch.
|
||||
- Secrets, keys and `.env` never get into the repository.
|
||||
|
||||
## 10. Packages
|
||||
|
||||
- **Every package has a `README.md`.** It says why the package exists and what problem it solves. You open the folder and understand what's inside without reading the code.
|
||||
- **The programming interface lives in an `api` module.** If other code uses the package, everything meant to be called from outside is collected in `api`. The rest of the package's modules are internal: other code doesn't reach into them, and I can change them without worrying about the package's users. If no code calls the package, it doesn't need `api`.
|
||||
|
||||
### Django packages
|
||||
|
||||
A Django app gets this set of modules:
|
||||
|
||||
- **`settings`, always.** The list of every setting the package understands, with defaults and documentation for each. Inside the package, settings are read only from here, not through `django.conf.settings` scattered across the code. To find out how to configure the package, one file is enough.
|
||||
- **`urls`, if the package has views.** The package's routes; the project plugs them in with `include()`.
|
||||
- **`api`, if other code calls the package.** Following the rule above.
|
||||
|
||||
```python
|
||||
# reports/settings.py
|
||||
from django.conf import settings
|
||||
|
||||
# How many days to keep generated reports. After that they are deleted.
|
||||
REPORTS_TTL_DAYS = getattr(settings, "REPORTS_TTL_DAYS", 30)
|
||||
|
||||
# Address that report emails are sent from.
|
||||
REPORTS_FROM_EMAIL = getattr(settings, "REPORTS_FROM_EMAIL", settings.DEFAULT_FROM_EMAIL)
|
||||
```
|
||||
Reference in new issue
Block a user