Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Version 1.15.0 (unreleased)
* Add support for Python 3.15 and drop 3.10
* Bump tornado to 6.6 (fixes ``BufferError`` on PyPy)
* Bump genshi to 0.7.12 (fixes ``TypeError`` on Python 3.15)
* Fix benchmark selection checking Python version requirements against the
running interpreter instead of the target specified by ``--python``

Version 1.14.0 (2026-02-07)
---------------------------
Expand Down
15 changes: 8 additions & 7 deletions pyperformance/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def parse_args():
cmd.add_argument("changed_filename", metavar="changed_file.json")

# list
cmd = subparsers.add_parser("list", help="List benchmarks of the running Python")
cmd = subparsers.add_parser("list", help="List benchmarks of the target Python")
cmds.append(cmd)
filter_opts(cmd)

Expand Down Expand Up @@ -317,11 +317,11 @@ def _benchmarks_from_options(options):
if not getattr(options, "benchmarks", None):
return None
manifest = _manifest_from_options(options)
return _select_benchmarks(options.benchmarks, manifest)
return _select_benchmarks(options.benchmarks, manifest, options.python)


def _select_benchmarks(raw, manifest):
from pyperformance import _benchmark_selections
def _select_benchmarks(raw, manifest, python):
from pyperformance import _benchmark_selections, _pythoninfo

# Get the raw list of benchmarks.
entries = raw.lower()
Expand All @@ -342,13 +342,14 @@ def parse_entry(o, s):

# Get the selections.
selected = []
this_python_version = ".".join(map(str, sys.version_info[:3]))
info = _pythoninfo.get_info(python)
target_python_version = ".".join(map(str, info.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
# Filter out any benchmarks that can't be run on the Python version we're running
if this_python_version in bench.python:
# Filter using the target interpreter, which may differ from the running Python.
if target_python_version in bench.python:
selected.append(bench)

return selected
Expand Down
21 changes: 20 additions & 1 deletion pyperformance/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import os
import os.path
import shutil
import sys
import textwrap
import unittest
from types import SimpleNamespace
from unittest import mock

import pyperformance
from pyperformance import tests
from pyperformance import _pythoninfo, cli, tests


class BenchmarkSelectionTests(unittest.TestCase):
def test_target_python_version(self):
options = SimpleNamespace(
benchmarks="async_tree_eager", manifest=None, python="target-python"
)
info = SimpleNamespace(sys=SimpleNamespace(version_info=(3, 16, 0)))
with (
mock.patch.object(sys, "version_info", (3, 11, 0)),
mock.patch.object(_pythoninfo, "get_info", return_value=info) as get_info,
):
benchmarks = cli._benchmarks_from_options(options)

get_info.assert_called_once_with("target-python")
self.assertEqual([bench.name for bench in benchmarks], ["async_tree_eager"])


class FullStackTests(tests.Functional, unittest.TestCase):
Expand Down
Loading