Skip to content

Update multiple unittests from CPython 3.10.5 #3910

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

Merged
merged 26 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5afa6f7
Update _osx_support from CPython 3.10.5
Jul 17, 2022
c737713
Update test_itertools from CPython 3.10.5
Jul 17, 2022
5b18683
Update list/tuple tests from CPython 3.10.5
Jul 17, 2022
003f9db
adjust failing markers for list tests
youknowone Jul 17, 2022
8d3bac9
Update test_array from CPython 3.10.5
Jul 17, 2022
b1c29aa
adjust failing markers for array tests
youknowone Jul 17, 2022
c62076e
Update test_dict from CPython 3.10.5
Jul 17, 2022
a4f2421
Update test_dictcomps from CPython 3.10.5
Jul 17, 2022
146c9ff
Update test_dictviews from CPython 3.10.5
Jul 17, 2022
fda0e0a
adjust failing markers for test_dict
youknowone Jul 17, 2022
71c2772
Update test_set from CPython 3.10.5
Jul 17, 2022
da54c40
adjust failing markers for test_set
youknowone Jul 17, 2022
9537149
Update collections/test_{collections,defaultdict} from CPython 3.10.5
Jul 17, 2022
7580e11
adjust failing markers for test_{collections,defaultdict}
youknowone Jul 17, 2022
c8ae180
Update test_deque from CPython 3.10.5
Jul 17, 2022
45e6fb1
adjust failing markers for test_deque
youknowone Jul 17, 2022
8a6fc05
Update test_contains from CPython 3.10.5
Jul 17, 2022
36f5134
Update test_bytes from CPython 3.10.5
Jul 17, 2022
c7a5b96
Update test_memoryview from CPython 3.10.5
Jul 17, 2022
b4c0a76
Update queue/test_queue from CPython 3.10.5
Jul 17, 2022
ff7b96f
Update test_unicode* from CPython 3.10.5
youknowone Jul 17, 2022
2f488cb
adjust failing tests from test_unicode*
youknowone Jul 17, 2022
33690be
Update tests from CPython 3.10.5
Jul 17, 2022
3d27f16
adjust failing markers for test_{builtin,decimal,float,range}
youknowone Jul 17, 2022
f3acd68
update {test_}xmlrpc from CPython 3.10.5
Jul 17, 2022
6729417
adjust failing markers for test_xmlrpc
youknowone Jul 17, 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
132 changes: 102 additions & 30 deletions Lib/_osx_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _find_executable(executable, path=None):
return executable


def _read_output(commandstring):
def _read_output(commandstring, capture_stderr=False):
"""Output from successful command execution or None"""
# Similar to os.popen(commandstring, "r").read(),
# but without actually using os.popen because that
Expand All @@ -67,7 +67,10 @@ def _read_output(commandstring):
os.getpid(),), "w+b")

with contextlib.closing(fp) as fp:
cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
if capture_stderr:
cmd = "%s >'%s' 2>&1" % (commandstring, fp.name)
else:
cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
return fp.read().decode('utf-8').strip() if not os.system(cmd) else None


Expand All @@ -93,7 +96,7 @@ def _get_system_version():
if _SYSTEM_VERSION is None:
_SYSTEM_VERSION = ''
try:
f = open('/System/Library/CoreServices/SystemVersion.plist')
f = open('/System/Library/CoreServices/SystemVersion.plist', encoding="utf-8")
except OSError:
# We're on a plain darwin box, fall back to the default
# behaviour.
Expand All @@ -110,6 +113,26 @@ def _get_system_version():

return _SYSTEM_VERSION

_SYSTEM_VERSION_TUPLE = None
def _get_system_version_tuple():
"""
Return the macOS system version as a tuple

The return value is safe to use to compare
two version numbers.
"""
global _SYSTEM_VERSION_TUPLE
if _SYSTEM_VERSION_TUPLE is None:
osx_version = _get_system_version()
if osx_version:
try:
_SYSTEM_VERSION_TUPLE = tuple(int(i) for i in osx_version.split('.'))
except ValueError:
_SYSTEM_VERSION_TUPLE = ()

return _SYSTEM_VERSION_TUPLE


def _remove_original_values(_config_vars):
"""Remove original unmodified values for testing"""
# This is needed for higher-level cross-platform tests of get_platform.
Expand All @@ -125,21 +148,52 @@ def _save_modified_value(_config_vars, cv, newvalue):
_config_vars[_INITPRE + cv] = oldvalue
_config_vars[cv] = newvalue


_cache_default_sysroot = None
def _default_sysroot(cc):
""" Returns the root of the default SDK for this system, or '/' """
global _cache_default_sysroot

if _cache_default_sysroot is not None:
return _cache_default_sysroot

contents = _read_output('%s -c -E -v - </dev/null' % (cc,), True)
in_incdirs = False
for line in contents.splitlines():
if line.startswith("#include <...>"):
in_incdirs = True
elif line.startswith("End of search list"):
in_incdirs = False
elif in_incdirs:
line = line.strip()
if line == '/usr/include':
_cache_default_sysroot = '/'
elif line.endswith(".sdk/usr/include"):
_cache_default_sysroot = line[:-12]
if _cache_default_sysroot is None:
_cache_default_sysroot = '/'

return _cache_default_sysroot

def _supports_universal_builds():
"""Returns True if universal builds are supported on this system"""
# As an approximation, we assume that if we are running on 10.4 or above,
# then we are running with an Xcode environment that supports universal
# builds, in particular -isysroot and -arch arguments to the compiler. This
# is in support of allowing 10.4 universal builds to run on 10.3.x systems.

osx_version = _get_system_version()
if osx_version:
try:
osx_version = tuple(int(i) for i in osx_version.split('.'))
except ValueError:
osx_version = ''
osx_version = _get_system_version_tuple()
return bool(osx_version >= (10, 4)) if osx_version else False

