From f7d29779fb387548edb73dfff8a1e893ee884a20 Mon Sep 17 00:00:00 2001 From: Thamirawaran <107134124+Thamirawaran@users.noreply.github.com> Date: Wed, 15 Jan 2025 15:35:26 +0000 Subject: [PATCH] test cases updated --- .../compiler/passes/main/import_pass.py | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/jac/jaclang/compiler/passes/main/import_pass.py b/jac/jaclang/compiler/passes/main/import_pass.py index 2d4859719..cae35a798 100644 --- a/jac/jaclang/compiler/passes/main/import_pass.py +++ b/jac/jaclang/compiler/passes/main/import_pass.py @@ -202,20 +202,22 @@ def import_jac_mod_from_file(self, target: str) -> ast.Module | None: from jaclang.compiler.compile import jac_file_to_pass from jaclang.compiler.passes.main import SubNodeTabPass - cache_dir = os.path.join( - os.path.dirname(self.ir.loc.mod_path), Constants.JAC_GEN_DIR - ) - os.makedirs(cache_dir, exist_ok=True) - module_name = os.path.splitext(os.path.basename(target))[0] - cache_path = os.path.join(cache_dir, f"{module_name}.pkl") - if not os.path.exists(target): self.error(f"Could not find module {target}") return None if target in self.import_table: return self.import_table[target] try: - mod = self.load_cached_module(target, cache_path, os.path.getmtime(target)) + if settings.cache: + cache_dir = os.path.join( + os.path.dirname(self.ir.loc.mod_path), Constants.JAC_GEN_DIR + ) + os.makedirs(cache_dir, exist_ok=True) + module_name = os.path.splitext(os.path.basename(target))[0] + cache_path = os.path.join(cache_dir, f"{module_name}.pkl") + mod = self.load_cached_module( + target, cache_path, os.path.getmtime(target) + ) if not mod: mod_pass = jac_file_to_pass(file_path=target, target=SubNodeTabPass) self.errors_had += mod_pass.errors_had @@ -439,12 +441,6 @@ def __import_py_module( assert isinstance(self.ir, ast.Module) - cache_dir = os.path.join( - os.path.dirname(self.ir.loc.mod_path), Constants.JAC_GEN_DIR - ) - os.makedirs(cache_dir, exist_ok=True) - cache_path = os.path.join(cache_dir, f"{mod_path}.pkl") - python_raise_map = self.ir.py_info.py_raise_map file_to_raise: Optional[str] = None @@ -472,10 +468,15 @@ def __import_py_module( f"\t{file_to_raise} was raised before, getting it from cache" ) return self.import_table[file_to_raise] - - mod = self.load_cached_module( - file_to_raise, cache_path, os.path.getmtime(file_to_raise) - ) + if settings.cache: + cache_dir = os.path.join( + os.path.dirname(self.ir.loc.mod_path), Constants.JAC_GEN_DIR + ) + os.makedirs(cache_dir, exist_ok=True) + cache_path = os.path.join(cache_dir, f"{mod_path}.pkl") + mod = self.load_cached_module( + file_to_raise, cache_path, os.path.getmtime(file_to_raise) + ) if not mod: with open(file_to_raise, "r", encoding="utf-8") as f: file_source = f.read()