From bcd1916ea6ce60c74e545c9ed6dd1597b81694bc Mon Sep 17 00:00:00 2001 From: Long Nguyen Date: Sun, 5 Sep 2021 23:17:11 +0700 Subject: [PATCH 1/7] Prefer sysconfig.python_build --- distutils/command/build_ext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/command/build_ext.py b/distutils/command/build_ext.py index f7ab32cfe1..22628baf90 100644 --- a/distutils/command/build_ext.py +++ b/distutils/command/build_ext.py @@ -220,7 +220,7 @@ def finalize_options(self): # For extensions under Cygwin, Python's library directory must be # appended to library_dirs if sys.platform[:6] == 'cygwin': - if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): + if not sysconfig.python_build: # building third party extensions self.library_dirs.append(os.path.join(sys.prefix, "lib", "python" + get_python_version(), From 7e16c3560e1f637f5e1638e03d02db829aeb7296 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Fri, 10 Sep 2021 17:57:04 +0300 Subject: [PATCH 2/7] adopt more standard schema for pypy3.8 (#51) --- distutils/command/install.py | 1 + distutils/sysconfig.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index 400fb45dd0..866e2d5971 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -470,6 +470,7 @@ def select_scheme(self, name): """Sets the install directories by applying the install schemes.""" # it's the caller's problem if they supply a bad name! if (hasattr(sys, 'pypy_version_info') and + sys.version_info < (3, 8) and not name.endswith(('_user', '_home'))): if os.name == 'nt': name = 'pypy_nt' diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index 879b6981ed..efb7b3d421 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -99,9 +99,9 @@ def get_python_inc(plat_specific=0, prefix=None): """ if prefix is None: prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX - if IS_PYPY: - return os.path.join(prefix, 'include') - elif os.name == "posix": + if os.name == "posix": + if IS_PYPY and sys.version_info < (3, 8): + return os.path.join(prefix, 'include') if python_build: # Assume the executable is in the build directory. The # pyconfig.h file should be in the same directory. Since @@ -113,7 +113,8 @@ def get_python_inc(plat_specific=0, prefix=None): else: incdir = os.path.join(get_config_var('srcdir'), 'Include') return os.path.normpath(incdir) - python_dir = 'python' + get_python_version() + build_flags + implementation = 'pypy' if IS_PYPY else 'python' + python_dir = implementation + get_python_version() + build_flags return os.path.join(prefix, "include", python_dir) elif os.name == "nt": if python_build: @@ -142,7 +143,8 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): If 'prefix' is supplied, use it instead of sys.base_prefix or sys.base_exec_prefix -- i.e., ignore 'plat_specific'. """ - if IS_PYPY: + + if IS_PYPY and sys.version_info < (3, 8): # PyPy-specific schema if prefix is None: prefix = PREFIX @@ -164,8 +166,9 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): else: # Pure Python libdir = "lib" + implementation = 'pypy' if IS_PYPY else 'python' libpython = os.path.join(prefix, libdir, - "python" + get_python_version()) + implementation + get_python_version()) if standard_lib: return libpython else: From 887749a40489c21c682794cc9c56f827c92f90dd Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 4 Sep 2021 22:14:18 -0500 Subject: [PATCH 3/7] Support overriding ranlib on macOS with env var --- distutils/sysconfig.py | 5 ++++- distutils/tests/test_sysconfig.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index efb7b3d421..871f93f546 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -143,7 +143,7 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): If 'prefix' is supplied, use it instead of sys.base_prefix or sys.base_exec_prefix -- i.e., ignore 'plat_specific'. """ - + if IS_PYPY and sys.version_info < (3, 8): # PyPy-specific schema if prefix is None: @@ -255,6 +255,9 @@ def customize_compiler(compiler): linker_exe=cc, archiver=archiver) + if 'RANLIB' in os.environ and compiler.executables.get('ranlib', None): + compiler.set_executables(ranlib=os.environ['RANLIB']) + compiler.shared_lib_extension = shlib_suffix diff --git a/distutils/tests/test_sysconfig.py b/distutils/tests/test_sysconfig.py index c757194288..80cd1599a7 100644 --- a/distutils/tests/test_sysconfig.py +++ b/distutils/tests/test_sysconfig.py @@ -9,6 +9,7 @@ from distutils import sysconfig from distutils.ccompiler import get_default_compiler +from distutils.unixccompiler import UnixCCompiler from distutils.tests import support from test.support import run_unittest, swap_item @@ -84,9 +85,14 @@ def customize_compiler(self): # make sure AR gets caught class compiler: compiler_type = 'unix' + executables = UnixCCompiler.executables + + def __init__(self): + self.exes = {} def set_executables(self, **kw): - self.exes = kw + for k, v in kw.items(): + self.exes[k] = v sysconfig_vars = { 'AR': 'sc_ar', @@ -125,6 +131,7 @@ def test_customize_compiler(self): os.environ['ARFLAGS'] = '--env-arflags' os.environ['CFLAGS'] = '--env-cflags' os.environ['CPPFLAGS'] = '--env-cppflags' + os.environ['RANLIB'] = 'env_ranlib' comp = self.customize_compiler() self.assertEqual(comp.exes['archiver'], @@ -145,6 +152,12 @@ def test_customize_compiler(self): ' --env-cppflags')) self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix') + if sys.platform == "darwin": + self.assertEqual(comp.exes['ranlib'], + 'env_ranlib') + else: + self.assertTrue('ranlib' not in comp.exes) + del os.environ['AR'] del os.environ['CC'] del os.environ['CPP'] @@ -154,6 +167,7 @@ def test_customize_compiler(self): del os.environ['ARFLAGS'] del os.environ['CFLAGS'] del os.environ['CPPFLAGS'] + del os.environ['RANLIB'] comp = self.customize_compiler() self.assertEqual(comp.exes['archiver'], @@ -171,6 +185,7 @@ def test_customize_compiler(self): self.assertEqual(comp.exes['linker_so'], 'sc_ldshared') self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix') + self.assertTrue('ranlib' not in comp.exes) def test_parse_makefile_base(self): self.makefile = TESTFN From 10988e02871fdb63de9671213bfe55af7c6f2381 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 16 Sep 2021 14:42:19 -0500 Subject: [PATCH 4/7] override ldshared on non-macos platforms too if CC is overriden --- distutils/sysconfig.py | 5 ++--- distutils/tests/test_unixccompiler.py | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index 871f93f546..8832b3eceb 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -214,10 +214,9 @@ def customize_compiler(compiler): if 'CC' in os.environ: newcc = os.environ['CC'] - if (sys.platform == 'darwin' - and 'LDSHARED' not in os.environ + if('LDSHARED' not in os.environ and ldshared.startswith(cc)): - # On OS X, if CC is overridden, use that as the default + # If CC is overridden, use that as the default # command for LDSHARED as well ldshared = newcc + ldshared[len(cc):] cc = newcc diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index ebd7c161e0..d8ebae1cc8 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -181,8 +181,8 @@ def gcv(v): sysconfig.get_config_var = gcv self.assertEqual(self.cc.rpath_foo(), '-R/foo') - @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X') - def test_osx_cc_overrides_ldshared(self): + @unittest.skipIf(sys.platform == 'win32', "can't test on Windows") + def test_cc_overrides_ldshared(self): # Issue #18080: # ensure that setting CC env variable also changes default linker def gcv(v): @@ -202,8 +202,8 @@ def gcvs(*args, _orig=sysconfig.get_config_vars): sysconfig.customize_compiler(self.cc) self.assertEqual(self.cc.linker_so[0], 'my_cc') - @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X') - def test_osx_explicit_ldshared(self): + @unittest.skipIf(sys.platform == 'win32', "can't test on Windows") + def test_explicit_ldshared(self): # Issue #18080: # ensure that setting CC env variable does not change # explicit LDSHARED setting for linker From f182b5e2f6e492cd13eed98d7f248d4146456d8c Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 16 Sep 2021 14:57:08 -0500 Subject: [PATCH 5/7] Split CC to make sure we get the correct basename of the compiler --- distutils/tests/test_unixccompiler.py | 8 ++++++++ distutils/unixccompiler.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index ebd7c161e0..fb9ac03224 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -140,6 +140,14 @@ def gcv(v): sysconfig.get_config_var = gcv self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo') + def gcv(v): + if v == 'CC': + return 'gcc -pthread -B /bar' + elif v == 'GNULD': + return 'yes' + sysconfig.get_config_var = gcv + self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo') + # GCC non-GNULD sys.platform = 'bar' def gcv(v): diff --git a/distutils/unixccompiler.py b/distutils/unixccompiler.py index f51977a5ae..c6f1f0d66a 100644 --- a/distutils/unixccompiler.py +++ b/distutils/unixccompiler.py @@ -231,7 +231,7 @@ def runtime_library_dir_option(self, dir): # this time, there's no way to determine this information from # the configuration data stored in the Python installation, so # we use this hack. - compiler = os.path.basename(sysconfig.get_config_var("CC")) + compiler = os.path.basename(sysconfig.get_config_var("CC").split(" ")[0]) if sys.platform[:6] == "darwin": from distutils.util import get_macosx_target_ver, split_version macosx_target_ver = get_macosx_target_ver() From c51dc8c8e970c012c7c841f30e576c5a343e02e1 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 21 Sep 2021 12:21:33 -0500 Subject: [PATCH 6/7] Use shlex Co-authored-by: "Jason R. Coombs" --- distutils/unixccompiler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distutils/unixccompiler.py b/distutils/unixccompiler.py index c6f1f0d66a..349cc1642b 100644 --- a/distutils/unixccompiler.py +++ b/distutils/unixccompiler.py @@ -13,7 +13,7 @@ * link shared library handled by 'cc -shared' """ -import os, sys, re +import os, sys, re, shlex from distutils import sysconfig from distutils.dep_util import newer @@ -231,7 +231,7 @@ def runtime_library_dir_option(self, dir): # this time, there's no way to determine this information from # the configuration data stored in the Python installation, so # we use this hack. - compiler = os.path.basename(sysconfig.get_config_var("CC").split(" ")[0]) + compiler = os.path.basename(shlex.split(sysconfig.get_config_var("CC"))[0]) if sys.platform[:6] == "darwin": from distutils.util import get_macosx_target_ver, split_version macosx_target_ver = get_macosx_target_ver() From 228c2e2c0e2c0b7930ae1d8a1ff650f585a3b9ca Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 21 Sep 2021 13:42:20 -0400 Subject: [PATCH 7/7] Add changelog --- changelog.d/2796.change.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/2796.change.rst diff --git a/changelog.d/2796.change.rst b/changelog.d/2796.change.rst new file mode 100644 index 0000000000..713743d529 --- /dev/null +++ b/changelog.d/2796.change.rst @@ -0,0 +1 @@ +Merge with pypa/distutils@02e9f65ab0