diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-12-26 21:53:16 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2017-12-29 22:57:37 +0100 |
commit | 937a849c9363b1fb745b0948310533b535348819 (patch) | |
tree | 3242b6b4d476097f073b928a577cb16528e20769 /release | |
parent | 749099e2922a2852a4628978b564ade4927fafd3 (diff) | |
download | mitmproxy-937a849c9363b1fb745b0948310533b535348819.tar.gz mitmproxy-937a849c9363b1fb745b0948310533b535348819.tar.bz2 mitmproxy-937a849c9363b1fb745b0948310533b535348819.zip |
rtool: include dev version in binaries
Diffstat (limited to 'release')
-rwxr-xr-x | release/rtool.py | 108 |
1 files changed, 74 insertions, 34 deletions
diff --git a/release/rtool.py b/release/rtool.py index 271392ba..14a0a078 100755 --- a/release/rtool.py +++ b/release/rtool.py @@ -4,6 +4,7 @@ import contextlib import fnmatch import os import platform +import re import runpy import shlex import shutil @@ -79,26 +80,38 @@ def git(args: str) -> str: return subprocess.check_output(["git"] + shlex.split(args)).decode() -def get_version() -> str: - return runpy.run_path(VERSION_FILE)["VERSION"] +def get_version(dev: bool = False, build: bool = False) -> str: + version = runpy.run_path(VERSION_FILE)["VERSION"] + version = re.sub(r"\.dev.+?$", "", version) # replace dev suffix if present. - -def get_snapshot_version() -> str: last_tag, tag_dist, commit = git("describe --tags --long").strip().rsplit("-", 2) + commit = commit.lstrip("g")[:7] tag_dist = int(tag_dist) - if tag_dist == 0: - return get_version() + + if tag_dist > 0 and dev: + dev_tag = ".dev{tag_dist:04}".format(tag_dist=tag_dist) else: - # remove the 'g' prefix added by recent git versions - if commit.startswith('g'): - commit = commit[1:] + dev_tag = "" + if tag_dist > 0 and build: # The wheel build tag (we use the commit) must start with a digit, so we include "0x" - return "{version}dev{tag_dist:04}-0x{commit}".format( - version=get_version(), # this should already be the next version - tag_dist=tag_dist, - commit=commit - ) + build_tag = "-0x{commit}".format(commit=commit) + else: + build_tag = "" + + return version + dev_tag + build_tag + + +def set_version(dev: bool) -> None: + """ + Update version information in mitmproxy's version.py to either include the dev version or not. + """ + v = get_version(dev) + with open(VERSION_FILE) as f: + content = f.read() + content = re.sub(r'^VERSION = ".+?"', 'VERSION = "{}"'.format(v), content) + with open(VERSION_FILE, "w") as f: + f.write(content) def archive_name(bdist: str) -> str: @@ -116,7 +129,7 @@ def archive_name(bdist: str) -> str: def wheel_name() -> str: return "mitmproxy-{version}-py3-none-any.whl".format( - version=get_version(), + version=get_version(True), ) @@ -179,6 +192,23 @@ def contributors(): f.write(contributors_data.encode()) +@cli.command("wheel") +def make_wheel(): + """ + Build a Python wheel + """ + set_version(True) + try: + subprocess.check_call([ + "tox", "-e", "wheel", + ], env={ + **os.environ, + "VERSION": get_version(True), + }) + finally: + set_version(False) + + @cli.command("bdist") def make_bdist(): """ @@ -206,24 +236,30 @@ def make_bdist(): excludes.append("mitmproxy.tools.web") if tool != "mitmproxy_main": excludes.append("mitmproxy.tools.console") - subprocess.check_call( - [ - "pyinstaller", - "--clean", - "--workpath", PYINSTALLER_TEMP, - "--distpath", PYINSTALLER_DIST, - "--additional-hooks-dir", PYINSTALLER_HOOKS, - "--onefile", - "--console", - "--icon", "icon.ico", - # This is PyInstaller, so setting a - # different log level obviously breaks it :-) - # "--log-level", "WARN", - ] - + [x for e in excludes for x in ["--exclude-module", e]] - + PYINSTALLER_ARGS - + [tool] - ) + + # Overwrite mitmproxy/version.py to include commit info + set_version(True) + try: + subprocess.check_call( + [ + "pyinstaller", + "--clean", + "--workpath", PYINSTALLER_TEMP, + "--distpath", PYINSTALLER_DIST, + "--additional-hooks-dir", PYINSTALLER_HOOKS, + "--onefile", + "--console", + "--icon", "icon.ico", + # This is PyInstaller, so setting a + # different log level obviously breaks it :-) + # "--log-level", "WARN", + ] + + [x for e in excludes for x in ["--exclude-module", e]] + + PYINSTALLER_ARGS + + [tool] + ) + finally: + set_version(False) # Delete the spec file - we're good without. os.remove("{}.spec".format(tool)) @@ -299,7 +335,11 @@ def upload_snapshot(host, port, user, private_key, private_key_password, wheel, for f in files: local_path = join(DIST_DIR, f) - remote_filename = f.replace(get_version(), get_snapshot_version()) + remote_filename = re.sub( + r"{version}(\.dev\d+(-0x[0-9a-f]+)?)?".format(version=get_version()), + get_version(True, True), + f + ) symlink_path = "../{}".format(f.replace(get_version(), "latest")) # Upload new version |