MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / python_run

Function python_run

tests_runfiles/test_runfiles_integrated.py:9–47  ·  view source on GitHub ↗
(
    cmdline,
    returncode: Union[Literal["error"], Literal["any"], int],
    cwd=None,
    additional_env: Optional[Dict[str, str]] = None,
    timeout=None,
)

Source from the content-addressed store, hash-verified

7
8
9def python_run(
10 cmdline,
11 returncode: Union[Literal["error"], Literal["any"], int],
12 cwd=None,
13 additional_env: Optional[Dict[str, str]] = None,
14 timeout=None,
15) -> CompletedProcess:
16 cp = os.environ.copy()
17 cp["PYTHONPATH"] = os.pathsep.join([x for x in sys.path if x])
18 if additional_env:
19 cp.update(additional_env)
20 args = [sys.executable] + cmdline
21 result = subprocess.run(args, capture_output=True, env=cp, cwd=cwd, timeout=timeout)
22
23 if returncode == "any":
24 return result
25
26 if returncode == "error" and result.returncode:
27 return result
28
29 if result.returncode == returncode:
30 return result
31
32 # This is a bit too verbose, so, commented out for now.
33 # env_str = "\n".join(str(x) for x in sorted(cp.items()))
34
35 raise AssertionError(
36 f"""Expected returncode: {returncode}. Found: {result.returncode}.
37=== stdout:
38{result.stdout.decode('utf-8')}
39
40=== stderr:
41{result.stderr.decode('utf-8')}
42
43=== Args:
44{args}
45
46"""
47 )
48
49
50project_rootdir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

Callers 1

test_runfiles_integratedFunction · 0.85

Calls 5

copyMethod · 0.80
joinMethod · 0.45
updateMethod · 0.45
runMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected