-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublish.py
executable file
·56 lines (55 loc) · 1.5 KB
/
publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
import subprocess
import argparse
import re
parser = argparse.ArgumentParser()
parser.add_argument("version")
parser.add_argument("-f", "--force", action="store_true")
args = parser.parse_args()
if (
not args.force and subprocess.call(["git", "diff-index", "--quiet", "HEAD"]) != 0
): # noqa
raise RuntimeError("Working directory must be clean.")
if not re.match("\\d+\\.\\d+\\.\\d+", args.version):
args.error("version must be in the format N.N.N")
with open("setup.py", "r") as source:
oldsetup = source.read()
with open("setup.py", "w") as dest:
dest.write(
re.sub(
"^GEN_version = .*$",
'GEN_version = "{}"'.format(args.version),
oldsetup,
flags=re.M,
)
)
subprocess.check_call(
[
"git",
"commit",
"setup.py",
"--allow-empty",
"-m",
"Version {}".format(args.version),
]
)
subprocess.check_call(["git", "tag", "v{}".format(args.version)])
subprocess.check_call(["git", "push"])
subprocess.check_call(["git", "push", "--tags"])
subprocess.check_call(["python", "setup.py", "sdist"])
dist = "dist/{}-{}.tar.gz".format(
re.search('^READ_name = "(.*)"$', oldsetup, flags=re.M).group(1), args.version
)
subprocess.check_call(
[
"twine",
"upload",
dist,
"--user",
"rendaw",
"--password",
subprocess.check_output(["gopass", "show", "service/pypi/rendaw"])
.decode("utf-8")
.strip(),
]
)