-
Notifications
You must be signed in to change notification settings - Fork 16
/
manage.py
126 lines (103 loc) · 3.66 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
"""repository management tasks"""
import copy
import re
from argparse import REMAINDER
from argcmdr import local, Local, LocalRoot
class Manage(LocalRoot):
"""manage the library repository"""
@Manage.register
@local('remainder', metavar='...', nargs=REMAINDER,
help="additional arguments for tox (include a '-' to pass options)")
def test(self, args):
"""run tests"""
if args.remainder and args.remainder[0] == '-':
remainder = args.remainder[1:]
else:
remainder = args.remainder
return (self.local.FG, self.local['tox'][remainder])
@Manage.register
class Version(Local):
"""bump package version (and optionally build and release)"""
bump_default_message = "Bump version: {current_version} → {new_version}"
def __init__(self, parser):
parser.add_argument(
'part',
choices=('major', 'minor', 'patch'),
help="part of the version to be bumped",
)
parser.add_argument(
'-m', '--message',
help=f"Tag message (in addition to default: "
f"'{self.bump_default_message}')",
)
parser.add_argument(
'--build',
action='store_true',
help='build the new version',
)
parser.add_argument(
'--release',
action='store_true',
help='release the new build',
)
def prepare(self, args, parser):
if args.message:
tag_message = f"{self.bump_default_message}\n\n{args.message}"
else:
tag_message = self.bump_default_message
(_code,
stdout,
_err) = yield self.local['bumpversion'][
'--tag-message', tag_message,
'--list',
args.part,
]
if args.build:
yield 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 self.root['release'].prepare(rel_args)
elif args.release:
parser.error('will not release package without build')
@Manage.register
class Build(Local):
"""build package"""
def prepare(self):
return self.local.FG, self.local['python'][
'setup.py',
'sdist',
'bdist_wheel',
]
@Manage.register
class Release(Local):
"""upload package(s) to pypi"""
# TODO: add support for upload to test.pypi.org
# (See also: https://github.com/bast/pypi-howto)
#
# NOTE: also, could set up a Github workflow that automatically builds for
# us, (triggered by say a tag or *maybe* even a push); perhaps stores that
# artifact in Github Packages; and even uploads it to PyPI, or at least to
# test.pypi.org.
# (This might be convenient. It also might alleviate set-up work -- and any
# concerns -- over credentials sharing.)
# (See also: https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)
def __init__(self, parser):
parser.add_argument(
'version',
nargs='*',
)
def prepare(self, args):
if args.version:
target = [f'dist/*{version}*' for version in args.version]
else:
target = 'dist/*'
return self.local.FG, self.local['twine']['upload'][target]