diff --git a/r2e/models/module.py b/r2e/models/module.py index 00b45f0..ecac98c 100644 --- a/r2e/models/module.py +++ b/r2e/models/module.py @@ -20,11 +20,31 @@ class Module(BaseModel): @property def local_path(self) -> str: - path = self.module_id.identifier.replace(".", "/") - if self.module_type == ModuleTypeEnum.PACKAGE: - return f"{self.repo.repo_path}/{path}" - else: - return f"{self.repo.repo_path}/{path}.py" + parts = self.module_id.identifier.split(".") + path = self.repo.repo_path + segment = "" + + for i, part in enumerate(parts): + # accumulate a path segment until full path exists + segment = f"{segment}.{part}" if segment else part + current_path = os.path.join(path, segment) + + # if the path exists, reset segment + if os.path.exists(current_path): + path = current_path + segment = "" + + elif i == len(parts) - 1: + # if module is a file, check if it exists + if self.module_type != ModuleTypeEnum.PACKAGE: + py_path = f"{current_path}.py" + if os.path.exists(py_path): + return py_path + + # if a package, return directory + return os.path.join(path, segment) + + return path @property def relative_module_path(self) -> str: