Spaces:
Runtime error
Runtime error
update
Browse files- README.md +2 -2
- app.py +3 -1
- py_code_analyzer/code_imports_analyzer.py +12 -9
README.md
CHANGED
@@ -27,8 +27,8 @@ input to one GitHub public repo's URL(input)
|
|
27 |
|
28 |
## TODOs
|
29 |
|
30 |
-
- [
|
31 |
-
- [
|
32 |
- [x] Fetch python files given public GitHub repo url(owner, repo, path, ref)
|
33 |
- [x] Use `ast` to parse imports among given python files
|
34 |
- [x] Generate a basic `networkx` graph given python imports
|
|
|
27 |
|
28 |
## TODOs
|
29 |
|
30 |
+
- [x] Build a prototype
|
31 |
+
- [x] Finish `generate_imports_graph` implementation
|
32 |
- [x] Fetch python files given public GitHub repo url(owner, repo, path, ref)
|
33 |
- [x] Use `ast` to parse imports among given python files
|
34 |
- [x] Generate a basic `networkx` graph given python imports
|
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
from py_code_analyzer import CodeFetcher, CodeImportsAnalyzer, ImportsGraphVisualizer
|
2 |
|
3 |
-
python_files = CodeFetcher().get_python_files(
|
|
|
|
|
4 |
imports_graph = CodeImportsAnalyzer(python_files).analyze().generate_imports_graph()
|
5 |
ImportsGraphVisualizer().visualize(imports_graph)
|
|
|
1 |
from py_code_analyzer import CodeFetcher, CodeImportsAnalyzer, ImportsGraphVisualizer
|
2 |
|
3 |
+
python_files = CodeFetcher().get_python_files(
|
4 |
+
"cyyeh", "py-code-analyzer", "py_code_analyzer"
|
5 |
+
)
|
6 |
imports_graph = CodeImportsAnalyzer(python_files).analyze().generate_imports_graph()
|
7 |
ImportsGraphVisualizer().visualize(imports_graph)
|
py_code_analyzer/code_imports_analyzer.py
CHANGED
@@ -68,15 +68,18 @@ class CodeImportsAnalyzer:
|
|
68 |
self.imports_graph.add_node(_nodes[0])
|
69 |
|
70 |
# generate graph based on imported modules in each file
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
80 |
|
81 |
return self.imports_graph
|
82 |
|
|
|
68 |
self.imports_graph.add_node(_nodes[0])
|
69 |
|
70 |
# generate graph based on imported modules in each file
|
71 |
+
if python_import["file_name"] != "__init__.py":
|
72 |
+
for _import in python_import["imports"]:
|
73 |
+
if _import["module"] is None:
|
74 |
+
_import_names = _import["name"].split(".")
|
75 |
+
_new_nodes = _import_names + [_nodes[-1]]
|
76 |
+
self._add_edges(_new_nodes)
|
77 |
+
else:
|
78 |
+
_import_names = _import["module"].split(".") + [
|
79 |
+
_import["name"]
|
80 |
+
]
|
81 |
+
_new_nodes = _import_names + [_nodes[-1]]
|
82 |
+
self._add_edges(_new_nodes)
|
83 |
|
84 |
return self.imports_graph
|
85 |
|