Cookiecutter template for a Python package based on the Hypermodern Python article series.
cookiecutter https://github.com/cjolowicz/cookiecutter-hypermodern-python- Packaging and dependency management with Poetry
- Test automation with Nox
- Continuous integration with GitHub Actions
- Documentation with Sphinx and Read the Docs
- Automated uploads to PyPI and TestPyPI
- Automated release notes with Release Drafter
- Code formatting with Black and Prettier
- Testing with Pytest
- Code coverage with Coverage.py
- Coverage reporting with Codecov
- Command-line interface with Click
- Linting with Flake8 and various awesome plugins
- Static type-checking with mypy and pytype
- Runtime type-checking with Typeguard
- Security audit with Bandit and Safety
- Git hook management with pre-commit
- Check documentation examples with xdoctest
- Generate API documentation with autodoc, napoleon, and sphinx-autodoc-typehints
The template supports Python 3.6, 3.7, and 3.8.
The linter suite uses the following tools and Flake8 plugins:
- darglint to detect inaccurate docstrings
- flake8-annotations to enforce type coverage
- flake8-bandit for integration with Bandit
- flake8-black for integration with Black
- flake8-bugbear to detect bugs and design problems
- flake8-docstrings for integration with pydocstyle
- flake8-import-order to check the order of import statements
- mccabe to limit the code complexity
- pep8-naming to enforce naming conventions from PEP 8
- pycodestyle to enforce style conventions from PEP 8
- pydocstyle to enforce docstring conventions from PEP 257
- pyflakes to find invalid Python code
Install Poetry:
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | pythonInstall Nox:
pip install --user --upgrade noxInstall the latest Cookiecutter:
pip install --user --upgrade cookiecutterIt is also recommended to use pyenv to set up Python 3.6, 3.7, and 3.8.
Generate a Python project:
cookiecutter https://github.com/cjolowicz/cookiecutter-hypermodern-pythonChange to the root directory of your new project.
Run the full test suite:
noxList the available Nox sessions:
nox --list-sessions- Sign up at PyPI.
- Go to the Account Settings on PyPI, generate an API token, and copy it.
- Go to the repository settings on GitHub,
and add a secret named
PYPI_TOKENwith the token you just copied.
- Sign up at TestPyPI.
- Go to the Account Settings on TestPyPI, generate an API token, and copy it.
- Go to the repository settings on GitHub,
and add a secret named
TEST_PYPI_TOKENwith the token you just copied.
- Sign up at Codecov, and install their GitHub app.
- Add your repository to Codecov.
- Sign up at Read the Docs.
- Import your GitHub repository, using the button Import a Project.
- Bump the version using
poetry version. Push to GitHub. - Publish a GitHub Release.
- GitHub Action triggers the PyPI upload.
Release notes are pre-filled with titles and authors of merged pull requests.
Use labels to group the pull requests into sections:
| Label | Section |
|---|---|
breaking |
💥 Breaking Changes |
bug |
🪲 Fixes |
build |
📦 Build System and Dependencies |
ci |
👷 Continuous Integration |
documentation |
📚 Documentation |
enhancement |
🚀 Features |
performance |
🐎 Performance |
refactoring |
🔨 Refactoring |
removal |
🔥 Removals and Deprecations |
style |
💄 Style |
testing |
🚨 Testing |
GitHub creates the bug, enhancement, and documentation labels for you.
Create the remaining labels on the Issues tab of your GitHub repository.
When upgrading Sphinx or its extensions using Poetry, also update the requirements located in docs/requirements.txt for Read the Docs.
The project setup is described in detail in the Hypermodern Python article series:
- Chapter 1: Setup
- Chapter 2: Testing
- Chapter 3: Linting
- Chapter 4: Typing
- Chapter 5: Documentation
- Chapter 6: CI/CD
You can also read the articles on my blog.
