Debian Codegraph @

.ci/release

raw symbols SCIP
1 #!/usr/bin/env python3
2 '''
3 Run [[file:scripts/release][scripts/release]] to deploy Python package onto [[https://pypi.org][PyPi]] and [[https://test.pypi.org][test PyPi]].
4
5 The script expects =TWINE_PASSWORD= environment variable to contain the [[https://pypi.org/help/#apitoken][PyPi token]] (not the password!).
6
7 The script can be run manually.
8 It's also running as =pypi= job in [[file:.github/workflows/main.yml][Github Actions config]]. Packages are deployed on:
9 - every master commit, onto test pypi
10 - every new tag, onto production pypi
11
12 You'll need to set =TWINE_PASSWORD= and =TWINE_PASSWORD_TEST= in [[https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets][secrets]]
13 for Github Actions deployment to work.
14 '''
15
16 import os
17 import sys
18 from pathlib import Path
19 from subprocess import check_call
20 import shutil
21
22 is_ci = os.environ.get('CI') is not None
23
24 def main() -> None:
25 import argparse
26 p = argparse.ArgumentParser()
27 p.add_argument('--test', action='store_true', help='use test pypi')
28 args = p.parse_args()
29
30 extra = []
31 if args.test:
32 extra.extend(['--repository', 'testpypi'])
33
34 root = Path(__file__).absolute().parent.parent
35 os.chdir(root) # just in case
36
37 if is_ci:
38 # see https://github.com/actions/checkout/issues/217
39 check_call('git fetch --prune --unshallow'.split())
40
41 dist = root / 'dist'
42 if dist.exists():
43 shutil.rmtree(dist)
44
45 check_call(['python3', '-m', 'build'])
46
47 TP = 'TWINE_PASSWORD'
48 password = os.environ.get(TP)
49 if password is None:
50 print(f"WARNING: no {TP} passed", file=sys.stderr)
51 import pip_secrets
52 password = pip_secrets.token_test if args.test else pip_secrets.token # meh
53
54 check_call([
55 'python3', '-m', 'twine',
56 'upload', *dist.iterdir(),
57 *extra,
58 ], env={
59 'TWINE_USERNAME': '__token__',
60 TP: password,
61 **os.environ,
62 })
63
64
65 if __name__ == '__main__':
66 main()