MCPcopy Index your code
hub / github.com/python/cpython / _del_pkg

Method _del_pkg

Lib/test/test_runpy.py:260–283  ·  view source on GitHub ↗
(self, top)

Source from the content-addressed store, hash-verified

258 return pkg_dir, mod_fname, mod_name, mod_spec
259
260 def _del_pkg(self, top):
261 for entry in list(sys.modules):
262 if entry.startswith("__runpy_pkg__"):
263 del sys.modules[entry]
264 if verbose > 1: print(" Removed sys.modules entries")
265 del sys.path[0]
266 if verbose > 1: print(" Removed sys.path entry")
267 for root, dirs, files in os.walk(top, topdown=False):
268 for name in files:
269 try:
270 os.remove(os.path.join(root, name))
271 except OSError as ex:
272 if verbose > 1: print(ex) # Persist with cleaning up
273 for name in dirs:
274 fullname = os.path.join(root, name)
275 try:
276 os.rmdir(fullname)
277 except OSError as ex:
278 if verbose > 1: print(ex) # Persist with cleaning up
279 try:
280 os.rmdir(top)
281 if verbose > 1: print(" Removed package tree")
282 except OSError as ex:
283 if verbose > 1: print(ex) # Persist with cleaning up
284
285 def _fix_ns_for_legacy_pyc(self, ns, alter_sys):
286 char_to_add = "c"

Callers 5

_check_moduleMethod · 0.95
_check_packageMethod · 0.95
test_run_nameMethod · 0.95

Calls 6

listClass · 0.85
rmdirMethod · 0.80
startswithMethod · 0.45
walkMethod · 0.45
removeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected