-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
136 lines (113 loc) · 4.15 KB
/
manage.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""argcmdr's own management module"""
import configparser
import copy
import re
from argcmdr import Local
class Manage(Local):
"""manage development of argcmdr ... (with argcmdr)"""
class Test(Local):
"""run tests"""
def prepare(self):
return (self.local.FG, self.local['tox'])
class Bump(Local):
"""bump package version (and optionally build and release)"""
def __init__(self, parser):
parser.add_argument(
'part',
choices=('major', 'minor', 'patch'),
help="part of the version to be bumped",
)
parser.add_argument(
'-b', '--build',
action='store_true',
help='build the new version',
)
parser.add_argument(
'-r', '--release',
action='store_true',
help='release the new build',
)
def prepare(self, args, parser):
(_code,
stdout,
_err) = yield self.local['bumpversion']['--list', args.part]
if args.build:
yield from self.root['build'].prepare()
if args.release:
rel_args = copy.copy(args)
if stdout is None:
rel_args.version = ('DRY-RUN',)
else:
(version_match,) = re.finditer(
r'^new_version=([\d.]+)$',
stdout,
re.M,
)
rel_args.version = version_match.groups()
yield from self.root['release'].prepare(rel_args)
elif args.release:
parser.error('will not release package without build')
class Build(Local):
"""build package"""
def prepare(self):
# determine current version
config = configparser.ConfigParser()
config.read('./setup.cfg')
version = config['bumpversion']['current_version']
# build pure python distribution
yield self.local['python'][
'setup.py',
'sdist',
'bdist_wheel',
]
# build zipapp
#
# we want to encourage easy installation as just "manage". but,
# until then, we want it to be properly labeled throughout its
# distribution. so, we'll build it in a temporary directory and wrap
# it in an otherwise-superfluous zip.
#
yield self.local['mkdir']['-p', './pyz/']
(_code, stdout, _err) = yield self.local['mktemp'][
'-d',
'--tmpdir',
'manage-XXXXXXXX',
]
tmpdir = 'DRY-RUN' if stdout is None else stdout.strip()
try:
yield self.local['shiv'][
'-c', 'manage',
'-o', f'{tmpdir}/manage',
'--build-id', version,
'--platform-root',
'.',
]
yield self.local['zip'][
'-j',
f'./pyz/manage-{version}.zip',
f'{tmpdir}/manage',
]
finally:
yield self.local['rm']['-r', tmpdir]
class Release(Local):
"""upload package(s) to pypi"""
def __init__(self, parser):
parser.add_argument(
'version',
nargs='+',
)
def prepare(self, args):
yield (
self.local.FG,
self.local['twine']['upload'][[f'dist/*{version}*' for version in args.version]],
)
yield self.local['git']['push']
yield self.local['git']['push', '--tags']
for version in args.version:
yield self.local['gh'][
'release',
'create',
version,
f'./pyz/manage-{version}.zip#manage-{version}',
'--generate-notes',
]