diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2020-07-01 20:42:12 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-07-01 20:42:12 -0400 |
| commit | 253d03cad23ed022d020ae635ce419255240feef (patch) | |
| tree | d1fe8f3ad2508255d77d5c1f20288c49bd2a88d9 /distutils | |
| parent | 71d738a1f6eced80defe3587f6adbbe4ce1fb7d1 (diff) | |
| download | external_python_setuptools-253d03cad23ed022d020ae635ce419255240feef.tar.gz external_python_setuptools-253d03cad23ed022d020ae635ce419255240feef.tar.bz2 external_python_setuptools-253d03cad23ed022d020ae635ce419255240feef.zip | |
Add compatibility module to fix failing tests on Python 3.5 due to missing functionality.
Diffstat (limited to 'distutils')
| -rw-r--r-- | distutils/tests/py35compat.py | 68 | ||||
| -rw-r--r-- | distutils/tests/test_build_clib.py | 4 | ||||
| -rw-r--r-- | distutils/tests/test_config_cmd.py | 4 | ||||
| -rw-r--r-- | distutils/tests/test_spawn.py | 4 |
4 files changed, 77 insertions, 3 deletions
diff --git a/distutils/tests/py35compat.py b/distutils/tests/py35compat.py new file mode 100644 index 00000000..3eb86b5f --- /dev/null +++ b/distutils/tests/py35compat.py @@ -0,0 +1,68 @@ +""" +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, +) diff --git a/distutils/tests/test_build_clib.py b/distutils/tests/test_build_clib.py index abd83137..259c4352 100644 --- a/distutils/tests/test_build_clib.py +++ b/distutils/tests/test_build_clib.py @@ -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 diff --git a/distutils/tests/test_config_cmd.py b/distutils/tests/test_config_cmd.py index 9aeab07b..4cd9a6b9 100644 --- a/distutils/tests/test_config_cmd.py +++ b/distutils/tests/test_config_cmd.py @@ -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 diff --git a/distutils/tests/test_spawn.py b/distutils/tests/test_spawn.py index cf1faad5..919d0ad9 100644 --- a/distutils/tests/test_spawn.py +++ b/distutils/tests/test_spawn.py @@ -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 |
