summaryrefslogtreecommitdiff
path: root/setup.py
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 /setup.py
parent1b09c1b54cb2ae46145de7f710e9b990cd264016 (diff)
downloadpsutil-614e91158ced7a65aabbe7244d52de1cebfc494b.tar.gz
feature: use ABI3 for cp36+ (#2102)
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py52
1 files changed, 43 insertions, 9 deletions
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',