diff options
author | Philippe Pepiot <philippe.pepiot@logilab.fr> | 2016-12-23 13:32:00 +0100 |
---|---|---|
committer | Philippe Pepiot <philippe.pepiot@logilab.fr> | 2016-12-23 13:32:00 +0100 |
commit | b85f119eb1f3064954e0454b1cfea85b1eb1ef2a (patch) | |
tree | 11b58ec4a49739801680469219c7a36b90d66e39 | |
parent | ff1093ac7866553ef95bb0f253170fc0f047dcea (diff) | |
download | logilab-common-b85f119eb1f3064954e0454b1cfea85b1eb1ef2a.tar.gz |
[modutils] add clean_sys_modules()
A variant of cleanup_sys_modules using a list of modnames to remove from
sys.modules.
-rw-r--r-- | logilab/common/modutils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/logilab/common/modutils.py b/logilab/common/modutils.py index f8e91ad..31b5b27 100644 --- a/logilab/common/modutils.py +++ b/logilab/common/modutils.py @@ -493,6 +493,18 @@ def cleanup_sys_modules(directories): return cleaned +def clean_sys_modules(names): + """remove submodules starting with name from `names` from `sys.modules`""" + cleaned = set() + for modname in list(sys.modules): + for name in names: + if modname.startswith(name): + del sys.modules[modname] + cleaned.add(modname) + break + return cleaned + + def is_python_source(filename): """ rtype: bool |