-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease.py
executable file
·87 lines (63 loc) · 1.93 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
77
78
79
80
81
82
83
84
85
86
87
import sys
import logging
import shutil
from pathlib import Path
from plumbum import local, ProcessExecutionError
from twine.commands.check import check as twine_check
from twine.commands.upload import upload as twine_upload
from twine.settings import Settings as twine_Settings
log = logging.getLogger(__name__)
PROJECT_ROOT_PATH = Path(__file__).parent
DIST_PATH = PROJECT_ROOT_PATH / "dist"
git = local["git"]
def main():
logging.basicConfig(level=logging.DEBUG)
if repo_is_dirty():
raise EnvironmentError("repo is dirty!")
if len(sys.argv) < 2:
raise ValueError("need a version!")
version = sys.argv[1]
dryRun = len(sys.argv) > 2
with local.cwd(PROJECT_ROOT_PATH):
release(version, dryRun)
def release(version, dryRun):
tidy_up()
tag_repo(version)
build_dists()
dists = get_dists()
if not long_description_is_ok(dists):
sys.exit("Long description not ok.")
if dryRun:
sys.exit(f"This was a dry run for version {version}.")
upload_dists(dists)
push_released_tag(version)
def repo_is_dirty():
try:
git("diff", "--quiet")
return False
except ProcessExecutionError as e:
if e.retcode != 1:
raise
return True
def tidy_up():
for path in [DIST_PATH, PROJECT_ROOT_PATH / "build"]:
if path.exists():
shutil.rmtree(path)
def tag_repo(version):
git("tag", version)
def build_dists():
python = local["python"]
python("setup.py", "sdist", "bdist_wheel")
def get_dists():
distPath = PROJECT_ROOT_PATH / "dist"
return list(str(dist) for dist in distPath.glob("*"))
def long_description_is_ok(dists):
log.info(f"check {dists}")
return not twine_check(dists)
def upload_dists(dists):
settings = twine_Settings()
twine_upload(settings, dists)
def push_released_tag(version):
git("push", "origin", version)
if __name__ == "__main__":
sys.exit(main())