diff --git a/pyperformance/_benchmark.py b/pyperformance/_benchmark.py index 398b2049..0cf8f2c7 100644 --- a/pyperformance/_benchmark.py +++ b/pyperformance/_benchmark.py @@ -13,6 +13,7 @@ import sys import pyperf +from packaging.specifiers import SpecifierSet from . import _utils, _benchmark_metadata @@ -164,9 +165,12 @@ def runscript(self): def extra_opts(self): return self._get_metadata_value('extra_opts', ()) + @property + def python(self): + return SpecifierSet(self._get_metadata_value("python", "")) + # Other metadata keys: # * base - # * python # * dependencies # * requirements diff --git a/pyperformance/cli.py b/pyperformance/cli.py index 4fe3ca1a..330d6e57 100644 --- a/pyperformance/cli.py +++ b/pyperformance/cli.py @@ -241,11 +241,15 @@ def parse_entry(o, s): # Get the selections. selected = [] + this_python_version = ".".join(map(str, sys.version_info[:3])) for bench in _benchmark_selections.iter_selections(manifest, parsed_infos): if isinstance(bench, str): logging.warning(f"no benchmark named {bench!r}") continue - selected.append(bench) + # Filter out any benchmarks that can't be run on the Python version we're running + if this_python_version in bench.python: + selected.append(bench) + return selected diff --git a/pyperformance/tests/data/bm_local_wheel/pyproject.toml b/pyperformance/tests/data/bm_local_wheel/pyproject.toml index a3191642..2710ced7 100644 --- a/pyperformance/tests/data/bm_local_wheel/pyproject.toml +++ b/pyperformance/tests/data/bm_local_wheel/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pyperformance_bm_local_wheel" -requires-python = ">=3.8" +requires-python = ">=3.7" dependencies = ["pyperf"] urls = {repository = "https://github.com/python/pyperformance"} version = "1.0"