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

Method run_py

Lib/test/test_launcher.py:218–262  ·  view source on GitHub ↗
(self, args, env=None, allow_fail=False, expect_returncode=0, argv=None)

Source from the content-addressed store, hash-verified

216 return self.py_exe
217
218 def run_py(self, args, env=None, allow_fail=False, expect_returncode=0, argv=None):
219 if not self.py_exe:
220 self.py_exe = self.find_py()
221
222 ignore = {"VIRTUAL_ENV", "PY_PYTHON", "PY_PYTHON2", "PY_PYTHON3"}
223 env = {
224 **{k.upper(): v for k, v in os.environ.items() if k.upper() not in ignore},
225 "PYLAUNCHER_DEBUG": "1",
226 "PYLAUNCHER_DRYRUN": "1",
227 "PYLAUNCHER_LIMIT_TO_COMPANY": "",
228 **{k.upper(): v for k, v in (env or {}).items()},
229 }
230 if not argv:
231 argv = [self.py_exe, *args]
232 with subprocess.Popen(
233 argv,
234 env=env,
235 executable=self.py_exe,
236 stdin=subprocess.PIPE,
237 stdout=subprocess.PIPE,
238 stderr=subprocess.PIPE,
239 ) as p:
240 p.stdin.close()
241 p.wait(10)
242 out = p.stdout.read().decode("utf-8", "replace")
243 err = p.stderr.read().decode("ascii", "replace").replace("\uFFFD", "?")
244 if p.returncode != expect_returncode and support.verbose and not allow_fail:
245 print("++ COMMAND ++")
246 print([self.py_exe, *args])
247 print("++ STDOUT ++")
248 print(out)
249 print("++ STDERR ++")
250 print(err)
251 if allow_fail and p.returncode != expect_returncode:
252 raise subprocess.CalledProcessError(p.returncode, [self.py_exe, *args], out, err)
253 else:
254 self.assertEqual(expect_returncode, p.returncode)
255 data = {
256 s.partition(":")[0]: s.partition(":")[2].lstrip()
257 for s in err.splitlines()
258 if not s.startswith("#") and ":" in s
259 }
260 data["stdout"] = out
261 data["stderr"] = err
262 return data
263
264 def py_ini(self, content):
265 local_appdata = os.environ.get("LOCALAPPDATA")

Callers 15

test_versionMethod · 0.80
test_help_optionMethod · 0.80
test_list_optionMethod · 0.80
test_listMethod · 0.80
test_list_pathsMethod · 0.80
test_filter_to_tagMethod · 0.80
test_search_major_3Method · 0.80

Calls 14

find_pyMethod · 0.95
printFunction · 0.50
upperMethod · 0.45
itemsMethod · 0.45
closeMethod · 0.45
waitMethod · 0.45
decodeMethod · 0.45
readMethod · 0.45
replaceMethod · 0.45
assertEqualMethod · 0.45
partitionMethod · 0.45
lstripMethod · 0.45

Tested by

no test coverage detected