A minimal template for creating a pypi package using poetry and github actions
This template allows the creation of python projects managed by poetry to be submitted to PyPi. All the github actions have been setup too. The github actions run tests on every push and also creates and new pacakage and pushes to the pypi when a merge happens to the release branch.
Just follow the seteps below for an hassle free setup of the project.
- Click here to create a new repo (you need to be logged in to GitHub for this link to work), and follow the instructions to create a new repo from this template.
git clone
your new repo
- activate your environment.
- install poetry
python -m pip install poetry
- Insert/Update the values in the
pyproject.toml
undertool.poetry
- Dont forget to update the desired python version under the
tool.poetry.dependencies
- Dont forget to modify the release branch under
tool.semantic_release
(assumption ismain
is the release branch) - add project dependancies. eg - if you want
numpy
as an dependancy simply runpoetry add numpy
- install the dependancies by running
poetry install
- More information on setting up a project with poetry
- Create a project folder. eg.
hapi_pypi
here - add all the code/implemenations in the folder.
- Check the functionality of the project folder by implementing tests.
- Implement tests in the
tests
folder. - All the tests should pass when you run the command
poetry run pytest tests/
- Details on how to implement tests with pytest.
- all the github actions are defined in the
.github/workflows
folder - setup the
test.yml
. Update the env variables according to the project setup before. The default coverage limit is set to 90% ie the test will fail below the coverage of 90.
env:
PYTHON_VERSION: "3.8.5"
PROJECT_FOLDER: hapy_pypi
TEST_FOLDER: tests
COVERAGE_LIMIT: 90
- setup the similar env variables in
release.yml
as well.
These secrets are used to push releases to the pypi repository.
- Generate a pypi api token
- Set Repo Secrets
- Add
PYPI_USER
as__token__
- Add
PYPI_TOKEN
as the token from above step including thepypi-
prefix
This secret is required to generate the CHANGELOG.MD
and update the version by SemRel.
- Generate a github token
- Set Repo Secrets
- Add
GH_TOKEN
as the token from github.