From 6527ae87347303ba558a329b56357bbd421d6f43 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 21 Dec 2024 09:52:40 +0100 Subject: [PATCH 1/5] wheels: build freethreading wheels Signed-off-by: mayeut --- .github/workflows/build.yml | 2 +- HISTORY.rst | 1 + pyproject.toml | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f609ee651..d4b8d38b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,7 +56,7 @@ jobs: uses: pypa/cibuildwheel@v2.22.0 env: CIBW_ARCHS: "${{ matrix.arch }}" - CIBW_ENABLE: "cpython-prerelease" + CIBW_ENABLE: "${{ startsWith(github.ref, 'refs/tags/') && '' || 'cpython-prerelease' }}" CIBW_TEST_EXTRAS: test CIBW_TEST_COMMAND: make -C {project} PYTHON="env python" PSUTIL_SCRIPTS_DIR="{project}/scripts" install-sysdeps install-pydeps-test install print-sysinfo test test-memleaks diff --git a/HISTORY.rst b/HISTORY.rst index 39bb66157..173e514b1 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,7 @@ XXXX-XX-XX **Enhancements** +- 2476_: Build Python 3.13t (free-threading) wheels - 2480_: Python 2.7 is no longer supported. Latest version supporting Python 2.7 is psutil 6.1.X. Install it with: ``pip2 install psutil==6.1.*``. - 2490_: removed long deprecated ``Process.memory_info_ex()`` method. It was diff --git a/pyproject.toml b/pyproject.toml index f6eb772d8..e0d2eb8af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -223,10 +223,11 @@ trailing_comma_inline_array = true [tool.cibuildwheel] skip = [ "*-musllinux*", - "cp313-win*", # pywin32 is not available on cp313 yet "cp3{7,8,9,10,11,12}-*linux_{aarch64,ppc64le,s390x}", # Only test cp36/cp313 on qemu tested architectures "pp*", ] +enable = ["cpython-freethreading"] +test-skip = ["cp3*t-win*"] # pywin32 is not available for free-threaded python yet, https://github.com/mhammond/pywin32/issues/2303 [tool.cibuildwheel.macos] archs = ["arm64", "x86_64"] From 766a1436cc56492742ed267440867c584d2be847 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 29 Dec 2024 12:05:06 +0100 Subject: [PATCH 2/5] fix: TestProcess.test_name when using a PythonT.framework install --- psutil/tests/test_process.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 1d81d498f..4b999760d 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -798,7 +798,13 @@ def test_long_cmdline(self): def test_name(self): p = self.spawn_psproc() name = p.name().lower() - pyexe = os.path.basename(os.path.realpath(sys.executable)).lower() + pypath = os.path.realpath(sys.executable) + if pypath.startswith("/Library/Frameworks/PythonT.framework/"): + # macOS Framework installations of Python can have their process + # replaced by PythonT using execve / posix_spawn + assert name == "pythont" + pypath = psutil.Process().cmdline()[0] + pyexe = os.path.basename(pypath).lower() assert pyexe.startswith(name), (pyexe, name) @pytest.mark.skipif(PYPY or QEMU_USER, reason="unreliable on PYPY") From 6c88fd7a399c571d1d5d1f79ce479a2e35b9ee13 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 29 Dec 2024 12:24:12 +0100 Subject: [PATCH 3/5] fix: scripts/internal/install-sysdeps.sh Does nothing on Darwin / macOS but that's supported. --- scripts/internal/install-sysdeps.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/internal/install-sysdeps.sh b/scripts/internal/install-sysdeps.sh index 003a7d081..830ab5e88 100755 --- a/scripts/internal/install-sysdeps.sh +++ b/scripts/internal/install-sysdeps.sh @@ -29,6 +29,9 @@ case "$UNAME_S" in OpenBSD) OPENBSD=true ;; + Darwin) + DARWIN=true + ;; esac # Check if running as root @@ -54,6 +57,8 @@ main() { $SUDO pkgin -y install python311-* gcc12-* elif [ $OPENBSD ]; then $SUDO pkg_add gcc python3 + elif [ $DARWIN ]; then + : else echo "Unsupported platform: $UNAME_S" fi From d76f68a97b8ae1fe5fd57bd5e228e9cfdf39a598 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 29 Dec 2024 12:01:44 +0100 Subject: [PATCH 4/5] fix: wheel tests --- .github/workflows/build.yml | 3 --- .gitignore | 1 + Makefile | 6 ++++++ pyproject.toml | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4b8d38b6..1e2b0a8e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,9 +57,6 @@ jobs: env: CIBW_ARCHS: "${{ matrix.arch }}" CIBW_ENABLE: "${{ startsWith(github.ref, 'refs/tags/') && '' || 'cpython-prerelease' }}" - CIBW_TEST_EXTRAS: test - CIBW_TEST_COMMAND: - make -C {project} PYTHON="env python" PSUTIL_SCRIPTS_DIR="{project}/scripts" install-sysdeps install-pydeps-test install print-sysinfo test test-memleaks - name: Upload wheels uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index ddafc64c6..d9f3d671b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ syntax: glob build/ dist/ wheelhouse/ +.tests/ diff --git a/Makefile b/Makefile index 3e74e8c7d..188169c72 100644 --- a/Makefile +++ b/Makefile @@ -162,6 +162,12 @@ test-coverage: ## Run test coverage. $(PYTHON) -m coverage html $(PYTHON) -m webbrowser -t htmlcov/index.html +test-ci: install-sysdeps + mkdir -p .tests + cd .tests/ && $(PYTHON) -c "from psutil.tests import print_sysinfo; print_sysinfo()" + cd .tests/ && $(PYTHON_ENV_VARS) PYTEST_ADDOPTS="-k 'not test_memleaks.py'" $(PYTHON) -m pytest $(PYTEST_ARGS) --pyargs psutil.tests + cd .tests/ && $(PYTHON_ENV_VARS) PYTEST_ADDOPTS="-k 'test_memleaks.py'" $(PYTHON) -m pytest $(PYTEST_ARGS) --pyargs psutil.tests + # =================================================================== # Linters # =================================================================== diff --git a/pyproject.toml b/pyproject.toml index e0d2eb8af..033ac74af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -227,6 +227,8 @@ skip = [ "pp*", ] enable = ["cpython-freethreading"] +test-extras = ["test"] +test-command = "make -C {project} PYTHON=python PSUTIL_SCRIPTS_DIR=\"{project}/scripts\" test-ci" test-skip = ["cp3*t-win*"] # pywin32 is not available for free-threaded python yet, https://github.com/mhammond/pywin32/issues/2303 [tool.cibuildwheel.macos] From bb312b66d115a6649831978da24465ad0c86c2d0 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 29 Dec 2024 14:27:51 +0100 Subject: [PATCH 5/5] fix: test_proc_net_connections On macOS, at least on macOS arm64>=14, python3.13t, there's an existing UNIX socket on syslog. Rework the test to ignore pre-existing sockets & just search for the newly created one. --- psutil/tests/test_unicode.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py index d8a8c4bfc..3c736630b 100755 --- a/psutil/tests/test_unicode.py +++ b/psutil/tests/test_unicode.py @@ -229,9 +229,12 @@ def test_proc_net_connections(self): name = self.get_testfn(suffix=self.funky_suffix) sock = bind_unix_socket(name) with closing(sock): - conn = psutil.Process().net_connections('unix')[0] - assert isinstance(conn.laddr, str) - assert conn.laddr == name + conns = psutil.Process().net_connections('unix') + for conn in conns: + assert isinstance(conn.laddr, str) + if conn.laddr == name: + return + raise ValueError("connection not found") @pytest.mark.skipif(not POSIX, reason="POSIX only") @pytest.mark.skipif(