codeguardian-cli 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. CODEGUARDIAN/__init__.py +0 -0
  2. CODEGUARDIAN/analyzers/__init__.py +0 -0
  3. CODEGUARDIAN/analyzers/circular_dependency_analyzer.py +101 -0
  4. CODEGUARDIAN/analyzers/db_access_analyzer.py +55 -0
  5. CODEGUARDIAN/analyzers/dependency_analyzer.py +259 -0
  6. CODEGUARDIAN/analyzers/file_analyzer.py +96 -0
  7. CODEGUARDIAN/analyzers/function_analyzer.py +199 -0
  8. CODEGUARDIAN/analyzers/source_code_analyzer.py +169 -0
  9. CODEGUARDIAN/cli/__init__.py +0 -0
  10. CODEGUARDIAN/cli/commands.py +619 -0
  11. CODEGUARDIAN/config/__init__.py +0 -0
  12. CODEGUARDIAN/config/config_loader.py +76 -0
  13. CODEGUARDIAN/config/settings.py +2 -0
  14. CODEGUARDIAN/main.py +4 -0
  15. CODEGUARDIAN/reports/__init__.py +0 -0
  16. CODEGUARDIAN/reports/architecture_score.py +68 -0
  17. CODEGUARDIAN/reports/console_reporter.py +487 -0
  18. CODEGUARDIAN/reports/html_reporter.py +293 -0
  19. CODEGUARDIAN/reports/json_reporter.py +69 -0
  20. CODEGUARDIAN/reports/markdown_reporter.py +130 -0
  21. CODEGUARDIAN/reports/severity.py +15 -0
  22. CODEGUARDIAN/reports/statistics_reporter.py +183 -0
  23. CODEGUARDIAN/rules/__init__.py +0 -0
  24. CODEGUARDIAN/rules/architecture_rules.py +5 -0
  25. CODEGUARDIAN/rules/architecture_validator.py +69 -0
  26. CODEGUARDIAN/rules/controllers/user_controller.py +16 -0
  27. CODEGUARDIAN/src/__init__.py +0 -0
  28. CODEGUARDIAN/src/discovery/__init__.py +0 -0
  29. CODEGUARDIAN/src/discovery/finder.py +39 -0
  30. CODEGUARDIAN/src/extractor/__init__.py +0 -0
  31. CODEGUARDIAN/src/extractor/class_extractor.py +32 -0
  32. CODEGUARDIAN/src/extractor/function_extractor.py +17 -0
  33. CODEGUARDIAN/src/extractor/import_extractor.py +23 -0
  34. CODEGUARDIAN/src/extractor/python_class_extractor.py +13 -0
  35. CODEGUARDIAN/src/extractor/python_function_extractor.py +16 -0
  36. CODEGUARDIAN/src/extractor/python_imports_extractor.py +24 -0
  37. CODEGUARDIAN/src/main.py +65 -0
  38. CODEGUARDIAN/src/parser/__init__.py +0 -0
  39. CODEGUARDIAN/src/parser/ts_parser.py +14 -0
  40. CODEGUARDIAN/src/tree/Walker.py +10 -0
  41. CODEGUARDIAN/src/tree/__init__.py +0 -0
  42. CODEGUARDIAN/utils/__init__.py +0 -0
  43. CODEGUARDIAN/utils/ast_cache.py +47 -0
  44. CODEGUARDIAN/utils/file_cache.py +30 -0
  45. CODEGUARDIAN/utils/layer_utils.py +19 -0
  46. codeguardian_cli-1.0.0.dist-info/METADATA +43 -0
  47. codeguardian_cli-1.0.0.dist-info/RECORD +50 -0
  48. codeguardian_cli-1.0.0.dist-info/WHEEL +5 -0
  49. codeguardian_cli-1.0.0.dist-info/entry_points.txt +2 -0
  50. codeguardian_cli-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,169 @@
