Skip to content

Commit a319528

Browse files
Add support for PyPy 3.12 (#524)
1 parent 498ff13 commit a319528

10 files changed

Lines changed: 75 additions & 19 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545
- os: ubuntu-latest
4646
python: pypy-3.11
4747
experimental: false
48+
- os: ubuntu-latest
49+
python: pypy-3.12
50+
experimental: false
4851
- os: macos-latest
4952
python: "3.15"
5053
experimental: true

‎README.rst‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ possible.
2020
(source code, issues)
2121
* `Download pyperformance on PyPI <https://pypi.python.org/pypi/pyperformance>`_
2222

23-
pyperformance is not tuned for PyPy yet: use the `PyPy benchmarks project
24-
<https://foss.heptapod.net/pypy/benchmarks>`_ instead to measure PyPy
25-
performances.
23+
pyperformance supports PyPy, except for the ``dask`` benchmark, as its dependencies
24+
do not support PyPy. See also the `PyPy benchmarks project <https://foss.heptapod.net/pypy/benchmarks>`_.
2625

2726
pyperformance is distributed under the MIT license.

‎doc/changelog.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
Version 2.0.0 (unreleased)
55
--------------------------
66
* Add support for Python 3.15 and drop 3.10
7+
* Add support for PyPy 3.12 (except the ``dask`` benchmark)
78
* Bump tornado to 6.6 (fixes ``BufferError`` on PyPy)
89
* Bump genshi to 0.7.12 (fixes ``TypeError`` on Python 3.15)
910
* Bump the pinned dependencies of most benchmarks to current releases,

‎doc/custom_benchmarks.rst‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,21 +324,25 @@ All other PEP 621 fields are optional (e.g. ``requires-python = ">=3.8"``,
324324
The ``[tool.pyperformance]`` Section
325325
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
326326

327-
=============== ===== === === ===
328-
field type R B F
329-
=============== ===== === === ===
330-
tool.name str X X
331-
tool.tags [str] X
332-
tool.extra_opts [str] X
333-
tool.inherits file
334-
tool.runscript file X
335-
tool.datadir file X
336-
=============== ===== === === ===
327+
================================ ===== === === ===
328+
field type R B F
329+
================================ ===== === === ===
330+
tool.name str X X
331+
tool.tags [str] X
332+
tool.extra_opts [str] X
333+
tool.unsupported_implementations [str] X
334+
tool.inherits file
335+
tool.runscript file X
336+
tool.datadir file X
337+
================================ ===== === === ===
337338

338339
"R": required
339340
"B": inferred from the inherited metadata
340341
"F": inferred from filename
341342

342343
* tags: optional list of names to group benchmarks
343344
* extra_opts: optional list of args to pass to ``tool.runscript``
345+
* unsupported_implementations: optional list of Python implementations
346+
(``sys.implementation.name``, e.g. ``"pypy"``) on which the benchmark
347+
does not work; it is not selected when running on one of them
344348
* runscript: the benchmark script to use instead of run_benchmark.py.

‎doc/index.rst‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ Other Python Benchmarks:
4343
See also the `Python pyperf module
4444
<https://pyperf.readthedocs.io/>`_ (used by pyperformance).
4545

46-
pyperformance is not tuned for PyPy yet: use the `PyPy benchmarks project
47-
<https://foss.heptapod.net/pypy/benchmarks>`_ instead to measure PyPy
48-
performances.
46+
pyperformance supports PyPy, except for the ``dask`` benchmark, as its dependencies
47+
do not support PyPy. See also the `PyPy benchmarks project <https://foss.heptapod.net/pypy/benchmarks>`_.
4948

5049
Image generated by bm_raytrace (pure Python raytrace):
5150

‎pyperformance/_benchmark.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ def extra_opts(self):
167167
def python(self):
168168
return SpecifierSet(self._get_metadata_value("python", ""))
169169

170+
@property
171+
def unsupported_implementations(self):
172+
"""The names (sys.implementation.name) of the unsupported Pythons."""
173+
return self._get_metadata_value("unsupported_implementations", ())
174+
170175
# Other metadata keys:
171176
# * base
172177
# * dependencies

‎pyperformance/_benchmark_metadata.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"datadir": None,
3030
"runscript": None,
3131
"extra_opts": None,
32+
"unsupported_implementations": None,
3233
}
3334

3435

@@ -43,6 +44,7 @@
4344
# datadir
4445
# runscript
4546
# extra_opts
47+
# unsupported_implementations
4648

4749

4850
def load_metadata(metafile, defaults=None):
@@ -235,6 +237,17 @@ def _resolve_value(field, value, rootdir):
235237
raise TypeError(
236238
f"extra_opts should be a list of strings, got {value!r}"
237239
)
240+
elif field == "unsupported_implementations":
241+
if isinstance(value, str):
242+
raise TypeError(
243+
f"unsupported_implementations should be a list of strings, got {value!r}"
244+
)
245+
for name in value:
246+
if not name or not isinstance(name, str):
247+
raise TypeError(
248+
f"unsupported_implementations should be a list of strings, got {value!r}"
249+
)
250+
value = [name.lower() for name in value]
238251
else:
239252
raise NotImplementedError(field)
240253
return value

‎pyperformance/cli.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,17 @@ def parse_entry(o, s):
344344
selected = []
345345
info = _pythoninfo.get_info(python)
346346
target_python_version = ".".join(map(str, info.sys.version_info[:3]))
347+
target_implementation = info.sys.implementation.name.lower()
347348
for bench in _benchmark_selections.iter_selections(manifest, parsed_infos):
348349
if isinstance(bench, str):
349350
logging.warning(f"no benchmark named {bench!r}")
350351
continue
351352
# Filter using the target interpreter, which may differ from the running Python.
352-
if target_python_version in bench.python:
353-
selected.append(bench)
353+
if target_python_version not in bench.python:
354+
continue
355+
if target_implementation in bench.unsupported_implementations:
356+
continue
357+
selected.append(bench)
354358

355359
return selected
356360

‎pyperformance/data-files/benchmarks/bm_dask/pyproject.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ dynamic = ["version"]
77

88
[tool.pyperformance]
99
name = "dask"
10+
# cloudpickle and distributed do not support PyPy.
11+
unsupported_implementations = ["pypy"]

‎pyperformance/tests/test_commands.py‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ def test_target_python_version(self):
1616
options = SimpleNamespace(
1717
benchmarks="async_tree_eager", manifest=None, python="target-python"
1818
)
19-
info = SimpleNamespace(sys=SimpleNamespace(version_info=(3, 16, 0)))
19+
info = SimpleNamespace(
20+
sys=SimpleNamespace(
21+
version_info=(3, 16, 0),
22+
implementation=SimpleNamespace(name="cpython"),
23+
)
24+
)
2025
with (
2126
mock.patch.object(sys, "version_info", (3, 11, 0)),
2227
mock.patch.object(_pythoninfo, "get_info", return_value=info) as get_info,
@@ -26,6 +31,27 @@ def test_target_python_version(self):
2631
get_info.assert_called_once_with("target-python")
2732
self.assertEqual([bench.name for bench in benchmarks], ["async_tree_eager"])
2833

34+
def test_unsupported_implementation(self):
35+
options = SimpleNamespace(
36+
benchmarks="dask,nbody", manifest=None, python="target-python"
37+
)
38+
for implementation, expected in [
39+
("cpython", ["dask", "nbody"]),
40+
("pypy", ["nbody"]),
41+
]:
42+
info = SimpleNamespace(
43+
sys=SimpleNamespace(
44+
version_info=(3, 12, 0),
45+
implementation=SimpleNamespace(name=implementation),
46+
)
47+
)
48+
with (
49+
self.subTest(implementation),
50+
mock.patch.object(_pythoninfo, "get_info", return_value=info),
51+
):
52+
benchmarks = cli._benchmarks_from_options(options)
53+
self.assertEqual(sorted(bench.name for bench in benchmarks), expected)
54+
2955

3056
class FullStackTests(tests.Functional, unittest.TestCase):
3157
maxDiff = 80 * 100

0 commit comments

Comments
 (0)