Here is a function that recursively loads a package. Double checked that the updated modules are updated in the modules where they are used, and that problems with infinite recursion are checked.
One of them is launching a package (which makes sense only for packages)
import os import types import importlib def reload_package(package): assert(hasattr(package, "__package__")) fn = package.__file__ fn_dir = os.path.dirname(fn) + os.sep module_visit = {fn} del fn def reload_recursive_ex(module): importlib.reload(module) for module_child in vars(module).values(): if isinstance(module_child, types.ModuleType): fn_child = getattr(module_child, "__file__", None) if (fn_child is not None) and fn_child.startswith(fn_dir): if fn_child not in module_visit:
source share