How sourcery-ai/python-best-practices-cookiecutter works
Project type and purpose
• This is not a runtime application but a “cookiecutter” template project. Its purpose is to generate new Python projects that follow a set of best practices (testing, linting, formatting, CI/CD, Dockerization, etc.).
File structure
• Top‐level:
• cookiecutter.json – defines user‐prompted variables
• hooks/ – pre_generation and post_generation Python scripts
• LICENSE, README.md, cookiecutter.json
• Template folder “{{cookiecutter.repo_name}}/” contains:
• Configuration files (.coveragerc, .pre‐commit-config.yaml, setup.cfg, Pipfile, Dockerfile, .editorconfig, .dockerignore, .gitignore)
• CI workflows (.github/workflows/test.yml, publish-docker.yml)
• Code scaffold:
– {{repo_name}}/__main__.py and module file {{repo_name}}.py
– test/ directory with pytest starter
• Hooks scripts execute before and after project generation to customize or validate context.
README for additional insights
• Lists the best‐practices enforced: pytest, black, isort, mypy, flake8, pre-commit, Docker, GitHub Actions.
• Quickstart shows the user flow: pipx → cookiecutter → pipenv → pre-commit hooks → start coding.
Detailed capture of essential architectural elements
• In the generated side, show subcomponents: source package, tests, CI workflows, Dockerfile, pre-commit hooks.
• Decision points if any (e.g., conditional steps in hooks).