Template repository for Python projects.
Setup a virtual environment venv and install the local development
requirements as follows:
python3 -m venv venv
source venv/bin/activate
python -m pip install -r requirements/local.txtpython -m toxpython -m tox -e py3python -m tox -e lintingThe repository is supported by a justfile. The easiest way to
install just is to first install cargo and then run cargo install just.
See these instructions for more information on installing cargo.
Once you have installed run just on its own to see all available commands.
Pre-commit can be used to provide more feedback before committing code. This reduces reduces the number of commits you might want to make when working on code, it's also an alternative to running tox manually.
To set up pre-commit, providing pip install has been run above:
pre-commit install
This repository contains a default number of pre-commit hooks, but there may be others suited to different projects. A list of other pre-commit hooks can be found here.
Pre-commit can be run by calling just pre-commit.
The justfile contains helper functions for packaging and release.
clean # Clean the package directory
package # Package
package-check # Check the distribution is valid
package-deps # Upgrade dependencies for packaging
package-source # Package the source code
package-upload # Upload package to pypi
package-upload-test # Upload package to test.pypiPackaging consumes the metadata in pyproject.toml which helps to describe
the project on the official pypi.org repository. Have a look at the
documentation and comments there to help you create a suitably descriptive
metadata file.
Versioning in Python can be quite hit and miss. You can label versions for yourself, but to make it reliaable, as well as meaningful is should be controlled by your source control system. We assume git, and versions can be created by tagging your work and pushing the tag to your git repository, e.g. to create a release candidate for version 1.0.0:
git tag -a 1.0.0-rc.1 -m "release candidate for 1.0.0"
git push origin 1.0.0-rc.1When you build, a package will be created with the correct version:
just package-source
### build process here ###
Successfully built python_repo_template-1.0.0rc1.tar.gz and python_repo_template-1.0.0rc1-py3-none-any.whlTo create a python wheel for testing locally, or distributing to colleagues run:
just package-source
A tar and whl file will be stored in a dist/ directory. The whl file
can be installed as follows:
pip install <your-package>.whl
Publishing for public use can be achieved with:
just package-upload-testorjust package-upload
just-package-upload-test will upload the package to test.pypi.org
which provides a way to look at package metadata and documentation and ensure
that it is correct before uploading to the official pypi.org
repository using just package-upload.