From 5ca7e814cc7d9aacbbd6c02ac8401579d2166abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=86=A0=E5=AE=87?= Date: Wed, 26 Jun 2024 11:00:46 +0800 Subject: [PATCH] fix bugs related to get_module_name and resolve_imports --- .gitignore | 1 + pyan/analyzer.py | 2 +- pyan/anutils.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 990fdc0..2209b40 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,4 @@ htmlcov .idea/ .history/ .vscode/ +*.swp diff --git a/pyan/analyzer.py b/pyan/analyzer.py index 75e9cb1..7ca65de 100644 --- a/pyan/analyzer.py +++ b/pyan/analyzer.py @@ -219,7 +219,7 @@ def resolve_imports(self): and from_node.flavor == Flavor.IMPORTEDITEM ): # use define edges as potential candidates - for candidate_to_node in self.defines_edges[to_node]: # + for candidate_to_node in self.defines_edges.get(to_node, []): # [to_node]: # if candidate_to_node.name == node.name: attribute_import_mapping[node] = candidate_to_node break diff --git a/pyan/anutils.py b/pyan/anutils.py index 8063e61..67261c6 100644 --- a/pyan/anutils.py +++ b/pyan/anutils.py @@ -30,7 +30,7 @@ def get_module_name(filename, root: str = None): module_path = os.path.dirname(filename) else: # otherwise it is the filename without extension - module_path = filename.replace(".py", "") + module_path = filename.rstrip(".py") # find the module root - walk up the tree and check if it contains .py files - if yes. it is the new root directories = [(module_path, True)]