Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge distutils at 5229dad46b #3258

Merged
merged 20 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c743883
Fix EXT_SUFFIX for windows py<3.8
isuruf Mar 27, 2022
e3de684
Fix SO too
isuruf Mar 27, 2022
74dc536
Move EXT_SUFFIX support to _py39compat, to be removed after support f…
jaraco Mar 27, 2022
79dc357
👹 Feed the hobgoblins (delint).
jaraco Mar 27, 2022
8f8d655
Just modify the vars in place.
jaraco Mar 27, 2022
55da5cb
Restore expectation that SO matches EXT_SUFFIX with rationale.
jaraco Mar 27, 2022
8270cfa
Get the version logic correct.
jaraco Mar 27, 2022
96629b7
Move compatibility concerns out of the function to do the adding.
jaraco Mar 27, 2022
fde3555
Merge pull request #131 from isuruf/ext_suffix_win_py37
jaraco Mar 27, 2022
f2e73a4
Emit warning after parsing. Fixes pypa/distutils#122.
jaraco Mar 28, 2022
2a233e5
Disable installation of Setuptools in tox instead of GHA. Ref pypa/di…
jaraco Mar 28, 2022
1c23f5e
Use cache_tag in default build_platlib dir
mgorny Apr 9, 2022
c76269b
Skip test_get_makefile_filename on non-CPython
mgorny Apr 9, 2022
12fd59d
Update test_home_installation_scheme for pypy install paths
mgorny Apr 9, 2022
9d86bf2
Refactor as simple replace. If a full string substitution proves to b…
jaraco Apr 10, 2022
a64a054
Merge pull request #135 from mgorny/pypy-home-scheme
jaraco Apr 10, 2022
ee180a7
Merge pull request #133 from mgorny/build_dir-cache_tag
jaraco Apr 10, 2022
5229dad
Merge pull request #134 from mgorny/non-cpy-makefile
jaraco Apr 10, 2022
f4d3174
Merge https://github.com/pypa/distutils into feature/distutils-5229da…
jaraco Apr 10, 2022
08c89e3
Update changelog.
jaraco Apr 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3258.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merge pypa/distutils@5229dad46b.
3 changes: 2 additions & 1 deletion setuptools/_distutils/command/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def finalize_options(self):
"--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
Expand Down
21 changes: 21 additions & 0 deletions setuptools/_distutils/py39compat.py
Original file line number Diff line number Diff line change
@@ -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
33 changes: 22 additions & 11 deletions setuptools/_distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
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

Expand Down Expand Up @@ -48,6 +48,7 @@ def _is_python_source_dir(d):
return True
return False


_sys_home = getattr(sys, '_home', None)

if os.name == 'nt':
Expand All @@ -59,11 +60,13 @@ def _fix_pcbuild(d):
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()


Expand All @@ -79,6 +82,7 @@ def _python_build():
# 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'
Expand Down Expand Up @@ -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.

Expand All @@ -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']
Expand Down Expand Up @@ -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()
Expand All @@ -302,6 +305,7 @@ def parse_config_h(fp, g=None):
_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.

Expand All @@ -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 = {}
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -379,15 +386,16 @@ 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:
done[name] = value
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:
Expand Down Expand Up @@ -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 = []
Expand All @@ -458,12 +467,14 @@ 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
get_config_vars().get(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)
6 changes: 3 additions & 3 deletions setuptools/_distutils/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def test_finalize_options(self):
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'
Expand Down
7 changes: 4 additions & 3 deletions setuptools/_distutils/tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ def check_path(got, expected):
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)

Expand Down
10 changes: 10 additions & 0 deletions setuptools/_distutils/tests/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def test_get_config_h_filename(self):

@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)
Expand Down Expand Up @@ -299,6 +301,14 @@ def test_parse_config_h(self):
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))
Expand Down
4 changes: 2 additions & 2 deletions setuptools/_distutils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down