diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60d188ae..42a4e8bd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,6 +45,9 @@ jobs: - os: ubuntu-latest python: pypy-3.11 experimental: false + - os: ubuntu-latest + python: pypy-3.12 + experimental: false - os: macos-latest python: "3.15" experimental: true diff --git a/README.rst b/README.rst index 757a0f41..c2bdb23d 100644 --- a/README.rst +++ b/README.rst @@ -20,8 +20,7 @@ possible. (source code, issues) * `Download pyperformance on PyPI `_ -pyperformance is not tuned for PyPy yet: use the `PyPy benchmarks project -`_ instead to measure PyPy -performances. +pyperformance supports PyPy, except for the ``dask`` benchmark, as its dependencies +do not support PyPy. See also the `PyPy benchmarks project `_. pyperformance is distributed under the MIT license. diff --git a/doc/changelog.rst b/doc/changelog.rst index 1c010403..96448214 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -4,6 +4,7 @@ Changelog Version 2.0.0 (unreleased) -------------------------- * Add support for Python 3.15 and drop 3.10 +* Add support for PyPy 3.12 (except the ``dask`` benchmark) * Bump tornado to 6.6 (fixes ``BufferError`` on PyPy) * Bump genshi to 0.7.12 (fixes ``TypeError`` on Python 3.15) * Bump the pinned dependencies of most benchmarks to current releases, diff --git a/doc/custom_benchmarks.rst b/doc/custom_benchmarks.rst index 01028f70..29efd596 100644 --- a/doc/custom_benchmarks.rst +++ b/doc/custom_benchmarks.rst @@ -324,16 +324,17 @@ All other PEP 621 fields are optional (e.g. ``requires-python = ">=3.8"``, The ``[tool.pyperformance]`` Section ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -=============== ===== === === === -field type R B F -=============== ===== === === === -tool.name str X X -tool.tags [str] X -tool.extra_opts [str] X -tool.inherits file -tool.runscript file X -tool.datadir file X -=============== ===== === === === +================================ ===== === === === +field type R B F +================================ ===== === === === +tool.name str X X +tool.tags [str] X +tool.extra_opts [str] X +tool.unsupported_implementations [str] X +tool.inherits file +tool.runscript file X +tool.datadir file X +================================ ===== === === === "R": required "B": inferred from the inherited metadata @@ -341,4 +342,7 @@ tool.datadir file X * tags: optional list of names to group benchmarks * extra_opts: optional list of args to pass to ``tool.runscript`` +* unsupported_implementations: optional list of Python implementations + (``sys.implementation.name``, e.g. ``"pypy"``) on which the benchmark + does not work; it is not selected when running on one of them * runscript: the benchmark script to use instead of run_benchmark.py. diff --git a/doc/index.rst b/doc/index.rst index a5539bf2..7a588376 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -43,9 +43,8 @@ Other Python Benchmarks: See also the `Python pyperf module `_ (used by pyperformance). -pyperformance is not tuned for PyPy yet: use the `PyPy benchmarks project -`_ instead to measure PyPy -performances. +pyperformance supports PyPy, except for the ``dask`` benchmark, as its dependencies +do not support PyPy. See also the `PyPy benchmarks project `_. Image generated by bm_raytrace (pure Python raytrace): diff --git a/pyperformance/_benchmark.py b/pyperformance/_benchmark.py index 17c34a06..ac2a3afe 100644 --- a/pyperformance/_benchmark.py +++ b/pyperformance/_benchmark.py @@ -167,6 +167,11 @@ def extra_opts(self): def python(self): return SpecifierSet(self._get_metadata_value("python", "")) + @property + def unsupported_implementations(self): + """The names (sys.implementation.name) of the unsupported Pythons.""" + return self._get_metadata_value("unsupported_implementations", ()) + # Other metadata keys: # * base # * dependencies diff --git a/pyperformance/_benchmark_metadata.py b/pyperformance/_benchmark_metadata.py index 8a2fd4f9..1a8d8064 100644 --- a/pyperformance/_benchmark_metadata.py +++ b/pyperformance/_benchmark_metadata.py @@ -29,6 +29,7 @@ "datadir": None, "runscript": None, "extra_opts": None, + "unsupported_implementations": None, } @@ -43,6 +44,7 @@ # datadir # runscript # extra_opts +# unsupported_implementations def load_metadata(metafile, defaults=None): @@ -235,6 +237,17 @@ def _resolve_value(field, value, rootdir): raise TypeError( f"extra_opts should be a list of strings, got {value!r}" ) + elif field == "unsupported_implementations": + if isinstance(value, str): + raise TypeError( + f"unsupported_implementations should be a list of strings, got {value!r}" + ) + for name in value: + if not name or not isinstance(name, str): + raise TypeError( + f"unsupported_implementations should be a list of strings, got {value!r}" + ) + value = [name.lower() for name in value] else: raise NotImplementedError(field) return value diff --git a/pyperformance/cli.py b/pyperformance/cli.py index cba81b52..1eb5816c 100644 --- a/pyperformance/cli.py +++ b/pyperformance/cli.py @@ -344,13 +344,17 @@ def parse_entry(o, s): selected = [] info = _pythoninfo.get_info(python) target_python_version = ".".join(map(str, info.sys.version_info[:3])) + target_implementation = info.sys.implementation.name.lower() for bench in _benchmark_selections.iter_selections(manifest, parsed_infos): if isinstance(bench, str): logging.warning(f"no benchmark named {bench!r}") continue # Filter using the target interpreter, which may differ from the running Python. - if target_python_version in bench.python: - selected.append(bench) + if target_python_version not in bench.python: + continue + if target_implementation in bench.unsupported_implementations: + continue + selected.append(bench) return selected diff --git a/pyperformance/data-files/benchmarks/bm_dask/pyproject.toml b/pyperformance/data-files/benchmarks/bm_dask/pyproject.toml index 4af6cd2e..1441abe2 100644 --- a/pyperformance/data-files/benchmarks/bm_dask/pyproject.toml +++ b/pyperformance/data-files/benchmarks/bm_dask/pyproject.toml @@ -7,3 +7,5 @@ dynamic = ["version"] [tool.pyperformance] name = "dask" +# cloudpickle and distributed do not support PyPy. +unsupported_implementations = ["pypy"] diff --git a/pyperformance/tests/test_commands.py b/pyperformance/tests/test_commands.py index e6256e9b..61cd8e52 100644 --- a/pyperformance/tests/test_commands.py +++ b/pyperformance/tests/test_commands.py @@ -16,7 +16,12 @@ 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))) + info = SimpleNamespace( + sys=SimpleNamespace( + version_info=(3, 16, 0), + implementation=SimpleNamespace(name="cpython"), + ) + ) with ( mock.patch.object(sys, "version_info", (3, 11, 0)), mock.patch.object(_pythoninfo, "get_info", return_value=info) as get_info, @@ -26,6 +31,27 @@ def test_target_python_version(self): get_info.assert_called_once_with("target-python") self.assertEqual([bench.name for bench in benchmarks], ["async_tree_eager"]) + def test_unsupported_implementation(self): + options = SimpleNamespace( + benchmarks="dask,nbody", manifest=None, python="target-python" + ) + for implementation, expected in [ + ("cpython", ["dask", "nbody"]), + ("pypy", ["nbody"]), + ]: + info = SimpleNamespace( + sys=SimpleNamespace( + version_info=(3, 12, 0), + implementation=SimpleNamespace(name=implementation), + ) + ) + with ( + self.subTest(implementation), + mock.patch.object(_pythoninfo, "get_info", return_value=info), + ): + benchmarks = cli._benchmarks_from_options(options) + self.assertEqual(sorted(bench.name for bench in benchmarks), expected) + class FullStackTests(tests.Functional, unittest.TestCase): maxDiff = 80 * 100