Steps to build and upload to PyPI - jasper-tms/npimage GitHub Wiki

This page contains the (very standard) commands I run to build this package and upload it to PyPI.

Prerequisites

A pyproject.toml file that specifies your package's information. See PEP621 for a description of how to build a pyproject.toml. (If this is your first time doing this, you can get started most easily by copy-pasting the example pyproject.toml file and editing it.)

Build

After committing any code changes, update the version number in pyproject.toml according to the semver.org guidelines and commit that change. Then:

# Activate an environment has updated versions of `build` and `twine`
# (You'll need to create this environment using conda or virtualenvs if you haven't yet)
workon pypi
pip install --upgrade pip build twine

python -m build

(Optional) Upload to testpypi and verify functionality

Click to view optional steps

After python -m build has completed successfully, run

twine upload -r testpypi dist/*

to upload to the testpypi server. Then make a fresh python environment to test the package you just uploaded

# mkvirtualenv is a command from virtualenvwrapper – if you use conda
# or something else, use whatever command makes a new environment
mkvirtualenv test-npimage

# Some requirements may not exist on testpypi, so you may first
# need to install requirements from standard PyPI via a command like:
pip install -r requirements.txt  # If your package has a requirements.txt file
pip install numpy scipy blah blah blah  # If you want/need to explicitly list the requirements

# Then install your new testpypi package into the environment
pip install -i https://test.pypi.org/simple/ numpyimage

and test the changes in python

import npimage
blah = npimage.do_something()

After verifying the new package works as expected, you're good to go to upload it to standard PyPI (see next section).

Upload to PyPI

Just run

twine upload dist/*

and enter your PyPI account token.

Bookkeeping

Finally, mark the release on Github through New release


Configure GitHub to automatically run the workflow above steps

If you add a publish.yml to your github repo in the folder .github/workflows/ that looks like this example, GitHub will do the steps above automatically. You can configure this action to trigger on whatever event you want, but the example triggers any time a change to pyproject.toml is pushed. If that change involved a change in the version number, the action will succeed and a new version of the package will appear automatically on PyPI. (If that change didn't involve a change in version number, the action will harmlessly fail.)

⚠️ **GitHub.com Fallback** ⚠️