Stmdency will release to PyPI, Python Package Index, is a repository of software for the Python programming language.
We use build to build package, and twine to upload package to PyPi. You could first install and upgrade them by:
python3 -m pip install --upgrade pip build twine
It is highly recommended releasing package to TestPyPi first, to check whether the package is correct, and then release to PyPi.
TestPyPi is a test environment of PyPi, you could release to it to test whether the package is work or not.
- Create an account in TestPyPi.
- Clean unrelated files in
dist
directory, and build packagepython3 setup.py clean
. - Build package
python3 -m build
, and you will see two new files indist
directory, with extension.tar.gz
and.whl
. - Upload to TestPyPi
python3 -m twine upload --repository testpypi dist/*
. - Check the package in TestPyPi and install it
by
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps stmdency
to test whether it is work or not.
After you check the package in TestPyPi is correct, you can directly tag the commit and push it to GitHub, then GitHub Actions will automatically release to PyPi based on the tag event. You can see more detail in pypi-workflow.yml.
# Preparation
VERSION=<VERSION>
git checkout -b "${VERSION}"
# For macOS
sed -i '' "s/__version__ = \".*\"/__version__ = \"${VERSION}\"/" src/stmdency/__init__.py
# For Linux
sed -i "s/__version__ = \".*\"/__version__ = \"${VERSION}\"/" src/stmdency/__init__.py
git commit -am "Release v${VERSION}"
# Tag & Auto Release in GitHub Actions
git tag -a "${VERSION}" -m "Release stmdency v${VERSION}"
git push tags/"${VERSION}"
There is an official way to package project from PyPA