Skip to content

Commit

Permalink
FIX: clear _modules_stack in jsonimporter.unload method
Browse files Browse the repository at this point in the history
  • Loading branch information
desty2k committed Feb 14, 2022
1 parent 886267c commit a20629f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions paker/importers/jsonimporter.py
Expand Up @@ -20,7 +20,6 @@


class jsonimporter:

def __init__(self, jsonmod: dict):
super(jsonimporter, self).__init__()
self._jsonmod = jsonmod
Expand Down Expand Up @@ -57,7 +56,7 @@ def find_module(self, fullname, path=None):
"""find_module(fullname, path=None) -> self or None.
Search for a module specified by 'fullname'. 'fullname' must be the
fully qualified (dotted) module name. It returns the zipimporter
fully qualified (dotted) module name. It returns the jsonimporter
instance itself if the module was found, or None if it wasn't.
The optional 'path' argument is ignored -- it's there for compatibility
with the importer protocol.
Expand Down Expand Up @@ -110,7 +109,7 @@ def load_module(self, fullname):
mod.__loader__ = self
if jsonmod["type"] == "package":
mod.__path__ = ["paker://" + fullname.replace(".", path_sep)]
if not hasattr(mod, '__builtins__'):
if not hasattr(mod, "__builtins__"):
mod.__builtins__ = __builtins__
sys.modules[fullname] = mod
exec(jsonmod["code"], mod.__dict__)
Expand All @@ -120,7 +119,7 @@ def load_module(self, fullname):
mod.__loader__ = self
if jsonmod["type"] == "package":
mod.__path__ = ["paker://" + fullname.replace(".", path_sep)]
if not hasattr(mod, '__builtins__'):
if not hasattr(mod, "__builtins__"):
mod.__builtins__ = __builtins__
sys.modules[fullname] = mod
exec(marshal.loads(base64.b64decode(jsonmod["code"])), mod.__dict__)
Expand Down Expand Up @@ -178,6 +177,7 @@ def unload(self):
del self._module_cache[module_name]
if module_name in sys.modules:
del sys.modules[module_name]
self._modules_stack.clear()
self._logger.info("unloaded all modules")

def __enter__(self):
Expand Down

0 comments on commit a20629f

Please sign in to comment.