summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Darbois <mayeut@users.noreply.github.com>2022-10-21 01:02:23 +0200
committerGitHub <noreply@github.com>2022-10-21 01:02:23 +0200
commit614e91158ced7a65aabbe7244d52de1cebfc494b (patch)
treee69c295da7ebf41d4f6a11db6378e37916625f1a
parent1b09c1b54cb2ae46145de7f710e9b990cd264016 (diff)
downloadpsutil-614e91158ced7a65aabbe7244d52de1cebfc494b.tar.gz
feature: use ABI3 for cp36+ (#2102)
-rw-r--r--.ci/appveyor/install.ps185
-rw-r--r--.github/workflows/build.yml49
-rw-r--r--appveyor.yml45
-rw-r--r--psutil/_psutil_linux.c32
-rw-r--r--psutil/arch/windows/process_info.c2
-rw-r--r--pyproject.toml20
-rwxr-xr-xsetup.py52
7 files changed, 120 insertions, 165 deletions
diff --git a/.ci/appveyor/install.ps1 b/.ci/appveyor/install.ps1
deleted file mode 100644
index 3f056282..00000000
--- a/.ci/appveyor/install.ps1
+++ /dev/null
@@ -1,85 +0,0 @@
-# Sample script to install Python and pip under Windows
-# Authors: Olivier Grisel and Kyle Kastner
-# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
-
-$BASE_URL = "https://www.python.org/ftp/python/"
-$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
-$GET_PIP_PATH = "C:\get-pip.py"
-
-
-function DownloadPython ($python_version, $platform_suffix) {
- $webclient = New-Object System.Net.WebClient
- $filename = "python-" + $python_version + $platform_suffix + ".msi"
- $url = $BASE_URL + $python_version + "/" + $filename
-
- $basedir = $pwd.Path + "\"
- $filepath = $basedir + $filename
- if (Test-Path $filename) {
- Write-Host "Reusing" $filepath
- return $filepath
- }
-
- # Download and retry up to 5 times in case of network transient errors.
- Write-Host "Downloading" $filename "from" $url
- $retry_attempts = 3
- for($i=0; $i -lt $retry_attempts; $i++){
- try {
- $webclient.DownloadFile($url, $filepath)
- break
- }
- Catch [Exception]{
- Start-Sleep 1
- }
- }
- Write-Host "File saved at" $filepath
- return $filepath
-}
-
-
-function InstallPython ($python_version, $architecture, $python_home) {
- Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
- if (Test-Path $python_home) {
- Write-Host $python_home "already exists, skipping."
- return $false
- }
- if ($architecture -eq "32") {
- $platform_suffix = ""
- } else {
- $platform_suffix = ".amd64"
- }
- $filepath = DownloadPython $python_version $platform_suffix
- Write-Host "Installing" $filepath "to" $python_home
- $args = "/qn /i $filepath TARGETDIR=$python_home"
- Write-Host "msiexec.exe" $args
- Start-Process -FilePath "msiexec.exe" -ArgumentList $args -Wait -Passthru
- Write-Host "Python $python_version ($architecture) installation complete"
- return $true
-}
-
-
-function InstallPip ($python_home) {
- $pip_path = $python_home + "/Scripts/pip.exe"
- $python_path = $python_home + "/python.exe"
- if (-not(Test-Path $pip_path)) {
- Write-Host "Installing pip..."
- $webclient = New-Object System.Net.WebClient
- $webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH)
- Write-Host "Executing:" $python_path $GET_PIP_PATH
- Start-Process -FilePath "$python_path" -ArgumentList "$GET_PIP_PATH" -Wait -Passthru
- } else {
- Write-Host "pip already installed."
- }
-}
-
-function InstallPackage ($python_home, $pkg) {
- $pip_path = $python_home + "/Scripts/pip.exe"
- & $pip_path install $pkg
-}
-
-function main () {
- InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
- InstallPip $env:PYTHON
- InstallPackage $env:PYTHON wheel
-}
-
-main
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e572b029..3a52c8fe 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -20,15 +20,15 @@
on: [push, pull_request]
name: build
jobs:
- # Linux + macOS + Python 3
- linux-macos-py3:
+ # Linux + macOS + Windows Python 3
+ py3:
name: ${{ matrix.os }}-py3
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
- os: [ubuntu-latest, macos-12]
+ os: [ubuntu-latest, macos-12, windows-2019]
steps:
- name: Cancel previous runs
@@ -60,6 +60,49 @@ jobs:
mv dist/psutil*.tar.gz wheelhouse/
python scripts/internal/print_hashes.py wheelhouse/
+ # Windows cp37+ tests
+ # psutil tests do not like running from a virtualenv with python>=3.7 so
+ # not using cibuildwheel for those. run them "manually" with this job.
+ windows-py3-test:
+ name: windows-py3-test-${{ matrix.python }}-${{ matrix.architecture }}
+ needs: py3
+ runs-on: windows-2019
+ timeout-minutes: 20
+ strategy:
+ fail-fast: false
+ matrix:
+ python: ["3.7", "3.8", "3.9", "3.10", "~3.11.0-0"]
+ architecture: ["x86", "x64"]
+
+ steps:
+ - name: Cancel previous runs
+ uses: styfle/cancel-workflow-action@0.9.1
+ with:
+ access_token: ${{ github.token }}
+ - uses: actions/checkout@v3
+ - uses: actions/setup-python@v4
+ with:
+ python-version: "${{ matrix.python }}"
+ architecture: "${{ matrix.architecture }}"
+ cache: pip
+ cache-dependency-path: .github/workflows/build.yml
+ - name: Download wheels
+ uses: actions/download-artifact@v3
+ with:
+ name: wheels
+ path: wheelhouse
+ - name: Run tests
+ run: |
+ mkdir .tests
+ cd .tests
+ pip install $(find ../wheelhouse -name '*-cp36-abi3-${{ matrix.architecture == 'x86' && 'win32' || 'win_amd64'}}.whl')[test]
+ export PYTHONWARNINGS=always
+ export PYTHONUNBUFFERED=1
+ export PSUTIL_DEBUG=1
+ python ../psutil/tests/runner.py
+ python ../psutil/tests/test_memleaks.py
+ shell: bash
+
# Linux + macOS + Python 2
linux-macos-py2:
name: ${{ matrix.os }}-py2
diff --git a/appveyor.yml b/appveyor.yml
index 4bbd51ae..0752e610 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -24,62 +24,17 @@ environment:
PYTHON_VERSION: "2.7.x"
PYTHON_ARCH: "32"
- - PYTHON: "C:\\Python36"
- PYTHON_VERSION: "3.6.x"
- PYTHON_ARCH: "32"
-
- - PYTHON: "C:\\Python37"
- PYTHON_VERSION: "3.7.x"
- PYTHON_ARCH: "32"
-
- - PYTHON: "C:\\Python38"
- PYTHON_VERSION: "3.8.x"
- PYTHON_ARCH: "32"
-
- - PYTHON: "C:\\Python39"
- PYTHON_VERSION: "3.9.x"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON_ARCH: "32"
-
- - PYTHON: "C:\\Python310"
- PYTHON_VERSION: "3.10.x"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON_ARCH: "32"
-
# 64 bits
- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.x"
PYTHON_ARCH: "64"
- - PYTHON: "C:\\Python36-x64"
- PYTHON_VERSION: "3.6.x"
- PYTHON_ARCH: "64"
-
- - PYTHON: "C:\\Python37-x64"
- PYTHON_VERSION: "3.7.x"
- PYTHON_ARCH: "64"
-
- - PYTHON: "C:\\Python38-x64"
- PYTHON_VERSION: "3.8.x"
- PYTHON_ARCH: "64"
-
- - PYTHON: "C:\\Python39-x64"
- PYTHON_VERSION: "3.9.x"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON_ARCH: "64"
-
- - PYTHON: "C:\\Python310-x64"
- PYTHON_VERSION: "3.10.x"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON_ARCH: "64"
init:
- "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH%"
install:
- - "powershell .ci\\appveyor\\install.ps1"
- # - ps: (new-object net.webclient).DownloadFile('https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 'C:/get-pip.py')
- "%WITH_COMPILER% %PYTHON%/python.exe -m pip --version"
- "%WITH_COMPILER% %PYTHON%/python.exe -m pip install --upgrade --user setuptools pip"
- "%WITH_COMPILER% %PYTHON%/python.exe scripts/internal/winmake.py setup-dev-env"
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 64cdf0b5..1ed1f91a 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -296,52 +296,46 @@ psutil_proc_cpu_affinity_set(PyObject *self, PyObject *args) {
cpu_set_t cpu_set;
size_t len;
pid_t pid;
- int i, seq_len;
+ Py_ssize_t i, seq_len;
PyObject *py_cpu_set;
- PyObject *py_cpu_seq = NULL;
if (!PyArg_ParseTuple(args, _Py_PARSE_PID "O", &pid, &py_cpu_set))
return NULL;
if (!PySequence_Check(py_cpu_set)) {
- PyErr_Format(PyExc_TypeError, "sequence argument expected, got %s",
- Py_TYPE(py_cpu_set)->tp_name);
- goto error;
+ return PyErr_Format(PyExc_TypeError, "sequence argument expected, got %R", Py_TYPE(py_cpu_set));
}
- py_cpu_seq = PySequence_Fast(py_cpu_set, "expected a sequence or integer");
- if (!py_cpu_seq)
- goto error;
- seq_len = PySequence_Fast_GET_SIZE(py_cpu_seq);
+ seq_len = PySequence_Size(py_cpu_set);
+ if (seq_len < 0) {
+ return NULL;
+ }
CPU_ZERO(&cpu_set);
for (i = 0; i < seq_len; i++) {
- PyObject *item = PySequence_Fast_GET_ITEM(py_cpu_seq, i);
+ PyObject *item = PySequence_GetItem(py_cpu_set, i);
+ if (!item) {
+ return NULL;
+ }
#if PY_MAJOR_VERSION >= 3
long value = PyLong_AsLong(item);
#else
long value = PyInt_AsLong(item);
#endif
+ Py_XDECREF(item);
if ((value == -1) || PyErr_Occurred()) {
if (!PyErr_Occurred())
PyErr_SetString(PyExc_ValueError, "invalid CPU value");
- goto error;
+ return NULL;
}
CPU_SET(value, &cpu_set);
}
len = sizeof(cpu_set);
if (sched_setaffinity(pid, len, &cpu_set)) {
- PyErr_SetFromErrno(PyExc_OSError);
- goto error;
+ return PyErr_SetFromErrno(PyExc_OSError);
}
- Py_DECREF(py_cpu_seq);
Py_RETURN_NONE;
-
-error:
- if (py_cpu_seq != NULL)
- Py_DECREF(py_cpu_seq);
- return NULL;
}
#endif /* PSUTIL_HAVE_CPU_AFFINITY */
diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c
index d44c4eb7..1981d306 100644
--- a/psutil/arch/windows/process_info.c
+++ b/psutil/arch/windows/process_info.c
@@ -578,7 +578,7 @@ psutil_get_cmdline(DWORD pid, int use_peb) {
wcslen(szArglist[i]));
if (py_unicode == NULL)
goto out;
- PyList_SET_ITEM(py_retlist, i, py_unicode);
+ PyList_SetItem(py_retlist, i, py_unicode);
py_unicode = NULL;
}
ret = py_retlist;
diff --git a/pyproject.toml b/pyproject.toml
index 52d4c728..87b84fc6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -38,12 +38,11 @@ exclude_lines = [
]
[build-system]
-requires = ["setuptools>=43"]
+requires = ["setuptools>=43", "wheel"]
build-backend = "setuptools.build_meta"
[tool.cibuildwheel]
-build = ["cp36-*", "cp37-*", "cp38-*", "cp39-*", "cp310-*"]
-skip = ["*-musllinux*"]
+skip = ["pp*", "*-musllinux*"]
test-extras = "test"
test-command = [
"PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_DEBUG=1 python {project}/psutil/tests/runner.py",
@@ -52,3 +51,18 @@ test-command = [
[tool.cibuildwheel.macos]
archs = ["x86_64", "arm64"]
+
+[tool.cibuildwheel.windows]
+# psutil tests do not like running from a virtualenv with python>=3.7
+# restrict build & tests to cp36
+# cp36-abi3 wheels will need to be tested outside cibuildwheel for python>=3.7
+build = "cp36-*"
+test-command = [
+ "python {project}/psutil/tests/runner.py",
+ "python {project}/psutil/tests/test_memleaks.py"
+]
+
+[tool.cibuildwheel.windows.environment]
+PYTHONWARNINGS = "always"
+PYTHONUNBUFFERED = "1"
+PSUTIL_DEBUG = "1"
diff --git a/setup.py b/setup.py
index 0f6716b3..b3f20666 100755
--- a/setup.py
+++ b/setup.py
@@ -31,6 +31,12 @@ with warnings.catch_warnings():
setuptools = None
from distutils.core import Extension
from distutils.core import setup
+ try:
+ from wheel.bdist_wheel import bdist_wheel
+ except ImportError:
+ if "CIBUILDWHEEL" in os.environ:
+ raise
+ bdist_wheel = None
HERE = os.path.abspath(os.path.dirname(__file__))
@@ -53,6 +59,9 @@ from _compat import which # NOQA
PYPY = '__pypy__' in sys.builtin_module_names
+PY36_PLUS = sys.version_info[:2] >= (3, 6)
+CP36_PLUS = PY36_PLUS and sys.implementation.name == "cpython"
+
macros = []
if POSIX:
macros.append(("PSUTIL_POSIX", 1))
@@ -100,6 +109,12 @@ def get_version():
VERSION = get_version()
macros.append(('PSUTIL_VERSION', int(VERSION.replace('.', ''))))
+if bdist_wheel and CP36_PLUS and (MACOS or LINUX or WINDOWS):
+ py_limited_api = {"py_limited_api": True}
+ macros.append(('Py_LIMITED_API', '0x03060000'))
+else:
+ py_limited_api = {}
+
def get_description():
script = os.path.join(HERE, "scripts", "internal", "convert_readme.py")
@@ -182,7 +197,8 @@ if WINDOWS:
"ws2_32", "PowrProf", "pdh",
],
# extra_compile_args=["/W 4"],
- # extra_link_args=["/DEBUG"]
+ # extra_link_args=["/DEBUG"],
+ **py_limited_api
)
elif MACOS:
@@ -197,7 +213,8 @@ elif MACOS:
define_macros=macros,
extra_link_args=[
'-framework', 'CoreFoundation', '-framework', 'IOKit'
- ])
+ ],
+ **py_limited_api)
elif FREEBSD:
macros.append(("PSUTIL_FREEBSD", 1))
@@ -214,7 +231,8 @@ elif FREEBSD:
'psutil/arch/freebsd/proc_socks.c',
],
define_macros=macros,
- libraries=["devstat"])
+ libraries=["devstat"],
+ **py_limited_api)
elif OPENBSD:
macros.append(("PSUTIL_OPENBSD", 1))
@@ -228,7 +246,8 @@ elif OPENBSD:
'psutil/arch/openbsd/proc.c',
],
define_macros=macros,
- libraries=["kvm"])
+ libraries=["kvm"],
+ **py_limited_api)
elif NETBSD:
macros.append(("PSUTIL_NETBSD", 1))
@@ -240,7 +259,8 @@ elif NETBSD:
'psutil/arch/netbsd/socks.c',
],
define_macros=macros,
- libraries=["kvm"])
+ libraries=["kvm"],
+ **py_limited_api)
elif LINUX:
def get_ethtool_macro():
@@ -276,7 +296,8 @@ elif LINUX:
ext = Extension(
'psutil._psutil_linux',
sources=sources + ['psutil/_psutil_linux.c'],
- define_macros=macros)
+ define_macros=macros,
+ **py_limited_api)
elif SUNOS:
macros.append(("PSUTIL_SUNOS", 1))
@@ -288,7 +309,8 @@ elif SUNOS:
'psutil/arch/solaris/environ.c'
],
define_macros=macros,
- libraries=['kstat', 'nsl', 'socket'])
+ libraries=['kstat', 'nsl', 'socket'],
+ **py_limited_api)
elif AIX:
macros.append(("PSUTIL_AIX", 1))
@@ -300,7 +322,8 @@ elif AIX:
'psutil/arch/aix/common.c',
'psutil/arch/aix/ifaddrs.c'],
libraries=['perfstat'],
- define_macros=macros)
+ define_macros=macros,
+ **py_limited_api)
else:
sys.exit('platform %s is not supported' % sys.platform)
@@ -310,7 +333,8 @@ if POSIX:
posix_extension = Extension(
'psutil._psutil_posix',
define_macros=macros,
- sources=sources)
+ sources=sources,
+ **py_limited_api)
if SUNOS:
def get_sunos_update():
# See https://serverfault.com/q/524883
@@ -341,11 +365,21 @@ if POSIX:
else:
extensions = [ext]
+cmdclass = {}
+if py_limited_api:
+ class bdist_wheel_abi3(bdist_wheel):
+ def get_tag(self):
+ python, abi, plat = bdist_wheel.get_tag(self)
+ return python, "abi3", plat
+
+ cmdclass["bdist_wheel"] = bdist_wheel_abi3
+
def main():
kwargs = dict(
name='psutil',
version=VERSION,
+ cmdclass=cmdclass,
description=__doc__ .replace('\n', ' ').strip() if __doc__ else '',
long_description=get_description(),
long_description_content_type='text/x-rst',