From 1c7cb0aaf24f135e4ffded5a39387514f862c92e Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Sat, 18 May 2024 12:43:20 -0400 Subject: [PATCH 1/2] Don't build with limited API for 3.13 free-threaded build (#2402) The `--disable-gil` configuration of CPython 3.13 does not currently support the limited API. Signed-off-by: Sam Gross --- HISTORY.rst | 1 + setup.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 15333dbaf..a53590555 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -14,6 +14,7 @@ been reused. This makes `process_iter()`_ around 20x times faster. - 2396_: a new ``psutil.process_iter.cache_clear()`` API can be used the clear `process_iter()`_ internal cache. +- 2401_, Support building with free-threaded CPython 3.13. - 2407_: `Process.connections()`_ was renamed to `Process.net_connections()`_. The old name is still available, but it's deprecated (triggers a ``DeprecationWarning``) and will be removed in the future. diff --git a/setup.py b/setup.py index 7c59f5645..3c7900669 100755 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ import struct import subprocess import sys +import sysconfig import tempfile import warnings @@ -65,6 +66,7 @@ PY37_PLUS = sys.version_info[:2] >= (3, 7) CP36_PLUS = PY36_PLUS and sys.implementation.name == "cpython" CP37_PLUS = PY37_PLUS and sys.implementation.name == "cpython" +Py_GIL_DISABLED = sysconfig.get_config_var("Py_GIL_DISABLED") macros = [] if POSIX: @@ -118,10 +120,10 @@ def get_version(): # Py_LIMITED_API lets us create a single wheel which works with multiple # python versions, including unreleased ones. -if bdist_wheel and CP36_PLUS and (MACOS or LINUX): +if bdist_wheel and CP36_PLUS and (MACOS or LINUX) and not Py_GIL_DISABLED: py_limited_api = {"py_limited_api": True} macros.append(('Py_LIMITED_API', '0x03060000')) -elif bdist_wheel and CP37_PLUS and WINDOWS: +elif bdist_wheel and CP37_PLUS and WINDOWS and not Py_GIL_DISABLED: # PyErr_SetFromWindowsErr / PyErr_SetFromWindowsErrWithFilename are # part of the stable API/ABI starting with CPython 3.7 py_limited_api = {"py_limited_api": True} From 553098524de5367c04a3e057b88208dc4b86aba4 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sat, 18 May 2024 20:04:11 +0200 Subject: [PATCH 2/2] chore(ci): update actions (#2417) --- .github/workflows/build.yml | 46 ++++++++++++++++++++++++++---------- .github/workflows/issues.yml | 2 +- Makefile | 2 +- pyproject.toml | 6 ++++- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5bd907fc6..c4e9c745e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,20 +37,30 @@ jobs: archs: "x86" steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + + # see https://cibuildwheel.pypa.io/en/stable/faq/#macos-building-cpython-38-wheels-on-arm64 + - name: "Install python 3.8 universal2 on macOS arm64" + if: runner.os == 'macOS' && runner.arch == 'ARM64' + uses: actions/setup-python@v5 + env: + PIP_DISABLE_PIP_VERSION_CHECK: 1 + with: + python-version: 3.8 + + - uses: actions/setup-python@v5 with: python-version: 3.11 - name: Create wheels + run tests - uses: pypa/cibuildwheel@v2.17.0 + uses: pypa/cibuildwheel@v2.18.0 env: CIBW_ARCHS: "${{ matrix.archs }}" CIBW_PRERELEASE_PYTHONS: True - name: Upload wheels - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: wheels + name: wheels-py3-${{ matrix.os }}-${{ startsWith(matrix.os, 'ubuntu') && 'all' || matrix.archs }} path: wheelhouse - name: Generate .tar.gz @@ -78,7 +88,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: 3.9 @@ -86,9 +96,9 @@ jobs: uses: pypa/cibuildwheel@v1.12.0 - name: Upload wheels - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: wheels + name: wheels-py2-${{ matrix.os }} path: wheelhouse - name: Generate .tar.gz @@ -103,24 +113,36 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: 3.x - name: 'Run linters' run: | - python3 -m pip install ruff==0.3.4 black rstcheck toml-sort sphinx + python3 -m pip install ruff==0.4.4 black rstcheck toml-sort sphinx make lint-all + # upload weels as a single artefact + upload-wheels: + needs: [py2, py3] + runs-on: ubuntu-latest + steps: + - uses: actions/upload-artifact/merge@v4 + with: + name: wheels + pattern: wheels-* + separate-directories: false + delete-merged: true + # Check sanity of .tar.gz + wheel files check-dist: - needs: [py2, py3] + needs: [upload-wheels] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: 3.x - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: wheels path: wheelhouse diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml index 3d3adbf83..a9f665eb6 100644 --- a/.github/workflows/issues.yml +++ b/.github/workflows/issues.yml @@ -15,7 +15,7 @@ jobs: # install python - uses: actions/checkout@v4 - name: Install Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.x' diff --git a/Makefile b/Makefile index e123a93c0..0406fb6da 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ PY3_DEPS = \ pypinfo \ requests \ rstcheck \ - ruff==0.3.4 \ + ruff==0.4.4 \ setuptools \ sphinx_rtd_theme \ teyit \ diff --git a/pyproject.toml b/pyproject.toml index 6f5bab2da..99a9b44d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -205,7 +205,11 @@ spaces_indent_inline_array = 4 trailing_comma_inline_array = true [tool.cibuildwheel] -skip = ["*-musllinux*", "pp*"] +skip = [ + "*-musllinux*", + "cp313-win*", # pywin32 is not available on cp313 yet + "pp*", +] test-command = [ "env PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_DEBUG=1 PSUTIL_SCRIPTS_DIR={project}/scripts python {project}/psutil/tests/runner.py", "env PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_DEBUG=1 PSUTIL_SCRIPTS_DIR={project}/scripts python {project}/psutil/tests/test_memleaks.py",