forked from xonsh/xonsh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.xsh
executable file
·137 lines (112 loc) · 3.85 KB
/
release.xsh
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
137
#!/usr/bin/env xonsh
"""Release helper script for xonsh."""
import os
import re
import sys
from argparse import ArgumentParser, Action
def replace_in_file(pattern, new, fname):
"""Replaces a given pattern in a file"""
with open(fname, 'r') as f:
raw = f.read()
lines = raw.splitlines()
ptn = re.compile(pattern)
for i, line in enumerate(lines):
if ptn.match(line):
lines[i] = new
upd = '\n'.join(lines) + '\n'
with open(fname, 'w') as f:
f.write(upd)
NEW_DEV = """
Current Developments
====================
**Added:** None
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None
""".strip()
def version_update(ver):
"""Updates version strings in relevant files."""
pnfs = [
('__version__\s*=.*', "__version__ = '{0}'".format(ver),
['xonsh', '__init__.py']),
('version:\s*', 'version: {0}.{{build}}'.format(ver), ['.appveyor.yml']),
('\*\*\w+:\*\* None', '', ['CHANGELOG.rst']),
('Current Developments', NEW_DEV + '\n\nv' + ver, ['CHANGELOG.rst']),
]
for p, n, f in pnfs:
replace_in_file(p, n, os.path.join(*f))
def just_do_git(ns):
"""Commits and updates tags."""
git status
git commit -am @("version bump to " + ns.ver)
git push @(ns.upstream) @(ns.branch)
git tag @(ns.ver)
git push --tags @(ns.upstream)
def pipify():
"""Make and upload pip package."""
./setup.py sdist upload
def condaify(ver):
"""Make and upload conda packages."""
conda_dir = os.path.dirname(os.path.dirname($(which conda)))
conda_bld = os.path.join(conda_dir, 'conda-bld')
rm -f @(os.path.join(conda_bld, 'src_cache', 'xonsh.tar.gz'))
conda build --no-test recipe
pkgpath = os.path.join(conda_bld, '*', 'xonsh-{0}*.tar.bz2'.format(ver))
pkg = __xonsh_glob__(pkgpath)[0]
conda convert -p all -o @(conda_bld) @(pkg)
anaconda upload -u xonsh @(__xonsh_glob__(pkgpath))
def docser():
"""Create docs"""
# FIXME this should be made more general
./setup.py install --user
cd docs
make clean html push-root
cd ..
DOERS = ('do_version_bump', 'do_git', 'do_pip', 'do_conda', 'do_docs')
class OnlyAction(Action):
def __init__(self, option_strings, dest, **kwargs):
super().__init__(option_strings, dest, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
for doer in DOERS:
if doer == self.dest:
setattr(namespace, doer, True)
else:
setattr(namespace, doer, False)
def main(args=None):
parser = ArgumentParser('release')
parser.add_argument('--upstream',
default='git@github.com:scopatz/xonsh.git',
help='upstream repo')
parser.add_argument('-b', '--branch', default='master',
help='branch to commit / push to.')
for doer in DOERS:
base = doer[3:].replace('_', '-')
parser.add_argument('--do-' + base, dest=doer, default=True,
action='store_true',
help='runs ' + base)
parser.add_argument('--no-' + base, dest=doer, action='store_false',
help='does not run ' + base)
parser.add_argument('--only-' + base, dest=doer, action=OnlyAction,
help='only runs ' + base, nargs=0)
parser.add_argument('ver', help='target version string')
ns = parser.parse_args(args or $ARGS[1:])
# enable debugging
$RAISE_SUBPROC_ERROR = True
trace on
# run commands
if ns.do_version_bump:
version_update(ns.ver)
if ns.do_git:
just_do_git(ns)
if ns.do_pip:
pipify()
if ns.do_conda:
condaify(ns.ver)
if ns.do_docs:
docser()
# disable debugging
trace off
if __name__ == '__main__':
main()