mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-30 23:09:44 +00:00
update build script
This commit is contained in:
parent
fe03a656a9
commit
c3c3d28bb1
166
release/build.py
166
release/build.py
@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import (absolute_import, print_function, division, unicode_literals)
|
||||
from contextlib import contextmanager
|
||||
from os.path import dirname, realpath, join, exists, normpath
|
||||
from os import chdir
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@ -22,16 +23,39 @@ mitmproxy_dir = join(root_dir, "mitmproxy")
|
||||
dist_dir = join(mitmproxy_dir, "dist")
|
||||
test_venv_dir = join(root_dir, "venv.mitmproxy-release")
|
||||
|
||||
projects = ("netlib", "pathod", "mitmproxy")
|
||||
tools = ["mitmproxy", "mitmdump", "mitmweb", "pathod", "pathoc"]
|
||||
all_projects = ("netlib", "pathod", "mitmproxy")
|
||||
tools = {
|
||||
"mitmproxy": ["mitmproxy", "mitmdump", "mitmweb"],
|
||||
"pathod": ["pathod", "pathoc"],
|
||||
"netlib": []
|
||||
}
|
||||
if os.name == "nt":
|
||||
tools.remove("mitmproxy")
|
||||
tools["mitmproxy"].remove("mitmproxy")
|
||||
version_files = {
|
||||
"mitmproxy": normpath(join(root_dir, "mitmproxy/libmproxy/version.py")),
|
||||
"pathod": normpath(join(root_dir, "pathod/libpathod/version.py")),
|
||||
"netlib": normpath(join(root_dir, "netlib/netlib/version.py")),
|
||||
}
|
||||
|
||||
version_files = (join(root_dir, x) for x in (
|
||||
"mitmproxy/libmproxy/version.py",
|
||||
"pathod/libpathod/version.py",
|
||||
"netlib/netlib/version.py"
|
||||
))
|
||||
|
||||
@contextmanager
|
||||
def empty_pythonpath():
|
||||
"""
|
||||
Make sure that the regular python installation is not on the python path,
|
||||
which would give us access to modules installed outside of our virtualenv.
|
||||
"""
|
||||
pythonpath = os.environ["PYTHONPATH"]
|
||||
os.environ["PYTHONPATH"] = ""
|
||||
yield
|
||||
os.environ["PYTHONPATH"] = pythonpath
|
||||
|
||||
|
||||
@contextmanager
|
||||
def chdir(path):
|
||||
old_dir = os.getcwd()
|
||||
os.chdir(path)
|
||||
yield
|
||||
os.chdir(old_dir)
|
||||
|
||||
|
||||
@click.group(chain=True)
|
||||
@ -67,14 +91,17 @@ def docs():
|
||||
|
||||
|
||||
@cli.command("set-version")
|
||||
@click.option('--project', '-p', 'projects', multiple=True, type=click.Choice(all_projects), default=all_projects)
|
||||
@click.argument('version')
|
||||
def set_version(version):
|
||||
def set_version(projects, version):
|
||||
"""
|
||||
Update version information
|
||||
"""
|
||||
print("Update versions...")
|
||||
version = ", ".join(version.split("."))
|
||||
for version_file in version_files:
|
||||
for project, version_file in version_files.items():
|
||||
if project not in projects:
|
||||
continue
|
||||
print("Update %s..." % version_file)
|
||||
with open(version_file, "rb") as f:
|
||||
content = f.read()
|
||||
@ -84,8 +111,9 @@ def set_version(version):
|
||||
|
||||
|
||||
@cli.command("git")
|
||||
@click.option('--project', '-p', 'projects', multiple=True, type=click.Choice(all_projects), default=all_projects)
|
||||
@click.argument('args', nargs=-1, required=True)
|
||||
def git(args):
|
||||
def git(projects, args):
|
||||
"""
|
||||
Run a git command on every project
|
||||
"""
|
||||
@ -99,56 +127,55 @@ def git(args):
|
||||
|
||||
|
||||
@cli.command("sdist")
|
||||
def sdist():
|
||||
@click.option('--project', '-p', 'projects', multiple=True, type=click.Choice(all_projects), default=all_projects)
|
||||
def sdist(projects):
|
||||
"""
|
||||
Build a source distribution
|
||||
"""
|
||||
# Make sure that the regular python installation is not on the python path!
|
||||
os.environ["PYTHONPATH"] = ""
|
||||
|
||||
print("Building release...")
|
||||
if exists(dist_dir):
|
||||
shutil.rmtree(dist_dir)
|
||||
for project in projects:
|
||||
print("Creating %s source distribution..." % project)
|
||||
subprocess.check_call(
|
||||
["python", "./setup.py", "-q", "sdist", "--dist-dir", dist_dir, "--formats=gztar"],
|
||||
cwd=join(root_dir, project)
|
||||
)
|
||||
with empty_pythonpath():
|
||||
print("Building release...")
|
||||
if exists(dist_dir):
|
||||
shutil.rmtree(dist_dir)
|
||||
for project in projects:
|
||||
print("Creating %s source distribution..." % project)
|
||||
subprocess.check_call(
|
||||
["python", "./setup.py", "-q", "sdist", "--dist-dir", dist_dir, "--formats=gztar"],
|
||||
cwd=join(root_dir, project)
|
||||
)
|
||||
|
||||
|
||||
@cli.command("test")
|
||||
@click.option('--project', '-p', 'projects', multiple=True, type=click.Choice(all_projects), default=all_projects)
|
||||
@click.pass_context
|
||||
def test(ctx):
|
||||
def test(ctx, projects):
|
||||
"""
|
||||
Test the source distribution
|
||||
"""
|
||||
if not exists(dist_dir):
|
||||
ctx.invoke(sdist)
|
||||
|
||||
# Make sure that the regular python installation is not on the python path!
|
||||
os.environ["PYTHONPATH"] = ""
|
||||
with empty_pythonpath():
|
||||
print("Creating virtualenv for test install...")
|
||||
if exists(test_venv_dir):
|
||||
shutil.rmtree(test_venv_dir)
|
||||
subprocess.check_call(["virtualenv", "-q", test_venv_dir])
|
||||
|
||||
print("Creating virtualenv for test install...")
|
||||
if exists(test_venv_dir):
|
||||
shutil.rmtree(test_venv_dir)
|
||||
subprocess.check_call(["virtualenv", "-q", test_venv_dir])
|
||||
pip = join(test_venv_dir, venv_bin, "pip")
|
||||
with chdir(dist_dir):
|
||||
for project in projects:
|
||||
print("Installing %s..." % project)
|
||||
dist = glob.glob("./%s*" % project)[0]
|
||||
subprocess.check_call([pip, "install", "-q", dist])
|
||||
|
||||
pip = join(test_venv_dir, venv_bin, "pip")
|
||||
chdir(dist_dir)
|
||||
for project in projects:
|
||||
print("Installing %s..." % project)
|
||||
dist = glob.glob("./%s*" % project)[0]
|
||||
subprocess.check_call([pip, "install", "-q", dist])
|
||||
print("Running binaries...")
|
||||
for project in projects:
|
||||
for tool in tools[project]:
|
||||
tool = join(test_venv_dir, venv_bin, tool)
|
||||
print(tool)
|
||||
print(subprocess.check_output([tool, "--version"]))
|
||||
|
||||
print("Running binaries...")
|
||||
for tool in tools:
|
||||
tool = join(test_venv_dir, venv_bin, tool)
|
||||
print(tool)
|
||||
print(subprocess.check_output([tool, "--version"]))
|
||||
|
||||
print("Virtualenv available for further testing:")
|
||||
print("source %s" % normpath(join(test_venv_dir, venv_bin, "activate")))
|
||||
print("Virtualenv available for further testing:")
|
||||
print("source %s" % normpath(join(test_venv_dir, venv_bin, "activate")))
|
||||
|
||||
|
||||
@cli.command("upload")
|
||||
@ -170,44 +197,45 @@ def upload_release(username, password, repository):
|
||||
])
|
||||
|
||||
|
||||
"""
|
||||
|
||||
TODO: Fully automate build process.
|
||||
This skeleton is missing OSX builds and updating mitmproxy.org.
|
||||
|
||||
|
||||
# TODO: Fully automate build process.
|
||||
# This wizard is missing OSX builds and updating mitmproxy.org.
|
||||
@cli.command("wizard")
|
||||
@click.option('--version', prompt=True)
|
||||
@click.option('--username', prompt=True)
|
||||
@click.password_option(confirmation_prompt=False)
|
||||
@click.option('--username', prompt="PyPI Username")
|
||||
@click.password_option(confirmation_prompt=False, prompt="PyPI Password")
|
||||
@click.option('--repository', default="pypi")
|
||||
@click.option('--test/--no-test', default=True)
|
||||
@click.option('--project', '-p', 'projects', multiple=True, type=click.Choice(all_projects), default=all_projects)
|
||||
@click.pass_context
|
||||
def wizard(ctx, version, username, password, repository, test):
|
||||
""
|
||||
def wizard(ctx, version, username, password, repository, projects):
|
||||
"""
|
||||
Interactive Release Wizard
|
||||
""
|
||||
|
||||
"""
|
||||
for project in projects:
|
||||
if subprocess.check_output(["git", "status", "--porcelain"], cwd=join(root_dir, project)):
|
||||
raise RuntimeError("%s repository is not clean." % project)
|
||||
|
||||
if test:
|
||||
ctx.invoke(sdist)
|
||||
ctx.invoke(test)
|
||||
click.confirm("Please test the release now. Is it ok?", abort=True)
|
||||
# Build test release
|
||||
ctx.invoke(sdist, projects=projects)
|
||||
ctx.invoke(test, projects=projects)
|
||||
click.confirm("Please test the release now. Is it ok?", abort=True)
|
||||
|
||||
ctx.invoke(set_version, version=version)
|
||||
# bump version, update docs and contributors
|
||||
ctx.invoke(set_version, version=version, projects=projects)
|
||||
ctx.invoke(docs)
|
||||
ctx.invoke(contributors)
|
||||
|
||||
ctx.invoke(git, args=["commit", "-a", "-m", "bump version"])
|
||||
ctx.invoke(git, args=["tag", "v" + version])
|
||||
ctx.invoke(git, args=["push", "--tags"])
|
||||
ctx.invoke(sdist)
|
||||
# version bump commit + tag
|
||||
ctx.invoke(git, args=["commit", "-a", "-m", "bump version"], projects=projects)
|
||||
ctx.invoke(git, args=["tag", "v" + version], projects=projects)
|
||||
ctx.invoke(git, args=["push"], projects=projects)
|
||||
ctx.invoke(git, args=["push", "--tags"], projects=projects)
|
||||
|
||||
# Re-invoke sdist with bumped version
|
||||
ctx.invoke(sdist, projects=projects)
|
||||
click.confirm("All good, can upload to PyPI?", abort=True)
|
||||
ctx.invoke(upload_release, username=username, password=password, repository=repository)
|
||||
click.echo("All done!")
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
|
Loading…
Reference in New Issue
Block a user