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

Method _check_package

Lib/test/test_runpy.py:336–375  ·  view source on GitHub ↗
(self, depth, alter_sys=False,
                          *, namespace=False, parent_namespaces=False)

Source from the content-addressed store, hash-verified

334 if verbose > 1: print("Module executed successfully")
335
336 def _check_package(self, depth, alter_sys=False,
337 *, namespace=False, parent_namespaces=False):
338 pkg_dir, mod_fname, mod_name, mod_spec = (
339 self._make_pkg(example_source, depth, "__main__",
340 namespace=namespace,
341 parent_namespaces=parent_namespaces))
342 pkg_name = mod_name.rpartition(".")[0]
343 forget(mod_name)
344 expected_ns = example_namespace.copy()
345 expected_ns.update({
346 "__name__": mod_name,
347 "__file__": mod_fname,
348 "__cached__": importlib.util.cache_from_source(mod_fname),
349 "__package__": pkg_name,
350 "__spec__": mod_spec,
351 })
352 if alter_sys:
353 expected_ns.update({
354 "run_argv0": mod_fname,
355 "run_name_in_sys_modules": True,
356 "module_in_sys_modules": True,
357 })
358 def create_ns(init_globals):
359 return run_module(pkg_name, init_globals, alter_sys=alter_sys)
360 try:
361 if verbose > 1: print("Running from source:", pkg_name)
362 self.check_code_execution(create_ns, expected_ns)
363 importlib.invalidate_caches()
364 __import__(mod_name)
365 os.remove(mod_fname)
366 if not sys.dont_write_bytecode:
367 make_legacy_pyc(mod_fname)
368 unload(mod_name) # In case loader caches paths
369 if verbose > 1: print("Running from compiled:", pkg_name)
370 importlib.invalidate_caches()
371 self._fix_ns_for_legacy_pyc(expected_ns, alter_sys)
372 self.check_code_execution(create_ns, expected_ns)
373 finally:
374 self._del_pkg(pkg_dir)
375 if verbose > 1: print("Package executed successfully")
376
377 def _add_relative_modules(self, base_dir, source, depth):
378 if depth <= 1:

Calls 14

_make_pkgMethod · 0.95
_del_pkgMethod · 0.95
forgetFunction · 0.90
make_legacy_pycFunction · 0.90
unloadFunction · 0.90
check_code_executionMethod · 0.80
printFunction · 0.50
__import__Function · 0.50
rpartitionMethod · 0.45
copyMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected