Skip to content

Commit 572cb6d

Browse files
authored
Allow for specifying local wheels and sdists as dependencies (#215)
It is useful, especially when creating custom versions of dependencies that are compatible with CPython main, to specify local file paths as dependencies. Unfortunately, that's blocked by a feature that treats any dependency that matches a file path as a requirements file. This makes that check a little more specific which allows for installing wheels.
1 parent 684eafe commit 572cb6d

File tree

8 files changed

+52
-2
lines changed

8 files changed

+52
-2
lines changed

pyperformance/_pip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def install_requirements(reqs, *extra,
150150
if upgrade:
151151
args.append('-U') # --upgrade
152152
for reqs in [reqs, *extra]:
153-
if os.path.exists(reqs):
153+
if os.path.isfile(reqs) and reqs.endswith('.txt'):
154154
args.append('-r') # --requirement
155155
args.append(reqs)
156156
return run_pip('install', *args, **kwargs)

pyperformance/tests/data/MANIFEST

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[benchmarks]
2+
3+
name metafile
4+
local_wheel <local>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "pyperformance_bm_local_wheel"
3+
requires-python = ">=3.8"
4+
dependencies = ["pyperf"]
5+
urls = {repository = "https://github.com/python/pyperformance"}
6+
version = "1.0"
7+
8+
[tool.pyperformance]
9+
name = "local_wheel"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this_is-1.0.2-py2.py3-none-any.whl#egg=this_is
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
A dummy benchmark that uses a local wheel
3+
"""
4+
5+
import pyperf
6+
from this_is import en_us
7+
8+
9+
def bench():
10+
return 1.0
11+
12+
13+
if __name__ == "__main__":
14+
runner = pyperf.Runner()
15+
runner.metadata['description'] = "A dummy benchmark that has a local wheel dependency"
16+
17+
args = runner.parse_args()
18+
runner.bench_func('local_wheel', bench)
19+
Binary file not shown.

pyperformance/tests/test_commands.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ def test_run_and_show(self):
161161
# XXX Capture and check the output.
162162
self.run_module('pyperf', 'slowest', filename)
163163

164+
def test_run_test_benchmarks(self):
165+
# Run the benchmarks that exist only for testing
166+
# in pyperformance/tests/data
167+
filename = self.resolve_tmp('bench-test.json')
168+
169+
self.run_pyperformance(
170+
'run',
171+
'--manifest', os.path.join(tests.DATA_DIR, 'MANIFEST'),
172+
'-b', 'all',
173+
'-o', filename,
174+
capture=None,
175+
)
176+
164177
###################################
165178
# compile
166179

pyperformance/venv.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def _add_from_file(self, filename):
4444
if not os.path.exists(filename):
4545
return
4646
for line in _utils.iter_clean_lines(filename):
47-
self._add(line)
47+
fullpath = os.path.join(os.path.dirname(filename), line.strip())
48+
if os.path.isfile(fullpath):
49+
self._add(fullpath)
50+
else:
51+
self._add(line)
4852

4953
def _add(self, line):
5054
self.specs.append(line)

0 commit comments

Comments
 (0)