-
Notifications
You must be signed in to change notification settings - Fork 26
/
version-release.py
executable file
·109 lines (86 loc) · 2.94 KB
/
version-release.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import getpass
import os
import shutil
import subprocess
__version__ = None
# pylint: disable=unspecified-encoding, exec-used
with open("nums/core/version.py") as f:
exec(f.read(), globals())
pj = lambda *paths: os.path.abspath(os.path.expanduser(os.path.join(*paths)))
def project_root():
return os.path.abspath(os.path.dirname(__file__))
def runproc(*args):
subproc_env = os.environ.copy()
return subprocess.Popen(
args,
env=subproc_env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
def communicate(*args):
p = runproc(*args)
return tuple(map(lambda x: x.decode("utf-8"), p.communicate()))
def execute():
out, err = communicate("conda", "env", "list")
if err:
raise Exception(err)
for row in out.split("\n"):
if "*" in row:
env_dir = row.split("*")[-1].strip()
print("Running subproc in conda environment", env_dir)
break
out, err = communicate("python", "-m", "pip", "install", "--upgrade", "pip")
if err:
raise Exception(err)
s = " upgrade pip"
print("-" * (50 - len(s)) + s)
print("out", out)
print("-" * 50)
out, err = communicate("pip", "install", "setuptools", "wheel", "twine")
if err:
raise Exception(err)
s = " install release deps"
print("-" * (50 - len(s)) + s)
print("out", out)
print("-" * 50)
# Remove old build.
build_dir = pj(project_root(), "build")
if os.path.exists(build_dir):
shutil.rmtree(build_dir)
dist_dir = pj(project_root(), "dist")
if os.path.exists(dist_dir):
shutil.rmtree(dist_dir)
# Build it.
out, err = communicate("python", "setup.py", "sdist", "bdist_wheel")
if err:
lines = err.split("\n")
print(lines)
for line in lines:
if not ("warn" in line or "UserWarning" in line or line == ""):
raise Exception(err)
s = " build %s" % __version__
print("-" * (50 - len(s)) + s)
print(out)
print("-" * 50)
repo_name = input(
"Release %s to pypi or test.pypi (pypi/test.pypi)? " % __version__
)
assert repo_name in ("pypi", "test.pypi"), "repo_name=%s" % repo_name
release_cmd = ["twine", "upload"]
username = input("Username? ")
password = getpass.getpass(prompt="Password? ", stream=None)
release_cmd += ["--username", username, "--password", password]
if repo_name == "pypi":
release_cmd += ["dist/*"]
elif repo_name == "test.pypi":
release_cmd += ["-r", "testpypi", "dist/*"]
else:
raise Exception("Unknown repository %s" % repo_name)
out, err = communicate(*release_cmd)
s = " release %s" % __version__
print("-" * (50 - len(s)) + s)
print("out", out)
print("err", err)
if __name__ == "__main__":
execute()