def _supports_arm64_builds():
"""Returns True if arm64 builds are supported on this system"""
# There are two sets of systems supporting macOS/arm64 builds:
# 1. macOS 11 and later, unconditionally
# 2. macOS 10.15 with Xcode 12.2 or later
# For now the second category is ignored.
osx_version = _get_system_version_tuple()
return osx_version >= (11, 0) if osx_version else False


def _find_appropriate_compiler(_config_vars):
"""Find appropriate C compiler for extension module builds"""
Expand Down Expand Up @@ -211,7 +265,7 @@ def _remove_universal_flags(_config_vars):
if cv in _config_vars and cv not in os.environ:
flags = _config_vars[cv]
flags = re.sub(r'-arch\s+\w+\s', ' ', flags, flags=re.ASCII)
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
flags = re.sub(r'-isysroot\s*\S+', ' ', flags)
_save_modified_value(_config_vars, cv, flags)

return _config_vars
Expand Down Expand Up @@ -287,15 +341,15 @@ def _check_for_unavailable_sdk(_config_vars):
# to /usr and /System/Library by either a standalone CLT
# package or the CLT component within Xcode.
cflags = _config_vars.get('CFLAGS', '')
m = re.search(r'-isysroot\s+(\S+)', cflags)
m = re.search(r'-isysroot\s*(\S+)', cflags)
if m is not None:
sdk = m.group(1)
if not os.path.exists(sdk):
for cv in _UNIVERSAL_CONFIG_VARS:
# Do not alter a config var explicitly overridden by env var
if cv in _config_vars and cv not in os.environ:
flags = _config_vars[cv]
flags = re.sub(r'-isysroot\s+\S+(?:\s|$)', ' ', flags)
flags = re.sub(r'-isysroot\s*\S+(?:\s|$)', ' ', flags)
_save_modified_value(_config_vars, cv, flags)

return _config_vars
Expand All @@ -320,7 +374,7 @@ def compiler_fixup(compiler_so, cc_args):
stripArch = stripSysroot = True
else:
stripArch = '-arch' in cc_args
stripSysroot = '-isysroot' in cc_args
stripSysroot = any(arg for arg in cc_args if arg.startswith('-isysroot'))

if stripArch or 'ARCHFLAGS' in os.environ:
while True:
Expand All @@ -331,36 +385,52 @@ def compiler_fixup(compiler_so, cc_args):
except ValueError:
break

elif not _supports_arm64_builds():
# Look for "-arch arm64" and drop that
for idx in reversed(range(len(compiler_so))):
if compiler_so[idx] == '-arch' and compiler_so[idx+1] == "arm64":
del compiler_so[idx:idx+2]

if 'ARCHFLAGS' in os.environ and not stripArch:
# User specified different -arch flags in the environ,
# see also distutils.sysconfig
compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()

if stripSysroot:
while True:
try:
index = compiler_so.index('-isysroot')
indices = [i for i,x in enumerate(compiler_so) if x.startswith('-isysroot')]
if not indices:
break
index = indices[0]
if compiler_so[index] == '-isysroot':
# Strip this argument and the next one:
del compiler_so[index:index+2]
except ValueError:
break
else:
# It's '-isysroot/some/path' in one arg
del compiler_so[index:index+1]

# Check if the SDK that is used during compilation actually exists,
# the universal build requires the usage of a universal SDK and not all
# users have that installed by default.
sysroot = None
if '-isysroot' in cc_args:
idx = cc_args.index('-isysroot')
sysroot = cc_args[idx+1]
elif '-isysroot' in compiler_so:
idx = compiler_so.index('-isysroot')
sysroot = compiler_so[idx+1]
argvar = cc_args
indices = [i for i,x in enumerate(cc_args) if x.startswith('-isysroot')]
if not indices:
argvar = compiler_so
indices = [i for i,x in enumerate(compiler_so) if x.startswith('-isysroot')]

for idx in indices:
if argvar[idx] == '-isysroot':
sysroot = argvar[idx+1]
break
else:
sysroot = argvar[idx][len('-isysroot'):]
break

if sysroot and not os.path.isdir(sysroot):
from distutils import log
log.warn("Compiling with an SDK that doesn't seem to exist: %s",
sysroot)
log.warn("Please check your Xcode installation")
sys.stderr.write(f"Compiling with an SDK that doesn't seem to exist: {sysroot}\n")
sys.stderr.write("Please check your Xcode installation\n")
sys.stderr.flush()

return compiler_so

Expand Down Expand Up @@ -411,7 +481,7 @@ def customize_compiler(_config_vars):

This customization is performed when the first
extension module build is requested
in distutils.sysconfig.customize_compiler).
in distutils.sysconfig.customize_compiler.
"""

# Find a compiler to use for extension module builds
Expand Down Expand Up @@ -454,10 +524,10 @@ def get_platform_osx(_config_vars, osname, release, machine):
try:
macrelease = tuple(int(i) for i in macrelease.split('.')[0:2])
except ValueError:
macrelease = (10, 0)
macrelease = (10, 3)
else:
# assume no universal support
macrelease = (10, 0)
macrelease = (10, 3)

if (macrelease >= (10, 4)) and '-arch' in cflags.strip():
# The universal build will build fat binaries, but not on
Expand All @@ -470,6 +540,8 @@ def get_platform_osx(_config_vars, osname, release, machine):

if len(archs) == 1:
machine = archs[0]
elif archs == ('arm64', 'x86_64'):
machine = 'universal2'
elif archs == ('i386', 'ppc'):
machine = 'fat'
elif archs == ('i386', 'x86_64'):
Expand Down
Loading