Skip to main content

python/deploy_to_pypi

1#!/usr/bin/env bash
2# Deploy a new version of a Python library:
3#
4# 1. Bump the version
5# 2. Tag the Git commit
6# 3. Push to PyPI and GitHub.
7#
8# This probably works for other projects as well, but relies on certain
9# aspects of the way the repos are laid out that may not be universal.
11# Note: unlike most Python scripts in this repo, this should run in
12# the project virtualenv rather than the script virtualenv.
14set -o errexit
15set -o nounset
17print_info '-> rm -rv dist/*'
18rm -rv dist/*
20echo ""
22print_info "-> uv build"
23uv build
25echo ""
27print_info "-> uv publish --username=__token__ --password=$(…)"
28uv publish --username=__token__ --password=$(security find-generic-password -s 'https://upload.pypi.org/legacy/' -a __token__ -w)
30echo ""
32version=$(find src -name __init__.py \
33 | xargs grep '__version__ =' \
34 | awk '{print $3}' \
35 | tr -d '"')
37print_info "-> git tag v$version"
38git tag "v$version"
40echo ""
42print_info "-> git push origin main --tag"
43git push origin main --tag