This repository is a template repository providing boilerplate for Python library.
Developer can start writing code without wasting so much time to set up basic stuffs like CI, lint, etc.
We recommand to use GitHub's Use this template button to kick off this template.
But yet, you can set up copy this template by cloning or downloading this repository.
Once you prepared this repository on your local machine, remaining part is project configuration. Unless you are familiar with stacks(uv, tox, GitHub action, etc.), Subsequent Installation step might be helpful.
Please read this installation guide to install uv.
Then install package dependencies with this command at project root. This will resolve package dependencies and install it in uv managed virtual environment.
uv sync --group devpyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
As quoted pyenv readme demonstrates, It provide us handy python version management.
This file contains build system requirements and information, which are used by hatchling to build the package.
We tried to gather every package related settings as much as possible here.
Through this design decision, project could remove package dependant configuration files like pytest.ini, etc.
- [project]: Describe package's metadata following PEP 621. Including package name, versions, description, authors etc.
- [dependency-groups]: Manage dev dependencies following PEP 735.
- [build-system]: Define how to build package using hatchling. Generally no need to edit this section.
- [tool.ruff]: Linting and formatting configuration using ruff.
- [tool.pytest.ini_options]: pytest configuration.
Except [build-system], We suggest you to update every settings above.
We choose GitHub action as Continuous Integration tool. It contains package-build, unittest, and lint job. Each job works concurrently on different virtual machines.
- package-build: Use tox to test package against multiple python versions.
- unittest: Test code and report coverage using pytest.
- lint: Lint and format code using ruff.
Change python-version value in this file according to package compatible python versions which configured at pyproject.toml.
Tox runs test against packages which built in isolated virtual environment.
Uses tox-uv plugin for uv integration.
- [tox]: Tox global settings including uv-venv-lock-runner.
- [testenv]: Test environment setting.
According to package's python compatible versions, [tox.envlist] should be defined.
Make your own named package in src directory.
NOTE: package setting in pyproject.toml should be changed as you set up your own package.
[tool.hatch.build.targets.wheel]
packages = ["src/{your-python-package-name}"]Every test code should resides in tests package at project root.
To test your source code, simply use 'pytest' or 'tox'.
# Use pytest
$ uv run pytest tests/
# Use Tox
$ uv run toxDetailed explanation about stacks used in this template is covered in this section.
This template repository follows src layout style. As the name suggests, its distinctive feature is subdirectory named src.
Main python packages lives inside src directory.
To tests python built package. Testing should be done against built package. not from the source code itself. Src layout helps to achieve this condition. By separating source code from project root, It prevents test code to import source code.
This layout is better explained in this blog post by Ionel Cristian Mărieș.
We use uv to control dependencies and build package. uv is an extremely fast Python package and project manager, written in Rust.
By default, uv automatically manages virtual environment for each project. It frees developer from virtual environment management. For more information read the docs.
Our GitHub action consists of two workflows. one for CI, and one for release draft.
ci.yml workflow contains three different jobs. Those are package-build, unittest, lint.
- package-build job is responsible for build package and test it. so it uses tox and can have multiple python versions.
- unittest job is in charge of test on source code, and report test coverage.
- lint job processes every linting stuffs.
release_drafter.yml workflow is activated whenever master branch changed.
It tracks merged pull requests and generate release draft containing chagelog and contributors.
Release draft template can be modified by editing .github/release-drafter.yml file.
It demonstrates how draft should be presented.
Pytest is our main test runner.
Code is double-checked during development process. One at commit phase, and the other at CI process.
pre-commit is help us to check at commit time. By executing installation command pre-commit install,
It automatically adds pre commit hooks. Types of hook are managed using .pre-commit-config.yaml.
Coverage of test functions is one of important metrics which decides code quality.
ci.yml workflow runs unittest and reports coverage report on pull request comment.
We use orgoros's github action as our coverage component of our CI workflow.
Pull requests are always welcome.
Check CONTRIBUTING.md for more details.
Distributed under the terms of the MIT license.