| 1 |
|
| 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 |
|
| 30 |
def main() -> None: |
| 31 |
p = argparse.ArgumentParser() |
| 32 |
p.add_argument('--use-test-pypi', action='store_true') |
| 33 |
args = p.parse_args() |
| 34 |
|
| 35 |
publish_url = ['--publish-url', 'https://test.pypi.org/legacy/'] if args.use_test_pypi else [] |
| 36 |
|
| 37 |
root = Path(__file__).absolute().parent.parent |
| 38 |
os.chdir(root) |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
dist = root / 'dist' |
| 43 |
if dist.exists(): |
| 44 |
shutil.rmtree(dist) |
| 45 |
|
| 46 |
check_call(['uv', 'build']) |
| 47 |
|
| 48 |
if not is_ci: |
| 49 |
|
| 50 |
assert UV_PUBLISH_TOKEN in os.environ, f'no {UV_PUBLISH_TOKEN} passed' |
| 51 |
|
| 52 |
check_call(['uv', 'publish', *publish_url]) |
| 53 |
|
| 54 |
|
| 55 |
if __name__ == '__main__': |
| 56 |
main() |