MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / _unload_path_modules

Method _unload_path_modules

apps/plugins/loader.py:828–853  ·  view source on GitHub ↗
(self, path: str)

Source from the content-addressed store, hash-verified

826 sys.modules.pop(name, None)
827
828 def _unload_path_modules(self, path: str) -> None:
829 if not path:
830 return
831 root = os.path.abspath(path)
832 for name, module in list(sys.modules.items()):
833 if not module:
834 continue
835 mod_path = getattr(module, "__file__", None)
836 if mod_path:
837 try:
838 abs_path = os.path.abspath(mod_path)
839 if abs_path == root or abs_path.startswith(f"{root}{os.sep}"):
840 sys.modules.pop(name, None)
841 continue
842 except Exception:
843 pass
844 mod_paths = getattr(module, "__path__", None)
845 if mod_paths:
846 try:
847 for pkg_path in mod_paths:
848 abs_pkg = os.path.abspath(pkg_path)
849 if abs_pkg == root or abs_pkg.startswith(f"{root}{os.sep}"):
850 sys.modules.pop(name, None)
851 break
852 except Exception:
853 continue

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected