Skip to content

Commit 435ea9c

Browse files
committed
Create stubs for entrypoint methods
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
1 parent 3c30cad commit 435ea9c

1 file changed

Lines changed: 67 additions & 60 deletions

File tree

cldk/analysis/python/python_analysis.py

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def __init__(
6767
use_codeql: bool = False,
6868
) -> None:
6969
if project_dir is None:
70-
raise ValueError("project_dir is required; source_code mode is not supported for Python.")
70+
raise ValueError(
71+
"project_dir is required; source_code mode is not supported for Python."
72+
)
7173
self.project_dir = project_dir
7274
self.analysis_level = analysis_level
7375
self.analysis_json_path = analysis_json_path
@@ -85,7 +87,7 @@ def __init__(
8587
use_codeql=use_codeql,
8688
)
8789

88-
# ---------------------------------------------------- treesitter passthrough
90+
# -----[ treesitter passthrough ]-----
8991
def is_parsable(self, source_code: str) -> bool:
9092
"""Return True when ``source_code`` parses as Python."""
9193
return self.treesitter_python.is_parsable(source_code)
@@ -94,7 +96,7 @@ def get_raw_ast(self, source_code: str) -> Tree:
9496
"""Return the raw tree-sitter AST for ``source_code``."""
9597
return self.treesitter_python.get_raw_ast(source_code)
9698

97-
# --------------------------------------------------------- application view
99+
# -----[ application view ]-----
98100
def get_application_view(self) -> PyApplication:
99101
"""Return the analyzed :class:`PyApplication`."""
100102
return self.backend.get_application_view()
@@ -103,10 +105,6 @@ def get_symbol_table(self) -> Dict[str, PyModule]:
103105
"""Return the symbol table keyed by file path."""
104106
return self.backend.get_symbol_table()
105107

106-
def get_compilation_units(self) -> List[PyModule]:
107-
"""Return all modules. Java-parlance alias for :meth:`get_modules`."""
108-
return self.backend.get_modules()
109-
110108
def get_modules(self) -> List[PyModule]:
111109
"""Return all modules."""
112110
return self.backend.get_modules()
@@ -119,12 +117,14 @@ def get_python_module(self, file_path: str) -> PyModule | None:
119117
"""Return the :class:`PyModule` for the given file path."""
120118
return self.backend.get_python_module(file_path)
121119

122-
# ---------------------------------------------------------------- imports
120+
# -----[ imports ]-----
123121
def get_imports(self) -> Dict[str, List]:
124122
"""Return imports for each module in the application."""
125-
return {fp: list(m.imports) for fp, m in self.backend.get_symbol_table().items()}
123+
return {
124+
fp: list(m.imports) for fp, m in self.backend.get_symbol_table().items()
125+
}
126126

127-
# ---------------------------------------------------------------- call graph
127+
# -----[ call graph ]-----
128128
def get_call_graph(self) -> nx.DiGraph:
129129
"""Return the call graph as a directed NetworkX graph."""
130130
return self.backend.get_call_graph()
@@ -133,21 +133,29 @@ def get_call_graph_json(self) -> str:
133133
"""Return the analysis serialized to JSON."""
134134
return self.backend.get_call_graph_json()
135135

136-
def get_callers(self, target_class_name: str, target_method_declaration: str) -> Dict:
136+
def get_callers(
137+
self, target_class_name: str, target_method_declaration: str
138+
) -> Dict:
137139
"""Return callers of the target method."""
138-
return self.backend.get_all_callers(target_class_name, target_method_declaration)
140+
return self.backend.get_all_callers(
141+
target_class_name, target_method_declaration
142+
)
139143

140-
def get_callees(self, source_class_name: str, source_method_declaration: str) -> Dict:
144+
def get_callees(
145+
self, source_class_name: str, source_method_declaration: str
146+
) -> Dict:
141147
"""Return callees of the source method."""
142-
return self.backend.get_all_callees(source_class_name, source_method_declaration)
148+
return self.backend.get_all_callees(
149+
source_class_name, source_method_declaration
150+
)
143151

144152
def get_class_call_graph(
145153
self, qualified_class_name: str, method_signature: str | None = None
146154
) -> List[Tuple[str, str]]:
147155
"""Return an edge list reachable from a class (and optionally a method)."""
148156
return self.backend.get_class_call_graph(qualified_class_name, method_signature)
149157

