Skip to content

Commit 3cf973b

Browse files
committed
Merge branch 'main' into maurycy-ruff-ci
* main: Remove fallbacks for unsupported Python versions (< 3.9) (psf#228) Docs: Update minimum Python version. Add matching badge (psf#226)
1 parent fcd5010 commit 3cf973b

7 files changed

Lines changed: 22 additions & 34 deletions

File tree

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ pyperf
66
:alt: Latest release on the Python Cheeseshop (PyPI)
77
:target: https://pypi.python.org/pypi/pyperf
88

9+
.. image:: https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fpsf%2Fpyperf%2Frefs%2Fheads%2Fmain%2Fpyproject.toml
10+
:alt: Supported Python versions
11+
:target: https://pypi.python.org/pypi/pyperf
12+
913
.. image:: https://github.com/psf/pyperf/actions/workflows/build.yml/badge.svg
1014
:alt: Build status of pyperf on GitHub Actions
1115
:target: https://github.com/psf/pyperf/actions
@@ -128,7 +132,7 @@ Command to install pyperf on Python 3::
128132

129133
python3 -m pip install pyperf
130134

131-
pyperf requires Python 3.7 or newer.
135+
pyperf requires Python 3.9 or newer.
132136

133137
Python 2.7 users can use pyperf 1.7.1 which is the last version compatible with
134138
Python 2.7.

doc/run_benchmark.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Optional dependencies:
2323
* Python module ``psutil``. Install: ``python3 -m pip install -U psutil``.
2424
* When you are using macOS, you need to install ``psutil`` if you want to use ``--track-memory`` option.
2525

26-
pyperf requires Python 3.6 or newer.
26+
pyperf requires Python 3.9 or newer.
2727

2828
Python 2.7 users can use pyperf 1.7.1 which is the last version compatible with
2929
Python 2.7.

doc/runner.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Option::
146146
There is no time out by default.
147147
* ``--tracemalloc``: Use the ``tracemalloc`` module to track Python memory
148148
allocation and get the peak of memory usage in metadata
149-
(``tracemalloc_peak``). The module is only available on Python 3.4 and newer.
149+
(``tracemalloc_peak``).
150150
See the `tracemalloc module
151151
<https://docs.python.org/dev/library/tracemalloc.html>`_.
152152
* ``--track-memory``: get the memory peak usage. it is less accurate than

pyperf/_cpu_utils.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,10 @@ def get_logical_cpu_count():
1717
if psutil is not None:
1818
# Number of logical CPUs
1919
cpu_count = psutil.cpu_count()
20-
elif hasattr(os, "cpu_count"):
20+
else:
2121
# Python 3.4
22+
# Python 3.13+: capped by -X cpu_count=n or $PYTHON_CPU_COUNT if set
2223
cpu_count = os.cpu_count()
23-
else:
24-
cpu_count = None
25-
try:
26-
import multiprocessing
27-
except ImportError:
28-
pass
29-
else:
30-
try:
31-
cpu_count = multiprocessing.cpu_count()
32-
except NotImplementedError:
33-
pass
3424

3525
if cpu_count is not None and cpu_count < 1:
3626
return None
@@ -148,7 +138,7 @@ def get_isolated_cpus():
148138

149139

150140
def set_cpu_affinity(cpus):
151-
# Python 3.3 or newer?
141+
# Availability: some Unix platforms
152142
if hasattr(os, "sched_setaffinity"):
153143
os.sched_setaffinity(0, cpus)
154144
return True
@@ -161,6 +151,8 @@ def set_cpu_affinity(cpus):
161151
except ImportError:
162152
return
163153

154+
# Availability: Linux, Windows, FreeBSD (psutil 2.2.0+)
155+
# https://psutil.rtfd.io/en/latest/index.html#psutil.Process.cpu_affinity
164156
proc = psutil.Process()
165157
if not hasattr(proc, "cpu_affinity"):
166158
return

pyperf/_runner.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,20 @@ def _cpu_affinity(self):
527527
else:
528528
if not isolated:
529529
print("ERROR: CPU affinity not available.", file=sys.stderr)
530-
print("Use Python 3.3 or newer, or install psutil dependency")
530+
print(
531+
"Install psutil dependency and check "
532+
"psutil.Process.cpu_affinity is available on your OS."
533+
)
531534
sys.exit(1)
532535
elif not self.args.quiet:
533536
print(
534537
"WARNING: unable to pin worker processes to "
535538
"isolated CPUs, CPU affinity not available"
536539
)
537-
print("Use Python 3.3 or newer, or install psutil dependency")
540+
print(
541+
"Install psutil dependency and check "
542+
"psutil.Process.cpu_affinity is available on your OS."
543+
)
538544

539545
def _process_priority(self):
540546
if not MS_WINDOWS:

pyperf/_utils.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,7 @@ def sysfs_path(path):
200200

201201

202202
def python_implementation():
203-
if hasattr(sys, "implementation"):
204-
# PEP 421, Python 3.3
205-
name = sys.implementation.name
206-
else:
207-
# Code extracted from platform.python_implementation().
208-
# Don't import platform to avoid the subprocess import.
209-
sys_version = sys.version
210-
if "IronPython" in sys_version:
211-
name = "IronPython"
212-
elif sys.platform.startswith("java"):
213-
name = "Jython"
214-
elif "PyPy" in sys_version:
215-
name = "PyPy"
216-
else:
217-
name = "CPython"
218-
return name.lower()
203+
return sys.implementation.name.lower()
219204

220205

221206
def python_has_jit():

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ classifiers = [
4444
"Programming Language :: Python :: 3",
4545
"Topic :: Software Development :: Libraries :: Python Modules"
4646
]
47+
# Also update: README.rst, docs/run_benchmark.rst
4748
requires-python = ">=3.9"
4849
dependencies = ["psutil>=5.9.0"]
4950

0 commit comments

Comments
 (0)