From 88ce6f5721a583e49ea64edde241179197be6240 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 27 Jul 2022 11:24:26 -0400 Subject: [PATCH] Allow for specifying local wheels and sdists as dependencies --- pyperformance/_pip.py | 2 +- pyperformance/tests/data/MANIFEST | 4 ++++ .../tests/data/bm_local_wheel/pyproject.toml | 9 +++++++++ .../data/bm_local_wheel/requirements.txt | 1 + .../data/bm_local_wheel/run_benchmark.py | 19 ++++++++++++++++++ .../this_is-1.0.2-py2.py3-none-any.whl | Bin 0 -> 3575 bytes pyperformance/tests/test_commands.py | 13 ++++++++++++ pyperformance/venv.py | 6 +++++- 8 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 pyperformance/tests/data/MANIFEST create mode 100644 pyperformance/tests/data/bm_local_wheel/pyproject.toml create mode 100644 pyperformance/tests/data/bm_local_wheel/requirements.txt create mode 100644 pyperformance/tests/data/bm_local_wheel/run_benchmark.py create mode 100755 pyperformance/tests/data/bm_local_wheel/this_is-1.0.2-py2.py3-none-any.whl diff --git a/pyperformance/_pip.py b/pyperformance/_pip.py index 7fc07874..7eb10e04 100644 --- a/pyperformance/_pip.py +++ b/pyperformance/_pip.py @@ -150,7 +150,7 @@ def install_requirements(reqs, *extra, if upgrade: args.append('-U') # --upgrade for reqs in [reqs, *extra]: - if os.path.exists(reqs): + if os.path.isfile(reqs) and reqs.endswith('.txt'): args.append('-r') # --requirement args.append(reqs) return run_pip('install', *args, **kwargs) diff --git a/pyperformance/tests/data/MANIFEST b/pyperformance/tests/data/MANIFEST new file mode 100644 index 00000000..9b55de6f --- /dev/null +++ b/pyperformance/tests/data/MANIFEST @@ -0,0 +1,4 @@ +[benchmarks] + +name metafile +local_wheel diff --git a/pyperformance/tests/data/bm_local_wheel/pyproject.toml b/pyperformance/tests/data/bm_local_wheel/pyproject.toml new file mode 100644 index 00000000..a3191642 --- /dev/null +++ b/pyperformance/tests/data/bm_local_wheel/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "pyperformance_bm_local_wheel" +requires-python = ">=3.8" +dependencies = ["pyperf"] +urls = {repository = "https://github.com/python/pyperformance"} +version = "1.0" + +[tool.pyperformance] +name = "local_wheel" diff --git a/pyperformance/tests/data/bm_local_wheel/requirements.txt b/pyperformance/tests/data/bm_local_wheel/requirements.txt new file mode 100644 index 00000000..ac230871 --- /dev/null +++ b/pyperformance/tests/data/bm_local_wheel/requirements.txt @@ -0,0 +1 @@ +this_is-1.0.2-py2.py3-none-any.whl#egg=this_is diff --git a/pyperformance/tests/data/bm_local_wheel/run_benchmark.py b/pyperformance/tests/data/bm_local_wheel/run_benchmark.py new file mode 100644 index 00000000..cb560fd1 --- /dev/null +++ b/pyperformance/tests/data/bm_local_wheel/run_benchmark.py @@ -0,0 +1,19 @@ +""" +A dummy benchmark that uses a local wheel +""" + +import pyperf +from this_is import en_us + + +def bench(): + return 1.0 + + +if __name__ == "__main__": + runner = pyperf.Runner() + runner.metadata['description'] = "A dummy benchmark that has a local wheel dependency" + + args = runner.parse_args() + runner.bench_func('local_wheel', bench) + diff --git a/pyperformance/tests/data/bm_local_wheel/this_is-1.0.2-py2.py3-none-any.whl b/pyperformance/tests/data/bm_local_wheel/this_is-1.0.2-py2.py3-none-any.whl new file mode 100755 index 0000000000000000000000000000000000000000..40279621898e66ae9280028c40bdb60f4bd54f9d GIT binary patch literal 3575 zcmaKv2T&7A8plJCrjY=O(xoYZ6zN?>3`8KIgFt8k5u^x&CQ?+S2!txV_YM-Oh9XFp z4v!KL>AZkcL5d*9ySuq}=iGa{v$L~1`~Bvdo&WrIKP`1C>Pr9sfDZ72IayCyOZeg_ zH30DFJOIFOw(DkVhcmas!JMC_#rHW)OMyB!y&1-?+z6^<)XJo-L%*PO0*#XM5-bGp z0&PHLZpP{0jR8T*fAZ@bt#U7GT=^4i{+ zx;t0FSayU?OHFN9e{j-a@J^-CsJ(v@r(Zs5^0`Esb22#lAl)wfJsW;lDUP$U_@Sx+ zzRU<3YUmj-6c-U}@Ofnq;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>@!?qK6#;{bE>auez9 zf&%DF6WOzk%r>lr?qkx%alXD&GMB2A?(A6q&vzDKowlvtdyZ zz<9U~3ckW7*fuq#k!6;DF4G&}jB!s7C{mYfa~efS=^BXy@{~GN*O-J|iiFURj zG!Bdw?zOyh2RC3t#X;d1UfH9)>RHkHb71H zn8CTh!s1!qCZcbz*dGI;$}?(Ltg`o$m9p9RQ&$Nj(O`d?81K=q5`vjXPd zaew)E|4RE+p?}g0&*bq}w14XLSJbbP`V+PNH>m#+*ssW6h4mjK#jUeK?XR-?m&~-( U&(ZvG{@hu2J`<+Pg+EsR0OiC$EdT%j literal 0 HcmV?d00001 diff --git a/pyperformance/tests/test_commands.py b/pyperformance/tests/test_commands.py index 4c7787c6..942b151c 100644 --- a/pyperformance/tests/test_commands.py +++ b/pyperformance/tests/test_commands.py @@ -161,6 +161,19 @@ def test_run_and_show(self): # XXX Capture and check the output. self.run_module('pyperf', 'slowest', filename) + def test_run_test_benchmarks(self): + # Run the benchmarks that exist only for testing + # in pyperformance/tests/data + filename = self.resolve_tmp('bench-test.json') + + self.run_pyperformance( + 'run', + '--manifest', os.path.join(tests.DATA_DIR, 'MANIFEST'), + '-b', 'all', + '-o', filename, + capture=None, + ) + ################################### # compile diff --git a/pyperformance/venv.py b/pyperformance/venv.py index fe686a9e..5a703024 100644 --- a/pyperformance/venv.py +++ b/pyperformance/venv.py @@ -44,7 +44,11 @@ def _add_from_file(self, filename): if not os.path.exists(filename): return for line in _utils.iter_clean_lines(filename): - self._add(line) + fullpath = os.path.join(os.path.dirname(filename), line.strip()) + if os.path.isfile(fullpath): + self._add(fullpath) + else: + self._add(line) def _add(self, line): self.specs.append(line)