150-
# ---------------------------------------------------------------- methods
158+
# -----[ methods ]-----
151159
def get_methods(self) -> Dict[str, Dict[str, PyCallable]]:
152160
"""Return all methods grouped by class signature."""
153161
return self.backend.get_all_methods_in_application()
@@ -156,19 +164,25 @@ def get_methods_in_class(self, qualified_class_name: str) -> Dict[str, PyCallabl
156164
"""Return methods of the given class."""
157165
return self.backend.get_all_methods_in_class(qualified_class_name)
158166

159-
def get_method(self, qualified_class_name: str, qualified_method_name: str) -> PyCallable | None:
167+
def get_method(
168+
self, qualified_class_name: str, qualified_method_name: str
169+
) -> PyCallable | None:
160170
"""Return the :class:`PyCallable` for the given class+method signatures."""
161171
return self.backend.get_method(qualified_class_name, qualified_method_name)
162172

163-
def get_method_parameters(self, qualified_class_name: str, qualified_method_name: str) -> List[str]:
173+
def get_method_parameters(
174+
self, qualified_class_name: str, qualified_method_name: str
175+
) -> List[str]:
164176
"""Return parameter names for the given method."""
165-
return self.backend.get_method_parameters(qualified_class_name, qualified_method_name)
177+
return self.backend.get_method_parameters(
178+
qualified_class_name, qualified_method_name
179+
)
166180

167181
def get_constructors(self, qualified_class_name: str) -> Dict[str, PyCallable]:
168182
"""Return ``__init__`` methods of the given class."""
169183
return self.backend.get_all_constructors(qualified_class_name)
170184

171-
# ---------------------------------------------------------------- classes
185+
# -----[ classes ]-----
172186
def get_classes(self) -> Dict[str, PyClass]:
173187
"""Return all classes keyed by qualified signature."""
174188
return self.backend.get_all_classes()
@@ -177,7 +191,9 @@ def get_class(self, qualified_class_name: str) -> PyClass | None:
177191
"""Return the :class:`PyClass` for the given qualified signature."""
178192
return self.backend.get_class(qualified_class_name)
179193

180-
def get_classes_by_criteria(self, inclusions=None, exclusions=None) -> Dict[str, PyClass]:
194+
def get_classes_by_criteria(
195+
self, inclusions=None, exclusions=None
196+
) -> Dict[str, PyClass]:
181197
"""Return classes whose qualified name matches inclusion/exclusion filters."""
182198
inclusions = inclusions or []
183199
exclusions = exclusions or []
@@ -206,75 +222,66 @@ def get_extended_classes(self, qualified_class_name: str) -> List[str]:
206222
"""Return base class names of the given class."""
207223
return self.backend.get_extended_classes(qualified_class_name)
208224

209-
# ---------------------------------------------------------------- comments
210-
def get_comments_in_a_method(self, qualified_class_name: str, method_signature: str) -> List[PyComment]:
211-
"""Return comments inside a method."""
212-
return self.backend.get_comments_in_a_method(qualified_class_name, method_signature)
213-
214-
def get_comments_in_a_class(self, qualified_class_name: str) -> List[PyComment]:
215-
"""Return comments inside a class."""
216-
return self.backend.get_comments_in_a_class(qualified_class_name)
217-
218-
def get_comment_in_file(self, file_path: str) -> List[PyComment]:
219-
"""Return comments in a file."""
220-
return self.backend.get_comment_in_file(file_path)
221-
222-
def get_all_comments(self) -> Dict[str, List[PyComment]]:
223-
"""Return every comment in the application, grouped by file path."""
224-
return self.backend.get_all_comments()
225-
226-
def get_all_docstrings(self) -> Dict[str, List[PyComment]]:
227-
"""Return every docstring in the application, grouped by file path."""
228-
return self.backend.get_all_docstrings()
229-
230-
# ---------------------------------------------------------- not yet supported
231-
def get_variables(self, **kwargs):
232-
"""Return all variables. Not implemented."""
233-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
234-
225+
# -----[ unsupported ]-----
235226
def get_class_hierarchy(self) -> nx.DiGraph:
236227
"""Return the class hierarchy. Not implemented."""
237228
raise NotImplementedError("Class hierarchy is not implemented yet.")
238229

239230
def get_service_entry_point_classes(self, **kwargs):
240231
"""Return service entry-point classes. Not implemented."""
241-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
232+
raise NotImplementedError(
233+
"Support for this functionality has not been implemented yet."
234+
)
242235

243236
def get_service_entry_point_methods(self, **kwargs):
244237
"""Return service entry-point methods. Not implemented."""
245-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
238+
raise NotImplementedError(
239+
"Support for this functionality has not been implemented yet."
240+
)
246241

247242
def get_entry_point_classes(self) -> Dict[str, PyClass]:
248243
"""Return entry-point classes. Not implemented."""
249-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
244+
raise NotImplementedError(
245+
"Support for this functionality has not been implemented yet."
246+
)
250247

251248
def get_entry_point_methods(self) -> Dict[str, Dict[str, PyCallable]]:
252249
"""Return entry-point methods. Not implemented."""
253-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
250+
raise NotImplementedError(
251+
"Support for this functionality has not been implemented yet."
252+
)
254253

255254
def get_implemented_interfaces(self, qualified_class_name: str) -> List[str]:
256255
"""Java parity stub — Python has no separate interface concept."""
257-
raise NotImplementedError("Python does not distinguish interfaces from base classes; use get_extended_classes.")
256+
raise NotImplementedError(
257+
"Python does not distinguish interfaces from base classes; use get_extended_classes."
258+
)
258259

259-
def get_methods_with_annotations(self, annotations: List[str]) -> Dict[str, List[Dict]]:
260+
def get_methods_with_decorators(
261+
self, decorators: List[str]
262+
) -> Dict[str, List[Dict]]:
260263
"""Return methods carrying the given decorators. Not implemented."""
261-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
264+
raise NotImplementedError(
265+
"Support for this functionality has not been implemented yet."
266+
)
262267

263268
def get_test_methods(self) -> Dict[str, str]:
264269
"""Return test methods. Not implemented."""
265-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
270+
raise NotImplementedError(
271+
"Support for this functionality has not been implemented yet."
272+
)
266273

267274
def get_calling_lines(self, target_method_name: str) -> List[int]:
268275
"""Return line numbers calling a method. Not implemented."""
269-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
276+
raise NotImplementedError(
277+
"Support for this functionality has not been implemented yet."
278+
)
270279

271280
def get_call_targets(self, declared_methods: dict) -> Set[str]:
272281
"""Return call targets via simple name resolution. Not implemented."""
273-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
274-
275-
def remove_all_comments(self) -> str:
276-
"""Strip comments from source. Not implemented."""
277-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
282+
raise NotImplementedError(
283+
"Support for this functionality has not been implemented yet."
284+
)
278285

279286
def get_all_crud_operations(self):
280287
"""Return CRUD operations. Not implemented."""

0 commit comments

Comments
 (0)