Mercurial > hg
view contrib/packaging/packaging.py @ 44996:c2df0bca0dfa
perf: make `hg perfwrite` more flexible
The more flexible command was used recently while finding a solution for a
buffering bug (eventually fixed in f9734b2d59cc (the changeset description uses
a different benchmark)).
In comparison to the previous version, the new version is much more flexible.
While using it, the focus was on testing small writes. For this reason, by
default it calls ui.write() 100 times with a single byte plus one newline byte,
for 100 lines.
To get the previous behavior, run `hg perfwrite --nlines=100000 --nitems=1
--item='Testing write performance' --batch-line`.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Fri, 05 Jun 2020 01:54:13 +0200 |
parents | 303bf312d5ed |
children |
line wrap: on
line source
#!/usr/bin/env python3 # # packaging.py - Mercurial packaging functionality # # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. import os import pathlib import subprocess import sys import venv HERE = pathlib.Path(os.path.abspath(__file__)).parent REQUIREMENTS_TXT = HERE / "requirements.txt" SOURCE_DIR = HERE.parent.parent VENV = SOURCE_DIR / "build" / "venv-packaging" def bootstrap(): venv_created = not VENV.exists() VENV.parent.mkdir(exist_ok=True) venv.create(VENV, with_pip=True) if os.name == "nt": venv_bin = VENV / "Scripts" pip = venv_bin / "pip.exe" python = venv_bin / "python.exe" else: venv_bin = VENV / "bin" pip = venv_bin / "pip" python = venv_bin / "python" args = [ str(pip), "install", "-r", str(REQUIREMENTS_TXT), "--disable-pip-version-check", ] if not venv_created: args.append("-q") subprocess.run(args, check=True) os.environ["HGPACKAGING_BOOTSTRAPPED"] = "1" os.environ["PATH"] = "%s%s%s" % (venv_bin, os.pathsep, os.environ["PATH"]) subprocess.run([str(python), __file__] + sys.argv[1:], check=True) def run(): import hgpackaging.cli as cli # Need to strip off main Python executable. cli.main() if __name__ == "__main__": try: if "HGPACKAGING_BOOTSTRAPPED" not in os.environ: bootstrap() else: run() except subprocess.CalledProcessError as e: sys.exit(e.returncode) except KeyboardInterrupt: sys.exit(1)