Skip to content

Commit b3ffad0

Browse files
committed
remove useless and potentially dangerous module cleanup
The bug is now fixed because we use relative imports everywhere
1 parent 324674a commit b3ffad0

1 file changed

Lines changed: 1 addition & 27 deletions

File tree

python/code/wypp/runCode.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,6 @@ def debugModule(name):
8686
print("Origin:", spec.origin)
8787
print("Loader:", type(spec.loader).__name__)
8888

89-
@contextmanager
90-
def freshModules():
91-
original_modules = sys.modules.copy()
92-
stdlib_path = os.path.dirname(os.__file__)
93-
whitelist = ('sys', 'os', 'contextlib', 'runpy', 'wypp', '__main__', '__wypp__')
94-
def is_core(name, module):
95-
if name in sys.stdlib_module_names or name in sys.builtin_module_names:
96-
return True
97-
module_file = getattr(module, '__file__', None)
98-
if module_file and module_file.startswith(stdlib_path):
99-
return True
100-
if name in whitelist:
101-
return True
102-
return False
103-
104-
try:
105-
for mod_name in list(sys.modules.keys()):
106-
if not is_core(mod_name, sys.modules[mod_name]):
107-
del sys.modules[mod_name]
108-
yield
109-
finally:
110-
# 4. Restore everything
111-
sys.modules.clear()
112-
sys.modules.update(original_modules)
113-
11489
def runCode(fileToRun, globals, doTypecheck=True, extraDirs=None) -> dict:
11590
if not extraDirs:
11691
extraDirs = []
@@ -119,8 +94,7 @@ def runCode(fileToRun, globals, doTypecheck=True, extraDirs=None) -> dict:
11994
sys.dont_write_bytecode = True
12095
if DEBUG:
12196
debugModule(modName)
122-
with freshModules():
123-
res = runpy.run_module(modName, init_globals=globals, run_name='__wypp__', alter_sys=False)
97+
res = runpy.run_module(modName, init_globals=globals, run_name='__wypp__', alter_sys=False)
12498
return res
12599

126100
def runStudentCode(fileToRun, globals, onlyCheckRunnable, doTypecheck=True, extraDirs=None) -> dict:

0 commit comments

Comments
 (0)