-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake.py
105 lines (70 loc) · 2.18 KB
/
make.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
import os
import shutil
import subprocess as sp
from buildlib import buildmisc, git, project, wheel, yaml_
from cmdi import print_summary
from docopt import docopt
interface = """
Install:
pipenv install --dev --pre
pipenv run python make.py
Usage:
make.py build [options]
make.py deploy [options]
make.py test <cmd> [options]
make.py bump [options]
make.py git [options]
make.py -h | --help
Commands:
test <cmd> <cmd> can be 'init' or 'run'. 'init' creates a test
directory and 'run' runs the tests.
Options:
-h, --help Show this screen.
"""
proj = yaml_.loadfile("Project")
class Cfg:
version = proj["version"]
registry = "pypi"
def build():
return wheel.cmd.build(clean_dir=True)
def deploy(cfg: Cfg):
return wheel.cmd.push(clean_dir=True, repository=cfg.registry)
def test(cfg: Cfg, cmd: str):
if cmd == "init":
shutil.rmtree("/tmp/vhpi/", ignore_errors=True)
os.makedirs("/tmp/vhpi/")
shutil.copytree(src="tests", dst="/tmp/vhpi/tests")
print("Created test directory at: /tmp/vhpi/tests")
elif cmd == "run":
sp.run(['python', '-m', 'vhpi.app', 'run', '--config-dir', '/tmp/vhpi/tests'])
def bump(cfg: Cfg):
results = []
if project.prompt.should_bump_version():
result = project.cmd.bump_version()
cfg.version = result.val
results.append(result)
if wheel.prompt.should_push("PYPI"):
results.append(deploy(cfg))
new_release = cfg.version != proj["version"]
results.extend(git.seq.bump_git(cfg.version, new_release))
return results
def run():
cfg = Cfg()
uinput = docopt(interface)
results = []
if uinput["build"]:
results.append(build(cfg))
if uinput["deploy"]:
results.append(deploy(cfg))
if uinput["test"]:
test(cfg, uinput["<cmd>"])
if uinput["git"]:
results.append(git.seq.bump_git(cfg.version, new_release=False))
if uinput["bump"]:
results.extend(bump(cfg))
print_summary(results)
if __name__ == "__main__":
try:
run()
except KeyboardInterrupt:
print("\n\nScript aborted by user.")