This project has been set up to quickly and easily set up a new Python package project instead of copying and modifying files from previous projects every time. For this we use Copier, which will configure your project based on a questionnaire.
- โป๏ธ GitHub Actions for continuous integration and publishing to PyPI
- ๐ฆ Poetry for dependency management and packaging
- ๐ก๏ธ Thrusted publishers for PyPI releases
- ๐ณ Dev Containers for easy development in VS Code
- โฌ๏ธ Renovate Bot for dependency updates
- โ mypy for static type checking
- ๐งช Pytest for testing and code coverage
- โ๏ธ Ruff for linting and code formatting
- And much more!
Ensure you have copier installed via pipx
:
pipx install copier
Decide where you want to create your new project, run the following command and answer all the questions:
copier copy --trust gh:klaasnicolaas/pypackage-template ~/path/to/destination
Or if you want to use the latest version from the main branch:
copier copy --trust --vcs-ref=HEAD gh:klaasnicolaas/pypackage-template ~/path/to/destination
A GitHub workflow is included that will automatically publish the packaged work to PyPI when a new release is created. To support this, there are some things you need to set up first.
- Create and verify an account on PyPI.
- Add a Trusted Publisher to your PyPI account.
- Create an Environment in the GitHub repository settings and name it "
release
".
Now, when you create a new release from your repository, a workflow will run and deploy the code to PyPI.
With every commit push to a pull request, a GitHub workflow will automatically run unit tests and output code coverage into an xml file. To easily see if code coverage is changing as a result of new work, you should install the GitHub app: Codecov.
- Go to the Codecov app page - https://github.com/apps/codecov
- Click Configure
- Select your repository and follow the instructions
- Add the
CODECOV_TOKEN
secret to your repository secrets, you can find the token on the Codecov app page (required since v4.x).
Future pull requests and commits will now include code coverage information.
Renovate checks if updates are available for dependencies and will update them automatically via a pull request. If your repository is set up correctly for auto-merging, the pull request will also be merged automatically.
- Go to the Renovate Bot app page - https://github.com/apps/renovate
- Click Configure
- Select your repository and follow the instructions
After this Renovate will create a GitHub issue in your repository which serves as a dashboard, you can see here which updates are pending and trigger Renovate to check again.
Automatically generate release notes with the Release Drafter workflow. This uses the labels from issues and pull requests to draft pretty and detailed release notes for your GitHub releases.
Future boilerplate updates can be as simple as:
copier update --trust --skip-answered
In case you want to update your answers to the questions as well as update:
copier update --trust
This Python template project relies on Poetry as its dependency manager, providing comprehensive management and control over project dependencies.
You need at least:
- Python 3.11+
- Poetry
Install all packages, including all development requirements:
poetry install
This will also generate a poetry.lock
file, you should track this file in version control. Check out the Poetry documentation for more information on the available commands.
This project uses pre-commit to run some checks before committing code. To install the pre-commit hooks, run the following command:
poetry run pre-commit install
The pyproject.toml file of the template has a jinja2 extension and is therefore not seen by Renovate bot to update automatically. That's why I keep track of the dependencies separately in a Gist and a workflow will check every week if anything needs to be adjusted.
Distributed under the MIT License. See LICENSE
for more information.