From 97a8f11a8a039fc0de04a31d281715f1ce6ea4bc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Sep 2020 21:18:01 -0400 Subject: [PATCH] Restore pythonlib support on older Pythons. Fixes pypa/distutils#9. --- distutils/command/build_ext.py | 3 ++- distutils/command/py37compat.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 distutils/command/py37compat.py diff --git a/distutils/command/build_ext.py b/distutils/command/build_ext.py index 1a9bd1200f..bbb348331b 100644 --- a/distutils/command/build_ext.py +++ b/distutils/command/build_ext.py @@ -16,6 +16,7 @@ from distutils.extension import Extension from distutils.util import get_platform from distutils import log +from . import py37compat from site import USER_BASE @@ -751,4 +752,4 @@ def get_libraries(self, ext): ldversion = get_config_var('LDVERSION') return ext.libraries + ['python' + ldversion] - return ext.libraries + return ext.libraries + py37compat.pythonlib() diff --git a/distutils/command/py37compat.py b/distutils/command/py37compat.py new file mode 100644 index 0000000000..754715a508 --- /dev/null +++ b/distutils/command/py37compat.py @@ -0,0 +1,30 @@ +import sys + + +def _pythonlib_compat(): + """ + On Python 3.7 and earlier, distutils would include the Python + library. See pypa/distutils#9. + """ + from distutils import sysconfig + if not sysconfig.get_config_var('Py_ENABLED_SHARED'): + return + + yield 'python{}.{}{}'.format( + sys.hexversion >> 24, + (sys.hexversion >> 16) & 0xff, + sysconfig.get_config_var('ABIFLAGS'), + ) + + +def compose(f1, f2): + return lambda *args, **kwargs: f1(f2(*args, **kwargs)) + + +pythonlib = ( + compose(list, _pythonlib_compat) + if sys.version_info < (3, 8) + and sys.platform != 'darwin' + and sys.platform[:3] != 'aix' + else list +)