MCPcopy Index your code
hub / github.com/python/cpython / interpreter_requires_environment

Function interpreter_requires_environment

Lib/test/support/script_helper.py:21–58  ·  view source on GitHub ↗

Returns True if our sys.executable interpreter requires environment variables in order to be able to run at all. This is designed to be used with @unittest.skipIf() to annotate tests that need to use an assert_python*() function to launch an isolated mode (-I) or no environment

()

Source from the content-addressed store, hash-verified

19
20
21def interpreter_requires_environment():
22 """
23 Returns True if our sys.executable interpreter requires environment
24 variables in order to be able to run at all.
25
26 This is designed to be used with @unittest.skipIf() to annotate tests
27 that need to use an assert_python*() function to launch an isolated
28 mode (-I) or no environment mode (-E) sub-interpreter process.
29
30 A normal build & test does not run into this situation but it can happen
31 when trying to run the standard library test suite from an interpreter that
32 doesn't have an obvious home with Python's current home finding logic.
33
34 Setting PYTHONHOME is one way to get most of the testsuite to run in that
35 situation. PYTHONPATH or PYTHONUSERSITE are other common environment
36 variables that might impact whether or not the interpreter can start.
37 """
38 global __cached_interp_requires_environment
39 if __cached_interp_requires_environment is None:
40 # If PYTHONHOME is set, assume that we need it
41 if 'PYTHONHOME' in os.environ:
42 __cached_interp_requires_environment = True
43 return True
44 # cannot run subprocess, assume we don't need it
45 if not support.has_subprocess_support:
46 __cached_interp_requires_environment = False
47 return False
48
49 # Try running an interpreter with -E to see if it works or not.
50 try:
51 subprocess.check_call([sys.executable, '-E',
52 '-c', 'import sys; sys.exit(0)'])
53 except subprocess.CalledProcessError:
54 __cached_interp_requires_environment = True
55 else:
56 __cached_interp_requires_environment = False
57
58 return __cached_interp_requires_environment
59
60
61class _PythonRunResult(collections.namedtuple("_PythonRunResult",

Callers 2

run_python_until_endFunction · 0.85
spawn_pythonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…