1
+ import ast
2
+
3
+ from pathlib import Path
4
+
5
+ from CODEGUARDIAN.src.discovery.finder import discover_files
6
+ from CODEGUARDIAN.src.parser.ts_parser import parse_typescript
7
+ from CODEGUARDIAN.utils.file_cache import FileCache
8
+ from CODEGUARDIAN.src.extractor.class_extractor import (
9
+ ClassExtractor
10
+ )
11
+
12
+ from CODEGUARDIAN.src.extractor.function_extractor import (
13
+ functionExtractor
14
+ )
15
+
16
+ from CODEGUARDIAN.src.extractor.import_extractor import (
17
+ importExtractor
18
+ )
19
+
20
+ from CODEGUARDIAN.src.extractor.python_function_extractor import (
21
+ PythonFunctionExtractor
22
+ )
23
+
24
+ from CODEGUARDIAN.src.extractor.python_class_extractor import (
25
+ PythonClassExtractor
26
+ )
27
+
28
+ from CODEGUARDIAN.src.extractor.python_imports_extractor import (
29
+ PythonImportExtractor
30
+ )
31
+
32
+ from CODEGUARDIAN.src.tree.Walker import walk
33
+ from CODEGUARDIAN.utils.ast_cache import ASTCache
34
+
35
+ class SourceCodeAnalyzer:
36
+
37
+ def analyze_python_file(
38
+ self,
39
+ file_path
40
+ ):
41
+
42
+ with open(
43
+ file_path,
44
+ "r",
45
+ encoding="utf-8"
46
+ ) as file:
47
+
48
+ source = file.read()
49
+ try:
50
+ tree = ASTCache.get_tree(
51
+ file_path,
52
+ source
53
+ )
54
+
55
+ except SyntaxError:
56
+ return None
57
+
58
+ class_extractor = (
59
+ PythonClassExtractor()
60
+ )
61
+ class_extractor.extract(tree)
62
+
63
+ function_extractor = (
64
+ PythonFunctionExtractor()
65
+ )
66
+ function_extractor.extract(tree)
67
+
68
+ import_extractor = (
69
+ PythonImportExtractor()
70
+ )
71
+ import_extractor.extract(tree)
72
+
73
+ return {
74
+ "file": str(file_path),
75
+ "classes": class_extractor.classes,
76
+ "functions": function_extractor.functions,
77
+ "imports": import_extractor.imports
78
+ }
79
+
80
+ def analyze_ts_js_file(
81
+ self,
82
+ file_path
83
+ ):
84
+
85
+ with open(
86
+ file_path,
87
+ "r",
88
+ encoding="utf-8"
89
+ ) as file:
90
+
91
+ source = file.read()
92
+ try:
93
+ tree = ASTCache.get_tree(
94
+ file_path,
95
+ source
96
+ )
97
+ except Exception:
98
+ return None
99
+
100
+ if tree.root_node.has_error:
101
+ return None
102
+
103
+ class_extractor = (
104
+ ClassExtractor()
105
+ )
106
+
107
+ function_extractor = (
108
+ functionExtractor()
109
+ )
110
+
111
+ import_extractor = (
112
+ importExtractor()
113
+ )
114
+
115
+ walk(
116
+ tree.root_node,
117
+ class_extractor.visit
118
+ )
119
+
120
+ walk(
121
+ tree.root_node,
122
+ function_extractor.visit
123
+ )
124
+
125
+ walk(
126
+ tree.root_node,
127
+ import_extractor.visit
128
+ )
129
+
130
+ return {
131
+ "file": str(file_path),
132
+ "classes": class_extractor.classes,
133
+ "functions": function_extractor.function,
134
+ "imports": import_extractor.imports
135
+ }
136
+
137
+ def analyze(
138
+ self,
139
+ path
140
+ ):
141
+
142
+ results = []
143
+
144
+ files = FileCache.get_files(
145
+ path,
146
+ {
147
+ ".py",
148
+ ".ts",
149
+ ".js"
150
+ }
151
+ )
152
+
153
+ for file_path in files:
154
+
155
+ if file_path.suffix == ".py":
156
+
157
+ result = self.analyze_python_file(
158
+ file_path
159
+ )
160
+
161
+ else:
162
+
163
+ result = self.analyze_ts_js_file(
164
+ file_path
165
+ )
166
+ if result is not None:
167
+ results.append(result)
168
+
169
+ return results
File without changes