MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / DependencyParser

Class DependencyParser

codewiki/src/be/dependency_analyzer/ast_parser.py:18–165  ·  view source on GitHub ↗

Parser for extracting code components from multi-language repositories.

Source from the content-addressed store, hash-verified

16 self,
17 repo_path: str,
18 include_patterns: list[str] | None = None,
19 exclude_patterns: list[str] | None = None,
20 use_gitignore: bool = True,
21 ):
22 """
23 Initialize the dependency parser.
24
25 Args:
26 repo_path: Path to the repository
27 include_patterns: File patterns to include (e.g., ["*.cs", "*.py"])
28 exclude_patterns: File/directory patterns to exclude (e.g., ["*Tests*"])
29 use_gitignore: Whether to apply Git ignore rules
30 """
31 self.repo_path = os.path.abspath(repo_path)
32 self.components: dict[str, Node] = {}
33 self.modules: set[str] = set()
34 self.include_patterns = include_patterns
35 self.exclude_patterns = exclude_patterns
36 self.use_gitignore = use_gitignore
37
38 self.analysis_service = AnalysisService()
39
40 def parse_repository(self, filtered_folders: list[str] | None = None) -> dict[str, Node]:
41 logger.debug(f"Parsing repository at {self.repo_path}")
42
43 # Log custom patterns if set
44 if self.include_patterns:
45 logger.info(f"Using custom include patterns: {self.include_patterns}")
46 if self.exclude_patterns:
47 logger.info(f"Using custom exclude patterns: {self.exclude_patterns}")
48
49 structure_result = self.analysis_service._analyze_structure(
50 self.repo_path,
51 include_patterns=self.include_patterns,
52 exclude_patterns=self.exclude_patterns,
53 use_gitignore=self.use_gitignore,
54 )
55
56 call_graph_result = self.analysis_service._analyze_call_graph(
57 structure_result["file_tree"], self.repo_path
58 )
59
60 self._build_components_from_analysis(call_graph_result)
61
62 logger.debug(f"Found {len(self.components)} components across {len(self.modules)} modules")
63 return self.components
64
65 def _build_components_from_analysis(self, call_graph_result: dict):
66 functions = call_graph_result.get("functions", [])
67 relationships = call_graph_result.get("relationships", [])
68
69 component_id_mapping = {}
70
71 for func_dict in functions:
72 component_id = func_dict.get("id", "")
73 if not component_id:
74 continue
75

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected