MCPcopy Index your code
hub / github.com/RustPython/RustPython / interpreter_requires_environment

Function interpreter_requires_environment

Lib/test/support/script_helper.py:20–57  ·  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

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