MCPcopy
hub / github.com/pex-tool/pex / _assert_exec_chain

Function _assert_exec_chain

tests/integration/test_reexec.py:29–105  ·  view source on GitHub ↗
(
    exec_chain=None,  # type: Optional[List[str]]
    pex_python=None,  # type: Optional[str]
    pex_python_path=None,  # type: Optional[Iterable[str]]
    interpreter_constraints=None,  # type: Optional[Iterable[str]]
    pythonpath=None,  # type: Optional[Iterable[str]]
)

Source from the content-addressed store, hash-verified

27
28
29def _assert_exec_chain(
30 exec_chain=None, # type: Optional[List[str]]
31 pex_python=None, # type: Optional[str]
32 pex_python_path=None, # type: Optional[Iterable[str]]
33 interpreter_constraints=None, # type: Optional[Iterable[str]]
34 pythonpath=None, # type: Optional[Iterable[str]]
35):
36 # type: (...) -> None
37 with temporary_dir() as td:
38 test_pex = os.path.join(td, "test.pex")
39
40 args = ["-o", test_pex]
41 if interpreter_constraints:
42 args.extend("--interpreter-constraint={}".format(ic) for ic in interpreter_constraints)
43
44 env = os.environ.copy()
45 PATH = env["PATH"].split(os.pathsep)
46
47 def add_to_path(entry):
48 # type: (str) -> None
49 if os.path.isfile(entry):
50 entry = os.path.dirname(entry)
51 PATH.append(entry)
52
53 if pex_python:
54 add_to_path(pex_python)
55 if pex_python_path:
56 for path in pex_python_path:
57 add_to_path(path)
58
59 env["PATH"] = os.pathsep.join(PATH)
60 result = run_pex_command(args, env=env)
61 result.assert_success()
62
63 env = make_env(
64 _PEX_EXEC_CHAIN=1,
65 PEX_INTERPRETER=1,
66 PEX_PYTHON=pex_python,
67 PEX_PYTHON_PATH=os.pathsep.join(pex_python_path) if pex_python_path else None,
68 PYTHONPATH=os.pathsep.join(pythonpath) if pythonpath else None,
69 )
70
71 initial_interpreter = PythonInterpreter.get()
72 output = subprocess.check_output(
73 [
74 initial_interpreter.binary,
75 test_pex,
76 "-c",
77 "import json, os; print(json.dumps(os.environ.copy()))",
78 ],
79 env=env,
80 )
81 final_env = json.loads(output.decode("utf-8"))
82
83 assert "PEX_PYTHON" not in final_env
84 assert "PEX_PYTHON_PATH" not in final_env
85 assert "_PEX_SHOULD_EXIT_BOOTSTRAP_REEXEC" not in final_env
86

Calls 13

temporary_dirFunction · 0.90
run_pex_commandFunction · 0.90
make_envFunction · 0.90
add_to_pathFunction · 0.85
extendMethod · 0.80
assert_successMethod · 0.80
decodeMethod · 0.80
from_binaryMethod · 0.80
appendMethod · 0.80
joinMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected