This is a minimal Python 3.12 application that uses pip-tools for packaging and dependency management. It also provides pre-commit hooks (for for ruff and mypy) and automated tests using pytest and GitHub Actions. Pre-commit hooks are automatically kept updated with a dedicated GitHub Action, this can be removed and replace with pre-commit.ci if using an public repo. It was developed by the Imperial College Research Computing Service.
pip-tools is chosen as a lightweight dependency manager that adheres to the latest standards using pyproject.toml.
To use this repository as a template for your own application:
-
Click the green "Use this template" button above
-
Name and create your repository
-
Clone your new repository and make it your working directory
-
Replace instances of
myprojectwith your own application name. Edit:pyproject.toml(also change the list of authors here)tests/test_myproject.py- Rename
myprojectdirectory
-
Create and activate a Virtual Environment:
python -m venv .venv source .venv/bin/activate # with Powershell on Windows: `.venv\Scripts\Activate.ps1`
-
Install development requirements:
pip install -r dev-requirements.txt
-
Install the git hooks:
pre-commit install
-
Run the main app:
python -m myproject
-
Run the tests:
pytest
To add or remove dependencies:
- Edit the
dependenciesvariables in thepyproject.tomlfile (aim to keep develpment tools separate from the project requirements). - Update the requirements files:
pip-compileforrequirements.txt- the project requirements.pip-compile --extra dev -o dev-requirements.txtfordev-requirements.txt- the development requirements.
- Sync the files with your installation (install packages):
pip-sync dev-requirements.txt requirements.txt
To upgrade pinned versions, use the --upgrade flag with pip-compile.
Versions can be restricted from updating within the pyproject.toml using standard python package version specifiers, i.e. "black<23" or "pip-tools!=6.12.2"
All configuration can be customised to your preferences. The key places to make changes for this are:
- The
pyproject.tomlfile, where you can edit: - The
.pre-commit-config.yamlfor pre-commit settings. - The
.githubdirectory for all the CI configuration.- This repo uses
pre-commit.cito update pre-commit package versions and automatically merges those PRs with theauto-merge.ymlworkflow. - Note that
pre-commit.ciis an external service and free for open source repos. For private repos uncomment the commented portion of thepre-commit_autoupdate.ymlworkflow.
- This repo uses
The GitHub workflow includes an action to publish on release.
To run this action, uncomment the commented portion of publish.yml, and modify the steps for the desired behaviour (publishing a Docker image, publishing to PyPI, deploying documentation etc.)