This file defines the canonical coding directives for this repository.
If other instruction files exist (Copilot, IDE rules, contributor docs) and conflict with this file, follow this file and treat the others as stale.
- Primary language: Python
- Target runtime: Python 3.12
- Dependency / execution tool:
uv - Project-root is the directory containing this file (and
.git/, and.gitignore).
- Assume user is in the project-root directory.
- Do not use
pythonto run scripts. - Run a script via:
uv run ./path_to_script.py --help - Run tests via:
uv run ./run_tests.py- Note that
run_tests.pyhas usage instructions about how to run more granular tests.
- Note that
- Run django management scripts via:
uv run ./manage.py THE-COMMAND
- Use Python 3.12 type hints everywhere (functions and important variables).
- Prefer builtin generics (e.g.,
list[str],dict[str, int]) overtyping.List/typing.Dict. - Prefer PEP 604 unions (e.g.,
str | None) overOptional[str]. - Avoid
typingandannotationsimports unless strictly necessary.
- Structure runnable modules as:
def main() -> None: ...if __name__ == '__main__': main()
- Keep
main()simple: parse args / orchestrate calls only. - Put real logic into top-level helper functions and modules (no nested function definitions).
- Prefer single-return functions (use local variables and a final return).
- Do not define functions inside other functions.
- Favor clarity and explicitness over cleverness.
- Use
httpxfor all HTTP calls. - Do not introduce alternate HTTP libraries (e.g.,
requests,aiohttp) unless the repository already depends on them and there is a documented reason.
- Use triple-quoted docstrings.
- Write docstrings in present tense, with triple-quotes on their own lines.
- Good:
""" Parses ... """ - Avoid:
"""Parse ..."""
- Good:
- Start test-function docstring-text with "Checks..."
- For header-comments, in functions, start the comment with two hashes (e.g.,
## does this).
- inspect the
/ruff.tomlfor additional coding directives, such asmax-line-lengthandquote-style.
project/app/views.pyshould contain only view functions that directly handle URL endpoints.- Every view function in
project/app/views.pyshould correspond to an entry inpdf_checker_project/config/urls.py. - Views should act as manager/orchestrator functions:
- Parse request input (query params, POST body, files)
- Perform minimal validation and shaping of inputs
- Delegate substantive work to modules under
project/app/lib/ - Convert returned results into the appropriate
HttpResponse(HTML, JSON, redirects)
- Put domain logic, integrations, and reusable operations in
project/app/lib/(not inviews.py). - If multiple endpoints share logic, move that shared logic into
project/app/lib/and keep each view thin. - Prefer pure, testable functions in
project/app/lib/that accept plain Python values (not Django request objects) unless passing the request is necessary for a narrow, well-justified reason.
views.pyshould primarily import:- Django primitives (
HttpRequest,HttpResponse,render,redirect, etc.) - The minimal set of functions/classes from
project/app/lib/needed for each endpoint
- Django primitives (
- Avoid creating a secondary abstraction layer inside
views.py(no view-helper utilities); place helpers inproject/app/lib/.
- Use the standard library
unittestframework (not pytest) for non-Django projects. - Use Django's test framework for Django projects.
- New behavior should usually come with a focused test covering:
- the happy path
- at least one failure / edge case
When implementing a change (especially from an issue/task):
- Read relevant surrounding code and match existing conventions.
- Make the smallest correct change that satisfies the request.
- Update tests and run:
uv run ./run_tests.py - If you cannot run tests in your environment, still write/adjust tests and state what you would run.
- Do not ask questions unless absolutely necessary to proceed.
- Make reasonable assumptions, state them explicitly, then implement.
- If blocked, provide:
- what you tried
- what you found in the repo
- a concrete next step (command, file to edit, or minimal decision needed)
In
/.github/copilot-instructions.md, I've added:Follow `/AGENTS.md` as the repository source of truth for coding conventions and commands.