Commit eb2fdc6f authored by Jason R. Coombs's avatar Jason R. Coombs

Extract function for _clear_modules, encapsulating the need for the module...

Extract function for _clear_modules, encapsulating the need for the module names to be greedily evaluated before removing them.
parent 824cfa0b
...@@ -98,13 +98,18 @@ def save_modules(): ...@@ -98,13 +98,18 @@ def save_modules():
finally: finally:
sys.modules.update(saved) sys.modules.update(saved)
# remove any modules imported since # remove any modules imported since
del_modules = [ del_modules = (
mod_name for mod_name in sys.modules mod_name for mod_name in sys.modules
if mod_name not in saved if mod_name not in saved
# exclude any encodings modules. See #285 # exclude any encodings modules. See #285
and not mod_name.startswith('encodings.') and not mod_name.startswith('encodings.')
] )
list(map(sys.modules.__delitem__, del_modules)) _clear_modules(del_modules)
def _clear_modules(module_names):
for mod_name in list(module_names):
del sys.modules[mod_name]
@contextlib.contextmanager @contextlib.contextmanager
...@@ -151,8 +156,8 @@ def hide_setuptools(): ...@@ -151,8 +156,8 @@ def hide_setuptools():
necessary to avoid issues such as #315 where setuptools upgrading itself necessary to avoid issues such as #315 where setuptools upgrading itself
would fail to find a function declared in the metadata. would fail to find a function declared in the metadata.
""" """
modules = list(filter(_is_setuptools_module, sys.modules)) modules = filter(_is_setuptools_module, sys.modules)
list(map(sys.modules.__delitem__, modules)) _clear_modules(modules)
def run_setup(setup_script, args): def run_setup(setup_script, args):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment