rtool: include dev version in binaries

This commit is contained in:
Maximilian Hils 2017-12-26 21:53:16 +01:00
parent 749099e292
commit 937a849c93
4 changed files with 78 additions and 38 deletions

View File

@ -36,7 +36,7 @@ test_script:
- ps: | - ps: |
$Env:VERSION = $(python mitmproxy/version.py) $Env:VERSION = $(python mitmproxy/version.py)
$Env:SKIP_MITMPROXY = "python -c `"print('skip mitmproxy')`"" $Env:SKIP_MITMPROXY = "python -c `"print('skip mitmproxy')`""
tox -e wheel tox -e rtool -- wheel
tox -e rtool -- bdist tox -e rtool -- bdist
- ps: | - ps: |

View File

@ -1,5 +1,4 @@
IVERSION = (3, 0, 0) VERSION = "3.0.0"
VERSION = ".".join(str(i) for i in IVERSION)
PATHOD = "pathod " + VERSION PATHOD = "pathod " + VERSION
MITMPROXY = "mitmproxy " + VERSION MITMPROXY = "mitmproxy " + VERSION

View File

@ -4,6 +4,7 @@ import contextlib
import fnmatch import fnmatch
import os import os
import platform import platform
import re
import runpy import runpy
import shlex import shlex
import shutil import shutil
@ -79,26 +80,38 @@ def git(args: str) -> str:
return subprocess.check_output(["git"] + shlex.split(args)).decode() return subprocess.check_output(["git"] + shlex.split(args)).decode()
def get_version() -> str: def get_version(dev: bool = False, build: bool = False) -> str:
return runpy.run_path(VERSION_FILE)["VERSION"] 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) last_tag, tag_dist, commit = git("describe --tags --long").strip().rsplit("-", 2)
commit = commit.lstrip("g")[:7]
tag_dist = int(tag_dist) tag_dist = int(tag_dist)
if tag_dist == 0:
return get_version()
else:
# remove the 'g' prefix added by recent git versions
if commit.startswith('g'):
commit = commit[1:]
if tag_dist > 0 and dev:
dev_tag = ".dev{tag_dist:04}".format(tag_dist=tag_dist)
else:
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" # 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( build_tag = "-0x{commit}".format(commit=commit)
version=get_version(), # this should already be the next version else:
tag_dist=tag_dist, build_tag = ""
commit=commit
) 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: def archive_name(bdist: str) -> str:
@ -116,7 +129,7 @@ def archive_name(bdist: str) -> str:
def wheel_name() -> str: def wheel_name() -> str:
return "mitmproxy-{version}-py3-none-any.whl".format( 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()) 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") @cli.command("bdist")
def make_bdist(): def make_bdist():
""" """
@ -206,24 +236,30 @@ def make_bdist():
excludes.append("mitmproxy.tools.web") excludes.append("mitmproxy.tools.web")
if tool != "mitmproxy_main": if tool != "mitmproxy_main":
excludes.append("mitmproxy.tools.console") excludes.append("mitmproxy.tools.console")
subprocess.check_call(
[ # Overwrite mitmproxy/version.py to include commit info
"pyinstaller", set_version(True)
"--clean", try:
"--workpath", PYINSTALLER_TEMP, subprocess.check_call(
"--distpath", PYINSTALLER_DIST, [
"--additional-hooks-dir", PYINSTALLER_HOOKS, "pyinstaller",
"--onefile", "--clean",
"--console", "--workpath", PYINSTALLER_TEMP,
"--icon", "icon.ico", "--distpath", PYINSTALLER_DIST,
# This is PyInstaller, so setting a "--additional-hooks-dir", PYINSTALLER_HOOKS,
# different log level obviously breaks it :-) "--onefile",
# "--log-level", "WARN", "--console",
] "--icon", "icon.ico",
+ [x for e in excludes for x in ["--exclude-module", e]] # This is PyInstaller, so setting a
+ PYINSTALLER_ARGS # different log level obviously breaks it :-)
+ [tool] # "--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. # Delete the spec file - we're good without.
os.remove("{}.spec".format(tool)) 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: for f in files:
local_path = join(DIST_DIR, f) 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")) symlink_path = "../{}".format(f.replace(get_version(), "latest"))
# Upload new version # Upload new version

View File

@ -51,6 +51,7 @@ commands =
pathoc --version pathoc --version
[testenv:rtool] [testenv:rtool]
passenv = SKIP_MITMPROXY SNAPSHOT_HOST SNAPSHOT_PORT SNAPSHOT_USER SNAPSHOT_PASS RTOOL_KEY
deps = deps =
-rrequirements.txt -rrequirements.txt
pyinstaller==3.3.1 pyinstaller==3.3.1