Commit 253d03ca authored by Jason R. Coombs's avatar Jason R. Coombs

Add compatibility module to fix failing tests on Python 3.5 due to missing functionality.

parent 71d738a1
"""
Backward compatibility support for Python 3.5
"""
import sys
import test.support
import subprocess
# copied from Python 3.9 test.support module
def _missing_compiler_executable(cmd_names=[]):
"""Check if the compiler components used to build the interpreter exist.
Check for the existence of the compiler executables whose names are listed
in 'cmd_names' or all the compiler executables when 'cmd_names' is empty
and return the first missing executable or None when none is found
missing.
"""
from distutils import ccompiler, sysconfig, spawn
compiler = ccompiler.new_compiler()
sysconfig.customize_compiler(compiler)
for name in compiler.executables:
if cmd_names and name not in cmd_names:
continue
cmd = getattr(compiler, name)
if cmd_names:
assert cmd is not None, \
"the '%s' executable is not configured" % name
elif not cmd:
continue
if spawn.find_executable(cmd[0]) is None:
return cmd[0]
missing_compiler_executable = vars(test.support).setdefault(
'missing_compiler_executable',
_missing_compiler_executable,
)
try:
from test.support import unix_shell
except ImportError:
# Adapted from Python 3.9 test.support module
is_android = hasattr(sys, 'getandroidapilevel')
unix_shell = (
None if sys.platform == 'win32' else
'/system/bin/sh' if is_android else
'/bin/sh'
)
# copied from Python 3.9 subprocess module
def _optim_args_from_interpreter_flags():
"""Return a list of command-line arguments reproducing the current
optimization settings in sys.flags."""
args = []
value = sys.flags.optimize
if value > 0:
args.append('-' + 'O' * value)
return args
vars(subprocess).setdefault(
'_optim_args_from_interpreter_flags',
_optim_args_from_interpreter_flags,
)
......@@ -3,7 +3,9 @@ import unittest
import os
import sys
from test.support import run_unittest, missing_compiler_executable
from test.support import run_unittest
from .py35compat import missing_compiler_executable
from distutils.command.build_clib import build_clib
from distutils.errors import DistutilsSetupError
......
......@@ -2,7 +2,9 @@
import unittest
import os
import sys
from test.support import run_unittest, missing_compiler_executable
from test.support import run_unittest
from .py35compat import missing_compiler_executable
from distutils.command.config import dump_file, config
from distutils.tests import support
......
......@@ -3,9 +3,11 @@ import os
import stat
import sys
import unittest.mock
from test.support import run_unittest, unix_shell
from test.support import run_unittest
from test import support as test_support
from .py35compat import unix_shell
from distutils.spawn import find_executable
from distutils.spawn import spawn
from distutils.errors import DistutilsExecError
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment