Skip to content

Commit 95af60a

Browse files
committed
ci: use uv for running and publishing
1 parent a7a41bb commit 95af60a

File tree

5 files changed

+77
-20
lines changed

5 files changed

+77
-20
lines changed

.ci/release-uv

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
'''
3+
Deploys Python package onto [[https://pypi.org][PyPi]] or [[https://test.pypi.org][test PyPi]].
4+
5+
- running manually
6+
7+
You'll need =UV_PUBLISH_TOKEN= env variable
8+
9+
- running on Github Actions
10+
11+
Instead of env variable, relies on configuring github as Trusted publisher (https://docs.pypi.org/trusted-publishers/) -- both for test and regular pypi
12+
13+
It's running as =pypi= job in [[file:.github/workflows/main.yml][Github Actions config]].
14+
Packages are deployed on:
15+
- every master commit, onto test pypi
16+
- every new tag, onto production pypi
17+
'''
18+
19+
UV_PUBLISH_TOKEN = 'UV_PUBLISH_TOKEN'
20+
21+
import argparse
22+
import os
23+
import shutil
24+
from pathlib import Path
25+
from subprocess import check_call
26+
27+
is_ci = os.environ.get('CI') is not None
28+
29+
def main() -> None:
30+
p = argparse.ArgumentParser()
31+
p.add_argument('--use-test-pypi', action='store_true')
32+
args = p.parse_args()
33+
34+
publish_url = ['--publish-url', 'https://test.pypi.org/legacy/'] if args.use_test_pypi else []
35+
36+
root = Path(__file__).absolute().parent.parent
37+
os.chdir(root) # just in case
38+
39+
if is_ci:
40+
# see https://github.com/actions/checkout/issues/217
41+
check_call('git fetch --prune --unshallow'.split())
42+
43+
# TODO ok, for now uv won't remove dist dir if it already exists
44+
# https://github.com/astral-sh/uv/issues/10293
45+
dist = root / 'dist'
46+
if dist.exists():
47+
shutil.rmtree(dist)
48+
49+
# todo what is --force-pep517?
50+
check_call(['uv', 'build'])
51+
52+
if not is_ci:
53+
# CI relies on trusted publishers so doesn't need env variable
54+
assert UV_PUBLISH_TOKEN in os.environ, f'no {UV_PUBLISH_TOKEN} passed'
55+
56+
check_call(['uv', 'publish', *publish_url])
57+
58+
59+
if __name__ == '__main__':
60+
main()

.ci/run

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ if [ -n "${CI-}" ]; then
2222
;;
2323
cygwin* | msys* | win*)
2424
# windows
25-
:
2625
# ugh. parallel stuff seems super flaky under windows, some random failures, "file used by other process" and crap like that
2726
tox_cmd='run'
2827
;;
@@ -33,12 +32,5 @@ if [ -n "${CI-}" ]; then
3332
esac
3433
fi
3534

36-
37-
PY_BIN="python3"
38-
# some systems might have python pointing to python3
39-
if ! command -v python3 &> /dev/null; then
40-
PY_BIN="python"
41-
fi
42-
43-
"$PY_BIN" -m pip install --user tox
44-
"$PY_BIN" -m tox $tox_cmd "$@"
35+
# NOTE: expects uv installed
36+
uv tool run --with tox-uv tox $tox_cmd "$@"

.github/workflows/main.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
- uses: actions/setup-python@v5
3939
with:
4040
python-version: ${{ matrix.python-version }}
41+
42+
- uses: astral-sh/setup-uv@v5
4143

4244
- uses: actions/checkout@v4
4345
with:
@@ -61,7 +63,9 @@ jobs:
6163
pypi:
6264
runs-on: ubuntu-latest
6365
needs: [build] # add all other jobs here
64-
66+
permissions:
67+
# necessary for Trusted Publishing
68+
id-token: write
6569
steps:
6670
# ugh https://github.com/actions/toolkit/blob/main/docs/commands.md#path-manipulation
6771
- run: echo "$HOME/.local/bin" >> $GITHUB_PATH
@@ -70,21 +74,19 @@ jobs:
7074
with:
7175
python-version: '3.10'
7276

77+
- uses: astral-sh/setup-uv@v5
78+
7379
- uses: actions/checkout@v4
7480
with:
7581
submodules: recursive
7682

7783
- name: 'release to test pypi'
7884
# always deploy merged master to test pypi
7985
if: github.event_name != 'pull_request' && github.event.ref == 'refs/heads/master'
80-
env:
81-
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD_TEST }}
82-
run: pip3 install --user --upgrade build twine && .ci/release --test
86+
run: .ci/release-uv --use-test-pypi
8387

8488
- name: 'release to pypi'
8589
# always deploy tags to release pypi
8690
# NOTE: release tags are guarded by on: push: tags on the top
8791
if: github.event_name != 'pull_request' && startsWith(github.event.ref, 'refs/tags')
88-
env:
89-
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
90-
run: pip3 install --user --upgrade build twine && .ci/release
92+
run: .ci/release-uv

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ build-backend = "setuptools.build_meta"
5858
[tool.setuptools_scm]
5959
version_scheme = "python-simplified-semver"
6060
local_scheme = "dirty-tag"
61+
62+
# workaround for error during uv publishing
63+
# see https://github.com/astral-sh/uv/issues/9513#issuecomment-2519527822
64+
[tool.setuptools]
65+
license-files = []

tox.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ passenv =
1818
MYPY_CACHE_DIR
1919
RUFF_CACHE_DIR
2020
usedevelop = true # for some reason tox seems to ignore "-e ." in deps section??
21-
# note: --use-pep517 here is necessary for tox --parallel flag to work properly
22-
# otherwise it seems that it tries to modify .eggs dir in parallel and it fails
23-
install_command = {envpython} -m pip install --use-pep517 {opts} {packages}
21+
uv_seed = true # seems necessary so uv creates separate venvs per tox env?
2422

2523

2624
[testenv:ruff]

0 commit comments

Comments
 (0)