Skip to content

Commit f8bb416

Browse files
authored
Merge pull request #3258 from pypa/feature/distutils-5229dad46b
Merge distutils at 5229dad
2 parents e5552d3 + 08c89e3 commit f8bb416

File tree

8 files changed

+65
-20
lines changed

8 files changed

+65
-20
lines changed

changelog.d/3258.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Merge pypa/distutils@5229dad46b.

setuptools/_distutils/command/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def finalize_options(self):
8181
"--plat-name only supported on Windows (try "
8282
"using './configure --help' on your platform)")
8383

84-
plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
84+
plat_specifier = ".%s-%s" % (self.plat_name,
85+
sys.implementation.cache_tag)
8586

8687
# Make it so Python 2.x and Python 2.x with --with-pydebug don't
8788
# share the same build directories. Doing so confuses the build
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
import platform
3+
4+
5+
def add_ext_suffix_39(vars):
6+
"""
7+
Ensure vars contains 'EXT_SUFFIX'. pypa/distutils#130
8+
"""
9+
import _imp
10+
ext_suffix = _imp.extension_suffixes()[0]
11+
vars.update(
12+
EXT_SUFFIX=ext_suffix,
13+
# sysconfig sets SO to match EXT_SUFFIX, so maintain
14+
# that expectation.
15+
# https://github.com/python/cpython/blob/785cc6770588de087d09e89a69110af2542be208/Lib/sysconfig.py#L671-L673
16+
SO=ext_suffix,
17+
)
18+
19+
20+
needs_ext_suffix = sys.version_info < (3, 10) and platform.system() == 'Windows'
21+
add_ext_suffix = add_ext_suffix_39 if needs_ext_suffix else lambda vars: None

setuptools/_distutils/sysconfig.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
1010
"""
1111

12-
import _imp
1312
import os
1413
import re
1514
import sys
1615
import sysconfig
1716

1817
from .errors import DistutilsPlatformError
18+
from . import py39compat
1919

2020
IS_PYPY = '__pypy__' in sys.builtin_module_names
2121

@@ -48,6 +48,7 @@ def _is_python_source_dir(d):
4848
return True
4949
return False
5050

51+
5152
_sys_home = getattr(sys, '_home', None)
5253

5354
if os.name == 'nt':
@@ -59,11 +60,13 @@ def _fix_pcbuild(d):
5960
project_base = _fix_pcbuild(project_base)
6061
_sys_home = _fix_pcbuild(_sys_home)
6162

63+
6264
def _python_build():
6365
if _sys_home:
6466
return _is_python_source_dir(_sys_home)
6567
return _is_python_source_dir(project_base)
6668

69+
6770
python_build = _python_build()
6871

6972

@@ -79,6 +82,7 @@ def _python_build():
7982
# this attribute, which is fine.
8083
pass
8184

85+
8286
def get_python_version():
8387
"""Return a string containing the major and minor Python version,
8488
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):
192196
"on platform '%s'" % os.name)
193197

194198

