Skip to content

Commit 2eea05b

Browse files
committed
On older versions of Python, skip benchmarks that use features introduced in newer Python versions
1 parent 974e29c commit 2eea05b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pyperformance/_benchmark.py

Lines changed: 6 additions & 1 deletion
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,13 @@ def runscript(self):
164165
def extra_opts(self):
165166
return self._get_metadata_value('extra_opts', ())
166167

168+
@property
169+
def python(self):
170+
req = self._get_metadata_value("python", None)
171+
return None if req is None else SpecifierSet(req)
172+
167173
# Other metadata keys:
168174
# * base
169-
# * python
170175
# * dependencies
171176
# * requirements
172177

pyperformance/cli.py

Lines changed: 5 additions & 1 deletion
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 bench.python is not None and this_python_version in bench.python:
251+
selected.append(bench)
252+
249253
return selected
250254

251255

0 commit comments

Comments
 (0)