Skip to content

Commit 1951e10

Browse files
committed
Add an explicit setup_py metadata to indicate the need to build
1 parent 1b89579 commit 1951e10

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

doc/custom_benchmarks.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ tool.extra_opts [str] X
333333
tool.inherits file
334334
tool.runscript file X
335335
tool.datadir file X
336+
tool.setup_py bool
336337
=============== ===== === === ===
337338

338339
"R": required
@@ -342,3 +343,5 @@ tool.datadir file X
342343
* tags: optional list of names to group benchmarks
343344
* extra_opts: optional list of args to pass to ``tool.runscript``
344345
* runscript: the benchmark script to use instead of run_benchmark.py.
346+
* setup_py: when ``true``, run the setup.py in the benchmark directory to build
347+
and install artifacts, such as C extensions

pyperformance/_benchmark.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ def runscript(self):
164164
def extra_opts(self):
165165
return self._get_metadata_value('extra_opts', ())
166166

167+
@property
168+
def setup_py(self):
169+
return self._get_metadata_value('setup_py', False)
170+
167171
# Other metadata keys:
168172
# * base
169173
# * python

pyperformance/_benchmark_metadata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'datadir': None,
3333
'runscript': None,
3434
'extra_opts': None,
35+
'setup_py': None,
3536
}
3637

3738

@@ -228,6 +229,9 @@ def _resolve_value(field, value, rootdir):
228229
for opt in value:
229230
if not opt or not isinstance(opt, str):
230231
raise TypeError(f'extra_opts should be a list of strings, got {value!r}')
232+
elif field == 'setup_py':
233+
if not isinstance(value, bool):
234+
raise TypeError(f'setup_py should be a bool, got {value!r}')
231235
else:
232236
raise NotImplementedError(field)
233237
return value

pyperformance/data-files/benchmarks/bm_ctypes/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dynamic = ["version"]
88
[tool.pyperformance]
99
name = "ctypes"
1010
tags = "extension"
11+
setup_py = true

pyperformance/venv.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def from_benchmarks(cls, benchmarks):
2424
for bench in benchmarks or ():
2525
filename = bench.requirements_lockfile
2626
self._add_from_file(filename)
27+
if bench.setup_py:
28+
self._add(os.path.dirname(bench.metafile))
2729
return self
2830

2931
def __init__(self):
@@ -241,10 +243,6 @@ def ensure_reqs(self, requirements=None):
241243
bench = requirements
242244
requirements = Requirements.from_benchmarks([bench])
243245

244-
benchmark_dir = os.path.dirname(bench.metafile)
245-
if os.path.isfile(os.path.join(benchmark_dir, "setup.py")):
246-
requirements._add(benchmark_dir)
247-
248246
# Every benchmark must depend on pyperf.
249247
if bench is not None and not requirements.get('pyperf'):
250248
basereqs = Requirements.from_file(REQUIREMENTS_FILE)

0 commit comments

Comments
 (0)