195-
196199
def customize_compiler(compiler):
197200
"""Do any platform-specific customization of a CCompiler instance.
198201
@@ -217,8 +220,9 @@ def customize_compiler(compiler):
217220
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
218221

219222
(cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
220-
get_config_vars('CC', 'CXX', 'CFLAGS',
221-
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
223+
get_config_vars(
224+
'CC', 'CXX', 'CFLAGS',
225+
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
222226

223227
if 'CC' in os.environ:
224228
newcc = os.environ['CC']
@@ -280,7 +284,6 @@ def get_config_h_filename():
280284
return sysconfig.get_config_h_filename()
281285

282286

283-
284287
def get_makefile_filename():
285288
"""Return full pathname of installed Makefile from the Python build."""
286289
return sysconfig.get_makefile_filename()
@@ -302,6 +305,7 @@ def parse_config_h(fp, g=None):
302305
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
303306
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
304307

308+
305309
def parse_makefile(fn, g=None):
306310
"""Parse a Makefile-style file.
307311
@@ -310,7 +314,9 @@ def parse_makefile(fn, g=None):
310314
used instead of a new dictionary.
311315
"""
312316
from distutils.text_file import TextFile
313-
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
317+
fp = TextFile(
318+
fn, strip_comments=1, skip_blanks=1, join_lines=1,
319+
errors="surrogateescape")
314320

315321
if g is None:
316322
g = {}
@@ -319,7 +325,7 @@ def parse_makefile(fn, g=None):
319325

320326
while True:
321327
line = fp.readline()
322-
if line is None: # eof
328+
if line is None: # eof
323329
break
324330
m = _variable_rx.match(line)
325331
if m:
@@ -363,7 +369,8 @@ def parse_makefile(fn, g=None):
363369
item = os.environ[n]
364370

365371
elif n in renamed_variables:
366-
if name.startswith('PY_') and name[3:] in renamed_variables:
372+
if name.startswith('PY_') and \
373+
name[3:] in renamed_variables:
367374
item = ""
368375

369376
elif 'PY_' + n in notdone:
@@ -379,15 +386,16 @@ def parse_makefile(fn, g=None):
379386
if "$" in after:
380387
notdone[name] = value
381388
else:
382-
try: value = int(value)
389+
try:
390+
value = int(value)
383391
except ValueError:
384392
done[name] = value.strip()
385393
else:
386394
done[name] = value
387395
del notdone[name]
388396

389397
if name.startswith('PY_') \
390-
and name[3:] in renamed_variables:
398+
and name[3:] in renamed_variables:
391399

392400
name = name[3:]
393401
if name not in done:
@@ -449,6 +457,7 @@ def get_config_vars(*args):
449457
global _config_vars
450458
if _config_vars is None:
451459
_config_vars = sysconfig.get_config_vars().copy()
460+
py39compat.add_ext_suffix(_config_vars)
452461

453462
if args:
454463
vals = []
@@ -458,12 +467,14 @@ def get_config_vars(*args):
458467
else:
459468
return _config_vars
460469

470+
461471
def get_config_var(name):
462472
"""Return the value of a single variable using the dictionary
463473
returned by 'get_config_vars()'. Equivalent to
464474
get_config_vars().get(name)
465475
"""
466476
if name == 'SO':
467477
import warnings
468-
warnings.warn('SO is deprecated, use EXT_SUFFIX', DeprecationWarning, 2)
478+
warnings.warn(
479+
'SO is deprecated, use EXT_SUFFIX', DeprecationWarning, 2)
469480
return get_config_vars().get(name)

setuptools/_distutils/tests/test_build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def test_finalize_options(self):
2424
wanted = os.path.join(cmd.build_base, 'lib')
2525
self.assertEqual(cmd.build_purelib, wanted)
2626

27-
# build_platlib is 'build/lib.platform-x.x[-pydebug]'
27+
# build_platlib is 'build/lib.platform-cache_tag[-pydebug]'
2828
# examples:
29-
# build/lib.macosx-10.3-i386-2.7
30-
plat_spec = '.%s-%d.%d' % (cmd.plat_name, *sys.version_info[:2])
29+
# build/lib.macosx-10.3-i386-cpython39
30+
plat_spec = '.%s-%s' % (cmd.plat_name, sys.implementation.cache_tag)
3131
if hasattr(sys, 'gettotalrefcount'):
3232
self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
3333
plat_spec += '-pydebug'

setuptools/_distutils/tests/test_install.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ def check_path(got, expected):
5656
expected = os.path.normpath(expected)
5757
self.assertEqual(got, expected)
5858

59-
libdir = os.path.join(destination, "lib", "python")
59+
impl_name = sys.implementation.name.replace("cpython", "python")
60+
libdir = os.path.join(destination, "lib", impl_name)
6061
check_path(cmd.install_lib, libdir)
6162
_platlibdir = getattr(sys, "platlibdir", "lib")
62-
platlibdir = os.path.join(destination, _platlibdir, "python")
63+
platlibdir = os.path.join(destination, _platlibdir, impl_name)
6364
check_path(cmd.install_platlib, platlibdir)
6465
check_path(cmd.install_purelib, libdir)
6566
check_path(cmd.install_headers,
66-
os.path.join(destination, "include", "python", "foopkg"))
67+
os.path.join(destination, "include", impl_name, "foopkg"))
6768
check_path(cmd.install_scripts, os.path.join(destination, "bin"))
6869
check_path(cmd.install_data, destination)
6970

setuptools/_distutils/tests/test_sysconfig.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def test_get_config_h_filename(self):
4040

4141
@unittest.skipIf(sys.platform == 'win32',
4242
'Makefile only exists on Unix like systems')
43+
@unittest.skipIf(sys.implementation.name != 'cpython',
44+
'Makefile only exists in CPython')
4345
def test_get_makefile_filename(self):
4446
makefile = sysconfig.get_makefile_filename()
4547
self.assertTrue(os.path.isfile(makefile), makefile)
@@ -299,6 +301,14 @@ def test_parse_config_h(self):
299301
result = sysconfig.parse_config_h(f)
300302
self.assertTrue(isinstance(result, dict))
301303

304+
@unittest.skipUnless(sys.platform == 'win32',
305+
'Testing windows pyd suffix')
306+
@unittest.skipUnless(sys.implementation.name == 'cpython',
307+
'Need cpython for this test')
308+
def test_win_ext_suffix(self):
309+
self.assertTrue(sysconfig.get_config_var("EXT_SUFFIX").endswith(".pyd"))
310+
self.assertNotEqual(sysconfig.get_config_var("EXT_SUFFIX"), ".pyd")
311+
302312
def test_suite():
303313
suite = unittest.TestSuite()
304314
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(SysconfigTestCase))

setuptools/_distutils/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class Version:
5050
"""
5151

5252
def __init__ (self, vstring=None):
53+
if vstring:
54+
self.parse(vstring)
5355
warnings.warn(
5456
"distutils Version classes are deprecated. "
5557
"Use packaging.version instead.",
5658
DeprecationWarning,
5759
stacklevel=2,
5860
)
59-
if vstring:
60-
self.parse(vstring)
6161

6262
def __repr__ (self):
6363
return "%s ('%s')" % (self.__class__.__name__, str(self))

0 commit comments

Comments
 (0)