aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/sandbox.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-12-28 15:42:40 -0500
committerJason R. Coombs <jaraco@jaraco.com>2014-12-28 15:42:40 -0500
commiteb2fdc6f488d1a1d4b0cf02e9a8cf03ab33f9d23 (patch)
treeed20c8aae0f11456a0ea8ca391f31801392ff8a8 /setuptools/sandbox.py
parent824cfa0bc32d500da6fd045147f752e8bf02f7b3 (diff)
downloadexternal_python_setuptools-eb2fdc6f488d1a1d4b0cf02e9a8cf03ab33f9d23.tar.gz
external_python_setuptools-eb2fdc6f488d1a1d4b0cf02e9a8cf03ab33f9d23.tar.bz2
external_python_setuptools-eb2fdc6f488d1a1d4b0cf02e9a8cf03ab33f9d23.zip
Extract function for _clear_modules, encapsulating the need for the module names to be greedily evaluated before removing them.
Diffstat (limited to 'setuptools/sandbox.py')
-rwxr-xr-xsetuptools/sandbox.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py
index e958f912..f4f9dfec 100755
--- a/setuptools/sandbox.py
+++ b/setuptools/sandbox.py
@@ -98,13 +98,18 @@ def save_modules():
finally:
sys.modules.update(saved)
# remove any modules imported since
- del_modules = [
+ del_modules = (
mod_name for mod_name in sys.modules
if mod_name not in saved
# exclude any encodings modules. See #285
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
@@ -151,8 +156,8 @@ def hide_setuptools():
necessary to avoid issues such as #315 where setuptools upgrading itself
would fail to find a function declared in the metadata.
"""
- modules = list(filter(_is_setuptools_module, sys.modules))
- list(map(sys.modules.__delitem__, modules))
+ modules = filter(_is_setuptools_module, sys.modules)
+ _clear_modules(modules)
def run_setup(setup_script, args):