generated from iamogbz/oss-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
76 lines (54 loc) · 1.63 KB
/
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
"""Release to pypi deploy logic"""
import importlib
import os
import semver
import nvshim
from nvshim.utils import process
DIST_PATH = "dist"
def _is_valid_release_version(version: str) -> bool:
try:
return bool(semver.VersionInfo.parse(version))
except ValueError:
return False
def _clean():
print("Cleaning...")
process.run("rm", "-rf", DIST_PATH)
def _build():
print("Building...")
process.run("python", "setup.py", "sdist", "bdist_wheel")
def _get_publish_command(*, dry_run: bool = True):
cmd = ["twine", "upload", "--skip-existing", "--username", "__token__"]
if dry_run:
cmd.extend(
[
"--password",
os.environ["TEST_PYPI_PUBLISH_TOKEN"],
"--repository-url",
"https://test.pypi.org/legacy/",
]
)
else:
cmd.extend(["--password", os.environ["PYPI_PUBLISH_TOKEN"]])
cmd.append(os.path.join(DIST_PATH, "*"))
return cmd
def _publish(*, dry_run: bool = True):
print("Target:", "test.pypi.org" if dry_run else "pypi.org")
process.run(*_get_publish_command(dry_run=dry_run))
print("Publishing completed.")
def main():
"""Run main release logic"""
_clean()
_build()
__version__ = importlib.reload(nvshim).__version__
print(f"Publishing: {__version__}")
if __version__:
_publish(dry_run=True)
else:
return print("No build version")
if _is_valid_release_version(__version__):
_publish(dry_run=False)
else:
return print("No release version")
return None
if __name__ == "__main__":
main()