diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2022-04-10 12:43:56 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2022-04-10 12:43:56 -0400 |
| commit | f4d31740584b1c9f45ad00cf62ff58c3418173a7 (patch) | |
| tree | 4cc403f6361da657f00b2de6daabbedfb42584d3 /setuptools/_distutils | |
| parent | e5552d3c42eddc463788861ae4c8847183eeec1c (diff) | |
| parent | 5229dad46bf61e5c15695c76b17860c1466eb5c5 (diff) | |
| download | python-setuptools-git-f4d31740584b1c9f45ad00cf62ff58c3418173a7.tar.gz | |
Merge https://github.com/pypa/distutils into feature/distutils-5229dad46b
Diffstat (limited to 'setuptools/_distutils')
| -rw-r--r-- | setuptools/_distutils/command/build.py | 3 | ||||
| -rw-r--r-- | setuptools/_distutils/py39compat.py | 21 | ||||
| -rw-r--r-- | setuptools/_distutils/sysconfig.py | 33 | ||||
| -rw-r--r-- | setuptools/_distutils/tests/test_build.py | 6 | ||||
| -rw-r--r-- | setuptools/_distutils/tests/test_install.py | 7 | ||||
| -rw-r--r-- | setuptools/_distutils/tests/test_sysconfig.py | 10 | ||||
| -rw-r--r-- | setuptools/_distutils/version.py | 4 |
7 files changed, 64 insertions, 20 deletions
diff --git a/setuptools/_distutils/command/build.py b/setuptools/_distutils/command/build.py index 4355a632..9606b81a 100644 --- a/setuptools/_distutils/command/build.py +++ b/setuptools/_distutils/command/build.py @@ -81,7 +81,8 @@ class build(Command): "--plat-name only supported on Windows (try " "using './configure --help' on your platform)") - plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2]) + plat_specifier = ".%s-%s" % (self.plat_name, + sys.implementation.cache_tag) # Make it so Python 2.x and Python 2.x with --with-pydebug don't # share the same build directories. Doing so confuses the build diff --git a/setuptools/_distutils/py39compat.py b/setuptools/_distutils/py39compat.py new file mode 100644 index 00000000..9de95013 --- /dev/null +++ b/setuptools/_distutils/py39compat.py @@ -0,0 +1,21 @@ +import sys +import platform + + +def add_ext_suffix_39(vars): + """ + Ensure vars contains 'EXT_SUFFIX'. pypa/distutils#130 + """ + import _imp + ext_suffix = _imp.extension_suffixes()[0] + vars.update( + EXT_SUFFIX=ext_suffix, + # sysconfig sets SO to match EXT_SUFFIX, so maintain + # that expectation. + # https://github.com/python/cpython/blob/785cc6770588de087d09e89a69110af2542be208/Lib/sysconfig.py#L671-L673 + SO=ext_suffix, + ) + + +needs_ext_suffix = sys.version_info < (3, 10) and platform.system() == 'Windows' +add_ext_suffix = add_ext_suffix_39 if needs_ext_suffix else lambda vars: None diff --git a/setuptools/_distutils/sysconfig.py b/setuptools/_distutils/sysconfig.py index 9fad3835..55a42e16 100644 --- a/setuptools/_distutils/sysconfig.py +++ b/setuptools/_distutils/sysconfig.py @@ -9,13 +9,13 @@ Written by: Fred L. Drake, Jr. Email: <fdrake@acm.org> """ -import _imp import os import re import sys import sysconfig from .errors import DistutilsPlatformError +from . import py39compat IS_PYPY = '__pypy__' in sys.builtin_module_names @@ -48,6 +48,7 @@ def _is_python_source_dir(d): return True return False + _sys_home = getattr(sys, '_home', None) if os.name == 'nt': @@ -59,11 +60,13 @@ if os.name == 'nt': project_base = _fix_pcbuild(project_base) _sys_home = _fix_pcbuild(_sys_home) + def _python_build(): if _sys_home: return _is_python_source_dir(_sys_home) return _is_python_source_dir(project_base) + python_build = _python_build() @@ -79,6 +82,7 @@ except AttributeError: # this attribute, which is fine. pass + def get_python_version(): """Return a string containing the major and minor Python version, leaving off the patchlevel. Sample return values could be '1.5' @@ -192,7 +196,6 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): "on platform '%s'" % os.name) - def customize_compiler(compiler): """Do any platform-specific customization of a CCompiler instance. @@ -217,8 +220,9 @@ def customize_compiler(compiler): _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' (cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \ - get_config_vars('CC', 'CXX', 'CFLAGS', - 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS') + get_config_vars( + 'CC', 'CXX', 'CFLAGS', + 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS') if 'CC' in os.environ: newcc = os.environ['CC'] @@ -280,7 +284,6 @@ def get_config_h_filename(): return sysconfig.get_config_h_filename() - def get_makefile_filename(): """Return full pathname of installed Makefile from the Python build.""" return sysconfig.get_makefile_filename() @@ -302,6 +305,7 @@ _variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)") _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)") _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") + def parse_makefile(fn, g=None): """Parse a Makefile-style file. @@ -310,7 +314,9 @@ def parse_makefile(fn, g=None): used instead of a new dictionary. """ from distutils.text_file import TextFile - fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape") + fp = TextFile( + fn, strip_comments=1, skip_blanks=1, join_lines=1, + errors="surrogateescape") if g is None: g = {} @@ -319,7 +325,7 @@ def parse_makefile(fn, g=None): while True: line = fp.readline() - if line is None: # eof + if line is None: # eof break m = _variable_rx.match(line) if m: @@ -363,7 +369,8 @@ def parse_makefile(fn, g=None): item = os.environ[n] elif n in renamed_variables: - if name.startswith('PY_') and name[3:] in renamed_variables: + if name.startswith('PY_') and \ + name[3:] in renamed_variables: item = "" elif 'PY_' + n in notdone: @@ -379,7 +386,8 @@ def parse_makefile(fn, g=None): if "$" in after: notdone[name] = value else: - try: value = int(value) + try: + value = int(value) except ValueError: done[name] = value.strip() else: @@ -387,7 +395,7 @@ def parse_makefile(fn, g=None): del notdone[name] if name.startswith('PY_') \ - and name[3:] in renamed_variables: + and name[3:] in renamed_variables: name = name[3:] if name not in done: @@ -449,6 +457,7 @@ def get_config_vars(*args): global _config_vars if _config_vars is None: _config_vars = sysconfig.get_config_vars().copy() + py39compat.add_ext_suffix(_config_vars) if args: vals = [] @@ -458,6 +467,7 @@ def get_config_vars(*args): else: return _config_vars + def get_config_var(name): """Return the value of a single variable using the dictionary returned by 'get_config_vars()'. Equivalent to @@ -465,5 +475,6 @@ def get_config_var(name): """ if name == 'SO': import warnings - warnings.warn('SO is deprecated, use EXT_SUFFIX', DeprecationWarning, 2) + warnings.warn( + 'SO is deprecated, use EXT_SUFFIX', DeprecationWarning, 2) return get_config_vars().get(name) diff --git a/setuptools/_distutils/tests/test_build.py b/setuptools/_distutils/tests/test_build.py index 83a9e4f4..93724419 100644 --- a/setuptools/_distutils/tests/test_build.py +++ b/setuptools/_distutils/tests/test_build.py @@ -24,10 +24,10 @@ class BuildTestCase(support.TempdirManager, wanted = os.path.join(cmd.build_base, 'lib') self.assertEqual(cmd.build_purelib, wanted) - # build_platlib is 'build/lib.platform-x.x[-pydebug]' + # build_platlib is 'build/lib.platform-cache_tag[-pydebug]' # examples: - # build/lib.macosx-10.3-i386-2.7 - plat_spec = '.%s-%d.%d' % (cmd.plat_name, *sys.version_info[:2]) + # build/lib.macosx-10.3-i386-cpython39 + plat_spec = '.%s-%s' % (cmd.plat_name, sys.implementation.cache_tag) if hasattr(sys, 'gettotalrefcount'): self.assertTrue(cmd.build_platlib.endswith('-pydebug')) plat_spec += '-pydebug' diff --git a/setuptools/_distutils/tests/test_install.py b/setuptools/_distutils/tests/test_install.py index 5dbc06b0..3aef9e43 100644 --- a/setuptools/_distutils/tests/test_install.py +++ b/setuptools/_distutils/tests/test_install.py @@ -56,14 +56,15 @@ class InstallTestCase(support.TempdirManager, expected = os.path.normpath(expected) self.assertEqual(got, expected) - libdir = os.path.join(destination, "lib", "python") + impl_name = sys.implementation.name.replace("cpython", "python") + libdir = os.path.join(destination, "lib", impl_name) check_path(cmd.install_lib, libdir) _platlibdir = getattr(sys, "platlibdir", "lib") - platlibdir = os.path.join(destination, _platlibdir, "python") + platlibdir = os.path.join(destination, _platlibdir, impl_name) check_path(cmd.install_platlib, platlibdir) check_path(cmd.install_purelib, libdir) check_path(cmd.install_headers, - os.path.join(destination, "include", "python", "foopkg")) + os.path.join(destination, "include", impl_name, "foopkg")) check_path(cmd.install_scripts, os.path.join(destination, "bin")) check_path(cmd.install_data, destination) diff --git a/setuptools/_distutils/tests/test_sysconfig.py b/setuptools/_distutils/tests/test_sysconfig.py index 9de3cb70..e671f9e0 100644 --- a/setuptools/_distutils/tests/test_sysconfig.py +++ b/setuptools/_distutils/tests/test_sysconfig.py @@ -40,6 +40,8 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase): @unittest.skipIf(sys.platform == 'win32', 'Makefile only exists on Unix like systems') + @unittest.skipIf(sys.implementation.name != 'cpython', + 'Makefile only exists in CPython') def test_get_makefile_filename(self): makefile = sysconfig.get_makefile_filename() self.assertTrue(os.path.isfile(makefile), makefile) @@ -299,6 +301,14 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase): result = sysconfig.parse_config_h(f) self.assertTrue(isinstance(result, dict)) + @unittest.skipUnless(sys.platform == 'win32', + 'Testing windows pyd suffix') + @unittest.skipUnless(sys.implementation.name == 'cpython', + 'Need cpython for this test') + def test_win_ext_suffix(self): + self.assertTrue(sysconfig.get_config_var("EXT_SUFFIX").endswith(".pyd")) + self.assertNotEqual(sysconfig.get_config_var("EXT_SUFFIX"), ".pyd") + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.TestLoader().loadTestsFromTestCase(SysconfigTestCase)) diff --git a/setuptools/_distutils/version.py b/setuptools/_distutils/version.py index 35e181db..31f504e4 100644 --- a/setuptools/_distutils/version.py +++ b/setuptools/_distutils/version.py @@ -50,14 +50,14 @@ class Version: """ def __init__ (self, vstring=None): + if vstring: + self.parse(vstring) warnings.warn( "distutils Version classes are deprecated. " "Use packaging.version instead.", DeprecationWarning, stacklevel=2, ) - if vstring: - self.parse(vstring) def __repr__ (self): return "%s ('%s')" % (self.__class__.__name__, str(self)) |
