aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/_distutils/tests/py35compat.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-07-03 15:11:32 -0400
committerGitHub <noreply@github.com>2020-07-03 15:11:32 -0400
commit5f151cbbcd6c65f7f48082bfaf36db3a55df936e (patch)
treeeb721c8957ee48c5149af6742a27a449fb618027 /setuptools/_distutils/tests/py35compat.py
parenta9eb9e73def8ca6c469e59f1b008746e368ad4c1 (diff)
parenta877dab0bddaeb5503d871794ca06f1c81d805b8 (diff)
downloadexternal_python_setuptools-5f151cbbcd6c65f7f48082bfaf36db3a55df936e.tar.gz
external_python_setuptools-5f151cbbcd6c65f7f48082bfaf36db3a55df936e.tar.bz2
external_python_setuptools-5f151cbbcd6c65f7f48082bfaf36db3a55df936e.zip
Merge branch 'master' into 2020-06-11-raise-from
Diffstat (limited to 'setuptools/_distutils/tests/py35compat.py')
-rw-r--r--setuptools/_distutils/tests/py35compat.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/setuptools/_distutils/tests/py35compat.py b/setuptools/_distutils/tests/py35compat.py
new file mode 100644
index 00000000..0c755261
--- /dev/null
+++ b/setuptools/_distutils/tests/py35compat.py
@@ -0,0 +1,77 @@
+"""
+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,
+)
+
+
+def adapt_glob(regex):
+ """
+ Supply legacy expectation on Python 3.5
+ """
+ if sys.version_info > (3, 6):
+ return regex
+ return regex.replace('(?s:', '').replace(r')\Z', r'\Z(?ms)')