xonsh/release.xsh

161 lines
4.8 KiB
Text
Raw Normal View History

2016-06-11 16:11:26 -04:00
#!/usr/bin/env xonsh
2015-12-21 21:19:49 -08:00
"""Release helper script for xonsh."""
import os
import re
import sys
2015-12-22 15:22:35 -08:00
from argparse import ArgumentParser, Action
2015-12-21 21:19:49 -08:00
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)
2016-06-11 17:15:37 -04:00
NEWS = [os.path.join('news', f) for f in os.listdir('news')
if f != 'TEMPLATE.rst']
NEWS_CATEGORIES = ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed',
'Security']
NEWS_RE = re.compile('\*\*({0}):\*\*(.*)'.format('|'.join(NEWS_CATEGORIES)),
flags=re.DOTALL)
def merge_news():
"""Reads news files and merges them."""
cats = {c: '' for c in NEWS_CATEGORIES}
for news in NEWS:
2016-06-11 17:24:31 -04:00
with open(news) as f:
2016-06-11 17:15:37 -04:00
raw = f.read()
2016-06-11 17:24:31 -04:00
raw = raw.strip()
parts = NEWS_RE.split(raw)
while len(parts) > 0 and parts[0] not in NEWS_CATEGORIES:
parts = parts[1:]
for key, val in zip(parts[::2], parts[1::2]):
val = val.strip()
if val == 'None':
continue
cats[key] += val + '\n'
2016-06-11 17:15:37 -04:00
for news in NEWS:
os.remove(news)
s = ''
for c in NEWS_CATEGORIES:
2016-06-11 17:24:31 -04:00
val = cats[c]
2016-06-11 17:15:37 -04:00
if len(val) == 0:
continue
s += '**' + c + '**:\n\n' + val + '\n\n'
return s
2015-12-21 21:19:49 -08:00
def version_update(ver):
2015-12-22 14:59:15 -08:00
"""Updates version strings in relevant files."""
2016-06-11 17:21:01 -04:00
fnews = ('Xonsh Change Log\n'
'====================\n\n'
'v{0}'
'====================\n\n'
'{1}')
news = merge_news()
news = fnews.format(ver, news)
2015-12-21 21:19:49 -08:00
pnfs = [
2016-06-11 16:11:26 -04:00
('__version__\s*=.*', "__version__ = '{0}'".format(ver),
2015-12-21 21:19:49 -08:00
['xonsh', '__init__.py']),
2016-02-07 17:31:01 -05:00
('version:\s*', 'version: {0}.{{build}}'.format(ver), ['.appveyor.yml']),
2016-06-11 17:21:01 -04:00
('Xonsh Change Log', news, ['CHANGELOG.rst']),
2015-12-21 21:19:49 -08:00
]
for p, n, f in pnfs:
replace_in_file(p, n, os.path.join(*f))
2015-12-22 14:59:15 -08:00
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)))
2015-12-28 13:15:03 -08:00
conda_bld = os.path.join(conda_dir, 'conda-bld')
2015-12-22 14:59:15 -08:00
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)
2015-12-30 11:47:04 -08:00
anaconda upload -u xonsh @(__xonsh_glob__(pkgpath))
2015-12-22 14:59:15 -08:00
2015-12-22 15:22:35 -08:00
def docser():
2016-02-07 17:38:30 -05:00
"""Create docs"""
# FIXME this should be made more general
./setup.py install --user
2015-12-22 14:59:15 -08:00
cd docs
make clean html push-root
cd ..
2015-12-30 11:13:24 -08:00
DOERS = ('do_version_bump', 'do_git', 'do_pip', 'do_conda', 'do_docs')
2015-12-22 15:22:35 -08:00
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)
2015-12-21 21:19:49 -08:00
def main(args=None):
parser = ArgumentParser('release')
2016-06-11 16:11:26 -04:00
parser.add_argument('--upstream',
default='git@github.com:scopatz/xonsh.git',
2015-12-22 14:59:15 -08:00
help='upstream repo')
2016-06-11 16:11:26 -04:00
parser.add_argument('-b', '--branch', default='master',
2015-12-22 14:59:15 -08:00
help='branch to commit / push to.')
2015-12-22 15:22:35 -08:00
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)
2015-12-21 21:19:49 -08:00
parser.add_argument('ver', help='target version string')
ns = parser.parse_args(args or $ARGS[1:])
2016-02-07 17:31:01 -05:00
# enable debugging
$RAISE_SUBPROC_ERROR = True
trace on
# run commands
2015-12-22 15:22:35 -08:00
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()
2015-12-21 21:19:49 -08:00
2016-02-07 18:35:42 -05:00
# disable debugging
trace off
2015-12-21 21:19:49 -08:00
if __name__ == '__main__':
main()