31. Publishing on PyPI

Damian Cugley

As part of the mini-project of chopping up the overlong README in to the beginning of the user manual for Mismiy, it would be nice to simplify the installation instructions a bit. One way to help this would be to publish a working app to PyPI.

Pre-publication adminitrivia

There are a few details to tick off to make the package more useful.

Which Python versions?

As of 2026-11 Python 3.10 has just come to end-of-life and 3.15 is recently released. So it does not seem unreasonable to set the minimum Python version to 3.11.

Support runpy

The runpy module conventions allow python -m mismiy to work the same as the mismiy command.

Add a module __main__ that calls the command:

import sys
from .command import main

if __name__ == "__main__":
    sys.exit(main())

Support Pipx run and uvx

There are two ways to use an app with Pipx or uv:

  1. Install the package first with pipx install mismiy and then run the mismiy command as a normal command; or
  2. pipx run mismiy or uvx mismiy, which create a temporary environment to run the app in.

There can be some faff involved if the package name differs from the command name. Since Mismiy and its command have the same name this seems to work without extra work.

Setting up authentication

It’s been a while, so I had forgotten I have a PyPI account dating back to 2018. PyPI has more than one way to authenticate a publishing program (in this case Poetry). Poetry works best with the API token method. to upload to PyPI. This starts with Configuraing credentials.

You can do this without leaving a copy of the token lying about by typing this in to a terminal without pressing Return yet:

poetry config pypi-token.pypi $(pbpaste)

In the page for creating the new token, click the Copy Token button to copy the token to the clipboard and hit Return to run this command and stash it in system password stash. The macOS command pbpaste pastes the contents of the clipboard. On Linux you’d use xclip -o. The point is that this way the token itself is not recorded in the shell history or in a plain file on disk.

Testing

There is a test index TestPyPI that can be used to rehearse publication without cluttering up the real index. We can go through the same rigamarole to set up the authentication, from the TestPyPI API token page this time:

poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry config pypi-token.test-pypi $(pbpaste)

Now we can test-publish with these commands:

poetry version prepatch
poetry build
poetry publish -r test-pypi

Now we can test running it via Pipx and uv:

pipx run  -i https://test.pypi.org/simple/ \
    --pip-args=--extra-index-url=https://pypi.org/simple/ \
    mismiy --help
uvx --default-index https://test.pypi.org/simple/  \
    --index https://pypi.org/simple/ \
    mismiy --help

We have to supply extra index arguments. When installed on the real PyPI index, it should work with pipx run mismiy or uvx mismiy.

Checklist

We have a lot of ceremony around making releases at my day job. What’s the least amount of steps I can get away with without too much risk of a dud release?

Steps:

  1. Create a release branch release/0.3.0
  2. Run poetry version --next-phase a couple of times so the version is 0.3.0rc0
  3. Write a post describing the new version
  4. Read through README.md and CHANGELOG.md to check they are up to date
  5. Run the tests one more time
  6. poetry version --next-phase to set the version number to 0.3.0 & commit
  7. Merge branch in to main
  8. git tag $(poetry version -s)
  9. poetry build and poetry publish
  10. Merge branch in to develop & delete branch
  11. poetry version prepatch and add a new (Unreleased) heading to the changelog.

Posts on similar topics