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
- Black for code formatting
- mypy for static type checking
- pytest for testing with code coverage
- Ruff for linting
- And much more!
Assuming you have already correctly installed Copier.
Choose where you would like to create your new project, run the following and answer the questions.
copier 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 Environments in the GitHub repository settings. Name it "
release
", choose selected branches and add a deployment branch rule formain
andv*
.
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
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.
The project uses Poetry for dependencies management and packaging. Make sure you have it installed in your development machine. To install the development dependencies in a virtual environment, type:
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 in the poetry environment:
pre-commit install
If you would like to test locally with copier to see what the output is, you can use the command below. So that you can be sure that it takes all changes into account.
copier -r HEAD ./ path/to/destination
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.