Sample PyPI package + GitHub Actions + Versioneer
This template aims to automate the tedious and error-prone steps of tagging/versioning, building and publishing new package versions. This is achieved by syncing git tags and versions with Versioneer, and automating the build and release with GitHub Actions, so that publishing a new version is as painless as:
$ git tag vX.Y.Z && git push --tags
The following guide assumes familiarity with setuptools and PyPI. For an introduction to Python packaging, see the references at the bottom.
How to use this template
-
Click on the Use this template button to get a copy of this repository.
-
Rename src/sample_package folder to your package name — src/ is where your package must reside.
-
Go through each of the following files and rename all instances of sample-package or sample_package to your package name. Also update the package information such as author names, URLs, etc.
- setup.py
- pyproject.toml
- __init__.py
-
Install
versioneerandtomli, and runversioneer:$ pip install tomli $ pip install versioneer $ versioneer install
Then commit the changes produced by
versioneer. See here to learn more. -
Setup your PyPI credentials. See the section Saving credentials on Github of this guide. You should use the variable names
TEST_PYPI_API_TOKENandPYPI_API_TOKENfor the TestPyPI and PyPI tokens, respectively. See .github/workflows/release.yaml.
You are all set! It should now be possible to run git tag vX.Y.Z && git push --tags to automatically version, build and publish a new release to PyPI.
Finally, it is a good idea to configure tag protection rules in your repository.
References
- Python packaging guide: https://packaging.python.org/en/latest/tutorials/packaging-projects/
- ...and how things are changing: https://snarky.ca/what-the-heck-is-pyproject-toml/ — in particular, note that while pyproject.toml seems to be the future, currently Versioneer still depends on setup.py.
- Versioneer: https://github.com/python-versioneer/python-versioneer
- GitHub Actions: https://docs.github.com/en/actions
Metadata
Release files for sample-package-chanshing 0.0.0.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sample-package-chanshing-0.0.0.post1.tar.gz | 24.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sample_package_chanshing-0.0.0.post1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.2 kB
Release files / sample-package-chanshing-0.0.0.post1.tar.gz
| Download URL | sample-package-chanshing-0.0.0.post1.tar.gz |
|---|---|
| Size | 24.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
750c1a9b373d9a2f683e48c0c9f98f0e5c085a2081fd54865d1379c56827fc02
|
|
BLAKE2b-256 checksum How to use checksums |
a9a8976aea4218ca9879c2135b6e41798280c0a6a621cffe647bdccd5d9af468
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / sample_package_chanshing-0.0.0.post1-py3-none-any.whl
| Download URL | sample_package_chanshing-0.0.0.post1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb9504cc6a4184e126dbb7fdc6981302f7f0bbaa0bbb6c3744ffa839c17632d2
|
|
BLAKE2b-256 checksum How to use checksums |
e30af7c37511aa1c35382b5e157c072d6542bd8ff24f1ab1c8536cdac2a9e4c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|