diff options
Diffstat (limited to 'release.py')
-rw-r--r-- | release.py | 107 |
1 files changed, 66 insertions, 41 deletions
@@ -22,19 +22,44 @@ try: except Exception: pass -VERSION = '0.6.50' -PACKAGE_INDEX = 'https://pypi.python.org/pypi' +VERSION = '0.7.8' PACKAGE_INDEX = 'https://pypi.python.org/pypi' -def get_next_version(): - digits = map(int, VERSION.split('.')) - digits[-1] += 1 - return '.'.join(map(str, digits)) +def set_versions(): + global VERSION + version = raw_input("Release as version [%s]> " % VERSION) or VERSION + if version != VERSION: + VERSION = bump_versions(version) + +def infer_next_version(version): + """ + Infer a next version from the current version by incrementing the last + number or appending a number. + + >>> infer_next_version('1.0') + '1.1' -NEXT_VERSION = get_next_version() + >>> infer_next_version('1.0b') + '1.0b1' + + >>> infer_next_version('1.0.9') + '1.0.10' + + >>> infer_next_version('1') + '2' + + >>> infer_next_version('') + '1' + """ + def incr(match): + ver = int(match.group(0) or '0') + return str(ver + 1) + return re.sub('\d*$', incr, version) -files_with_versions = ('docs/conf.py', 'setup.py', 'release.py', - 'README.txt', 'distribute_setup.py') +files_with_versions = ( + 'docs/conf.py', 'setup.py', 'release.py', 'ez_setup.py', 'README.txt', + 'setuptools/__init__.py', +) def get_repo_name(): """ @@ -65,7 +90,7 @@ def get_mercurial_creds(system='https://bitbucket.org', username=None): Credential = collections.namedtuple('Credential', 'username password') return Credential(username, password) -def add_milestone_and_version(version=NEXT_VERSION): +def add_milestone_and_version(version): auth = 'Basic ' + ':'.join(get_mercurial_creds()).encode('base64').strip() headers = { 'Authorization': auth, @@ -81,12 +106,17 @@ def add_milestone_and_version(version=NEXT_VERSION): except urllib2.HTTPError as e: print(e.fp.read()) -def bump_versions(): - list(map(bump_version, files_with_versions)) +def bump_versions(target_ver): + for filename in files_with_versions: + bump_version(filename, target_ver) + subprocess.check_call(['hg', 'ci', '-m', + 'Bumped to {target_ver} in preparation for next ' + 'release.'.format(**vars())]) + return target_ver -def bump_version(filename): +def bump_version(filename, target_ver): with open(filename, 'rb') as f: - lines = [line.replace(VERSION, NEXT_VERSION) for line in f] + lines = [line.replace(VERSION, target_ver) for line in f] with open(filename, 'wb') as f: f.writelines(lines) @@ -96,6 +126,8 @@ def do_release(): assert has_sphinx(), "You must have Sphinx installed to release" + set_versions() + res = raw_input('Have you read through the SCM changelog and ' 'confirmed the changelog is current for releasing {VERSION}? ' .format(**globals())) @@ -114,6 +146,20 @@ def do_release(): subprocess.check_call(['hg', 'update', VERSION]) + upload_to_pypi() + + # update to the tip for the next operation + subprocess.check_call(['hg', 'update']) + + # we just tagged the current version, bump for the next release. + next_ver = bump_versions(infer_next_version(VERSION)) + + # push the changes + subprocess.check_call(['hg', 'push']) + + add_milestone_and_version(next_ver) + +def upload_to_pypi(): linkify('CHANGES.txt', 'CHANGES (links).txt') has_docs = build_docs() @@ -123,27 +169,14 @@ def do_release(): sys.executable, 'setup.py', '-q', 'egg_info', '-RD', '-b', '', 'sdist', - 'register', '-r', PACKAGE_INDEX, - 'upload', '-r', PACKAGE_INDEX, + #'register', '-r', PACKAGE_INDEX, + #'upload', '-r', PACKAGE_INDEX, ] if has_docs: - cmd.extend(['upload_docs', '-r', PACKAGE_INDEX]) + cmd.extend([ + 'upload_docs', '-r', PACKAGE_INDEX + ]) subprocess.check_call(cmd) - upload_bootstrap_script() - - # update to the tip for the next operation - subprocess.check_call(['hg', 'update']) - - # we just tagged the current version, bump for the next release. - bump_versions() - subprocess.check_call(['hg', 'ci', '-m', - 'Bumped to {NEXT_VERSION} in preparation for next ' - 'release.'.format(**globals())]) - - # push the changes - subprocess.check_call(['hg', 'push']) - - add_milestone_and_version() def has_sphinx(): try: @@ -169,14 +202,6 @@ def build_docs(): subprocess.check_call(cmd, cwd='docs') return True -def upload_bootstrap_script(): - scp_command = 'pscp' if sys.platform.startswith('win') else 'scp' - try: - subprocess.check_call([scp_command, 'distribute_setup.py', - 'pypi@ziade.org:python-distribute.org/']) - except: - print("Unable to upload bootstrap script. Ask Tarek to do it.") - def linkify(source, dest): with open(source) as source: out = _linkified_text(source.read()) @@ -209,7 +234,7 @@ def _linkified_text(rst_content): anchors = sorted(anchors) - bitroot = 'http://bitbucket.org/tarek/distribute' + bitroot = 'https://bitbucket.org/tarek/distribute' rst_content += "\n" for x in anchors: issue = re.findall(r'\d+', x)[0] |