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 '-> ts'
18ts
20print_info '-> rm -rfv dist/*'
21rm -rfv dist/*
23echo ""
25print_info "-> uv build"
26uv build
28echo ""
30print_info "-> uv publish --username=__token__ --password=\$(…)"
31uv publish --username=__token__ --password=$(security find-generic-password -s 'https://upload.pypi.org/legacy/' -a __token__ -w)
33echo ""
35version=$(grep -rl '^__version__ = ' . --exclude-dir=.venv \
36 | xargs grep '__version__ =' \
37 | awk '{print $3}' \
38 | tr -d '"')
40print_info "-> git tag v$version"
41git tag "v$version"
43echo ""
45print_info "-> git push origin main --tag"
46git push origin main --tag