From 21c56bc845046371618905d0a84f5290fdb50c9c Mon Sep 17 00:00:00 2001 From: Ashish Mahendra Date: Tue, 27 Aug 2024 14:39:45 +0000 Subject: [PATCH] fix: sys.module dependency --- jaclang/runtimelib/importer.py | 6 +++--- jaclang/runtimelib/machine.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/jaclang/runtimelib/importer.py b/jaclang/runtimelib/importer.py index 39f1dd1cf..39c221a9b 100644 --- a/jaclang/runtimelib/importer.py +++ b/jaclang/runtimelib/importer.py @@ -202,7 +202,7 @@ def run_import(self, spec: ImportPathSpec) -> ImportReturn: def update_sys(self, module: types.ModuleType, spec: ImportPathSpec) -> None: """Update sys.modules with the newly imported module.""" if spec.module_name not in self.jac_machine.loaded_modules: - self.jac_machine.loaded_modules[spec.module_name] = module + self.jac_machine.load_module(spec.module_name, module) class PythonImporter(Importer): @@ -305,7 +305,7 @@ def handle_directory( module.__file__ = None if module_name not in self.jac_machine.loaded_modules: - self.jac_machine.loaded_modules[module_name] = module + self.jac_machine.load_module(module_name, module) return module def create_jac_py_module( @@ -331,7 +331,7 @@ def create_jac_py_module( module_name=package_name, full_mod_path=full_mod_path, ) - self.jac_machine.loaded_modules[module_name] = module + self.jac_machine.load_module(module_name, module) return module def run_import( diff --git a/jaclang/runtimelib/machine.py b/jaclang/runtimelib/machine.py index 846267bb5..866fb77c2 100644 --- a/jaclang/runtimelib/machine.py +++ b/jaclang/runtimelib/machine.py @@ -3,6 +3,7 @@ import inspect import marshal import os +import sys import types from typing import Dict, Optional @@ -59,6 +60,7 @@ def get_bytecode( def load_module(self, module_name: str, module: types.ModuleType) -> None: """Load a module into the machine.""" self.loaded_modules[module_name] = module + sys.modules[module_name] = module def list_modules(self) -> list[str]: """List all loaded modules."""