Skip to content

Commit 708265b

Browse files
On older versions of Python, skip benchmarks that use features introduced in newer Python versions (#283)
Co-authored-by: Brandt Bucher <[email protected]>
1 parent 974e29c commit 708265b

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Diff for: pyperformance/_benchmark.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414

1515
import pyperf
16+
from packaging.specifiers import SpecifierSet
1617

1718
from . import _utils, _benchmark_metadata
1819

@@ -164,9 +165,12 @@ def runscript(self):
164165
def extra_opts(self):
165166
return self._get_metadata_value('extra_opts', ())
166167

168+
@property
169+
def python(self):
170+
return SpecifierSet(self._get_metadata_value("python", ""))
171+
167172
# Other metadata keys:
168173
# * base
169-
# * python
170174
# * dependencies
171175
# * requirements
172176

Diff for: pyperformance/cli.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,15 @@ def parse_entry(o, s):
241241

242242
# Get the selections.
243243
selected = []
244+
this_python_version = ".".join(map(str, sys.version_info[:3]))
244245
for bench in _benchmark_selections.iter_selections(manifest, parsed_infos):
245246
if isinstance(bench, str):
246247
logging.warning(f"no benchmark named {bench!r}")
247248
continue
248-
selected.append(bench)
249+
# Filter out any benchmarks that can't be run on the Python version we're running
250+
if this_python_version in bench.python:
251+
selected.append(bench)
252+
249253
return selected
250254

251255

Diff for: pyperformance/tests/data/bm_local_wheel/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pyperformance_bm_local_wheel"
3-
requires-python = ">=3.8"
3+
requires-python = ">=3.7"
44
dependencies = ["pyperf"]
55
urls = {repository = "https://github.com/python/pyperformance"}
66
version = "1.0"

0 commit comments

Comments
 (0)