Skip to content

Commit

Permalink
store the module in sys.modules
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyAv46 committed Nov 21, 2023
1 parent 885ff1f commit ddc076d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions RLTest/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, filename, symbol, modulename):
def initialize(self):
module_spec = importlib.util.spec_from_file_location(self.modulename, self.filename)
module = importlib.util.module_from_spec(module_spec)
sys.modules[self.modulename] = module
module_spec.loader.exec_module(module)
obj = getattr(module, self.symbol)
self.target = obj
Expand Down Expand Up @@ -53,6 +54,7 @@ def __init__(self, filename, symbol, modulename, functions):
def initialize(self):
module_spec = importlib.util.spec_from_file_location(self.modulename, self.filename)
module = importlib.util.module_from_spec(module_spec)
sys.modules[self.modulename] = module
module_spec.loader.exec_module(module)
obj = getattr(module, self.symbol)
self.clsname = obj.__name__
Expand Down Expand Up @@ -117,6 +119,7 @@ def load_files(self, module_dir, module_name, toplevel_filter=None, subfilter=No
try:
module_spec = importlib.util.spec_from_file_location(module_name, filename)
module = importlib.util.module_from_spec(module_spec)
sys.modules[module_name] = module
module_spec.loader.exec_module(module)
for symbol in dir(module):
if not self.filter_modulevar(symbol, toplevel_filter):
Expand Down

0 comments on commit ddc076d

Please sign in to comment.