metripy 0.2.5__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.

Potentially problematic release.


This version of metripy might be problematic. Click here for more details.

Files changed (66) hide show
  1. metripy-0.2.5.dist-info/METADATA +112 -0
  2. metripy-0.2.5.dist-info/RECORD +66 -0
  3. metripy-0.2.5.dist-info/WHEEL +5 -0
  4. metripy-0.2.5.dist-info/entry_points.txt +2 -0
  5. metripy-0.2.5.dist-info/licenses/LICENSE +21 -0
  6. metripy-0.2.5.dist-info/top_level.txt +1 -0
  7. src/Application/Analyzer.py +105 -0
  8. src/Application/Application.py +54 -0
  9. src/Application/Config/Config.py +13 -0
  10. src/Application/Config/File/ConfigFileReaderFactory.py +22 -0
  11. src/Application/Config/File/ConfigFileReaderInterface.py +14 -0
  12. src/Application/Config/File/JsonConfigFileReader.py +81 -0
  13. src/Application/Config/GitConfig.py +10 -0
  14. src/Application/Config/Parser.py +30 -0
  15. src/Application/Config/ProjectConfig.py +27 -0
  16. src/Application/Config/ReportConfig.py +10 -0
  17. src/Application/__init__.py +0 -0
  18. src/Component/Debug/Debugger.py +20 -0
  19. src/Component/File/Finder.py +37 -0
  20. src/Component/Output/CliOutput.py +49 -0
  21. src/Component/Output/ProgressBar.py +27 -0
  22. src/Dependency/Composer/Composer.py +30 -0
  23. src/Dependency/Composer/Packegist.py +55 -0
  24. src/Dependency/Dependency.py +30 -0
  25. src/Dependency/Npm/Npm.py +30 -0
  26. src/Dependency/Npm/NpmOrg.py +47 -0
  27. src/Dependency/Pip/Pip.py +69 -0
  28. src/Dependency/Pip/PyPi.py +49 -0
  29. src/Git/GitAnalyzer.py +86 -0
  30. src/LangAnalyzer/AbstractLangAnalyzer.py +65 -0
  31. src/LangAnalyzer/Generic/HalSteadAnalyzer.py +58 -0
  32. src/LangAnalyzer/Generic/__init__.py +0 -0
  33. src/LangAnalyzer/Php/PhpAnalyzer.py +193 -0
  34. src/LangAnalyzer/Php/PhpBasicAstParser.py +56 -0
  35. src/LangAnalyzer/Php/PhpBasicLocAnalyzer.py +174 -0
  36. src/LangAnalyzer/Php/PhpHalSteadAnalyzer.py +44 -0
  37. src/LangAnalyzer/Python/PythonAnalyzer.py +129 -0
  38. src/LangAnalyzer/Typescript/TypescriptAnalyzer.py +210 -0
  39. src/LangAnalyzer/Typescript/TypescriptAstParser.py +68 -0
  40. src/LangAnalyzer/Typescript/TypescriptBasicComplexityAnalyzer.py +114 -0
  41. src/LangAnalyzer/Typescript/TypescriptBasicLocAnalyzer.py +69 -0
  42. src/LangAnalyzer/Typescript/TypescriptHalSteadAnalyzer.py +55 -0
  43. src/LangAnalyzer/__init__.py +0 -0
  44. src/Metric/Code/AggregatedMetrics.py +42 -0
  45. src/Metric/Code/FileMetrics.py +33 -0
  46. src/Metric/Code/ModuleMetrics.py +32 -0
  47. src/Metric/Code/SegmentedMetrics.py +65 -0
  48. src/Metric/FileTree/FileTree.py +15 -0
  49. src/Metric/FileTree/FileTreeParser.py +42 -0
  50. src/Metric/Git/GitCodeHotspot.py +37 -0
  51. src/Metric/Git/GitContributor.py +37 -0
  52. src/Metric/Git/GitKnowledgeSilo.py +27 -0
  53. src/Metric/Git/GitMetrics.py +148 -0
  54. src/Metric/ProjectMetrics.py +55 -0
  55. src/Report/Csv/Reporter.py +12 -0
  56. src/Report/Html/Reporter.py +210 -0
  57. src/Report/Json/AbstractJsonReporter.py +10 -0
  58. src/Report/Json/GitJsonReporter.py +21 -0
  59. src/Report/Json/JsonReporter.py +12 -0
  60. src/Report/ReporterFactory.py +22 -0
  61. src/Report/ReporterInterface.py +17 -0
  62. src/Tree/ClassNode.py +32 -0
  63. src/Tree/FunctionNode.py +49 -0
  64. src/Tree/ModuleNode.py +42 -0
  65. src/__init__.py +0 -0
  66. src/codemetrics.py +15 -0
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: metripy
3
+ Version: 0.2.5
4
+ Summary: A Python tool to generate multi project, multi language code metric reports
5
+ Author-email: Yannick Zimmermann <yannick.zimmermann@proton.me>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/zimmer-yan/codemetrics
8
+ Project-URL: Repository, https://github.com/zimmer-yan/codemetrics
9
+ Project-URL: Documentation, https://github.com/zimmer-yan/codemetrics#readme
10
+ Project-URL: Bug Tracker, https://github.com/zimmer-yan/codemetrics/issues
11
+ Keywords: code metrics,multi-language,code analysis,git metrics,code visualization,software quality,static analysis,repository insights,developer productivity,codebase health,technical debt,language-agnostic
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: lizard==1.18.0
21
+ Requires-Dist: GitPython==3.1.45
22
+ Requires-Dist: py-template-engine>=0.1.0
23
+ Requires-Dist: radon==6.0.1
24
+ Requires-Dist: requests==2.32.5
25
+ Requires-Dist: packaging==25.0
26
+ Requires-Dist: toml==0.10.2
27
+ Requires-Dist: tree-sitter==0.21.3
28
+ Requires-Dist: tree-sitter-languages==1.10.2
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
31
+ Requires-Dist: pytest-cov==7.0.0; extra == "dev"
32
+ Requires-Dist: pytest-mock==3.15.1; extra == "dev"
33
+ Requires-Dist: black>=22.0.0; extra == "dev"
34
+ Requires-Dist: flake8>=5.0.0; extra == "dev"
35
+ Requires-Dist: mypy>=0.991; extra == "dev"
36
+ Requires-Dist: poethepoet==0.37.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # Codemetrics
40
+ A multilanguage, multi project code metrics analysis tool.
41
+
42
+ # Languages
43
+ Supported languages
44
+ - Python (with radon)
45
+ - Php (experimental)
46
+ - Typescript (experimental)
47
+ - TBD
48
+
49
+ # Analysis types
50
+
51
+ ## Code analysis
52
+ Analyses code with cyclomatic complexity, maintainability index, halstead metrics.
53
+
54
+ ## Git analysis
55
+ Analyses git stats of the past months
56
+
57
+ ## Dependeny analysis
58
+ Analyzses composer, npm or pip dependencies
59
+
60
+ More dependencies TBD
61
+
62
+ # Report formats
63
+
64
+ ## Html
65
+ Generates an easy to read dashboard
66
+
67
+ TODO: as this application generates multi project reports, add central dashboard to have project specific insights at first glance
68
+
69
+ ## Csv
70
+ Coming soon...
71
+
72
+ ## Json
73
+ Coming soon...
74
+
75
+ ## Cli
76
+ Coming soon...
77
+
78
+ # Configuration
79
+ Configuration is for the moment only possible with the `--config=<file>.json` option. More TBD
80
+
81
+ Sample configuraiton:
82
+ ```json
83
+ {
84
+ "configs": {
85
+ "funny codemetrics": {
86
+ "base_path": "./", // base path to look at
87
+ "includes": [
88
+ "src/" // paths to include from the base path on
89
+ ],
90
+ "excludes": [
91
+ "__pycache__" // exclude patterns of paths / files
92
+ ],
93
+ "extensions": [
94
+ "py" // file extensions to look at
95
+ ],
96
+ "git": { // if git is set, analyzes git history
97
+ "branch": "main" // git branch to look at
98
+ },
99
+ "composer": true, // looks for base_path/composer.json and analyzes dependencies - for php projects
100
+ "npm": true, // looks for base_path/package.json and analyzes dependencies - for ts/js projects
101
+ "pip": true,
102
+ // looks for base_path/requirements.txt or base_path/pyproject.toml and analyzes dependencies - for python projects
103
+ "reports": {
104
+ "html": "./build/report/codemetrics", // report should be put into this directory
105
+ "json-git": "./build/json-report/codemetrics-git.json" // file where to put git json report
106
+ // more types of reports TBA
107
+ }
108
+ },
109
+ // next project name: { next config... }
110
+ }
111
+ }
112
+ ```
@@ -0,0 +1,66 @@
1
+ metripy-0.2.5.dist-info/licenses/LICENSE,sha256=RQUMdlYUkqBhJgf7iIlzqrlaYz8VGr6KAn60wkv3FzE,1067
2
+ src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ src/codemetrics.py,sha256=zBlIveTZax-kKi20CFFYLKYrpBw1MPzdFXO8NdKqzso,258
4
+ src/Application/Analyzer.py,sha256=e4UQnLXc25F8rBQiHC441DhTabWmFdMZt0EdEgbcO-0,3909
5
+ src/Application/Application.py,sha256=A4ytSzZGaNvs9MQ4egYbTzikkcNXRR7Oayipwa-9N-8,1915
6
+ src/Application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ src/Application/Config/Config.py,sha256=rEO3p57Rf0JCuBlNj16o3i1XoonZYLOdHUvyh09nKXc,345
8
+ src/Application/Config/GitConfig.py,sha256=4y676GYv-FH6QyLxh6IQn64gUG9xOQciMgkXH9pJtb4,220
9
+ src/Application/Config/Parser.py,sha256=gzzpciFtGTOwuoHCOX1GQXecYQT6ndwM0DFDAtSlHrM,882
10
+ src/Application/Config/ProjectConfig.py,sha256=kB5Zl1PdOBYFuTuQkSuc4c2zHl2trNJGu5S-t0SPDbw,916
11
+ src/Application/Config/ReportConfig.py,sha256=Vh3S1n2nyH5YNmt8JrfGRTcmYZuqLMxyFnFF5mmxu_4,259
12
+ src/Application/Config/File/ConfigFileReaderFactory.py,sha256=0WGj8cVD5Bd6KWjA1tthD0iHcFiA9arjMGMzZi1_-lg,897
13
+ src/Application/Config/File/ConfigFileReaderInterface.py,sha256=vJPJdob3zMCYlPT2yNZZnqw_KGbTwWepWfUFiNA-jRs,273
14
+ src/Application/Config/File/JsonConfigFileReader.py,sha256=TEAdCzeGu3I1GD590iMatZZkfvRtyHcy68HcSNK3BQk,2762
15
+ src/Component/Debug/Debugger.py,sha256=puvmjX-AenkXcpHJZuXL2eW0Sq4OEZvDj9diAdyiwZ4,415
16
+ src/Component/File/Finder.py,sha256=nLJqQsnmOkbX9YuuiA0LWfAQEPsfw1hoteZEfAbQtT0,1391
17
+ src/Component/Output/CliOutput.py,sha256=XJ5vJa7jxoukk4fRuj1UVV7GNkkZx-4Jb_Pl7ZYOSFk,1197
18
+ src/Component/Output/ProgressBar.py,sha256=CGt6RfLukbDdfMgVvSkDfOIqEuFBh6LFvmYid2A1IBs,717
19
+ src/Dependency/Dependency.py,sha256=6YSuNPEAbJY5MZ_8ZwMyppnWA_j84dwKx_hzm0eYmYc,1002
20
+ src/Dependency/Composer/Composer.py,sha256=iHNHsGmNOLSOjwUywuzsVqYX2kKPcVA63sUhMYDdzl8,1017
21
+ src/Dependency/Composer/Packegist.py,sha256=frroQwCJjFMonnrs9AueJW3OhTD1IOB-e96tTnZ4YFw,1972
22
+ src/Dependency/Npm/Npm.py,sha256=nwN_LU0B7ukg_E63S3AdnHsGmb521FbUsCBZk9GeyTw,959
23
+ src/Dependency/Npm/NpmOrg.py,sha256=Bp9LUluc_lbqHDHO8O5MNtaIODdN1hYtsmw-XbqjnXM,1543
24
+ src/Dependency/Pip/Pip.py,sha256=MfuUbV86yYKyHngF5Qn2A-6YsQdcf_3gQu_2tKQ9ink,2302
25
+ src/Dependency/Pip/PyPi.py,sha256=cCHU8WEeal9EXPuCfrwWzrj4j6yo2BFpBG4TqGVwEow,1604
26
+ src/Git/GitAnalyzer.py,sha256=DLlQUe3xXRKFG0H7oQjWsbKHGrCyieo3OGwkrF30Rps,3055
27
+ src/LangAnalyzer/AbstractLangAnalyzer.py,sha256=xT12UhRfJ0VeV2yXvNPCXYLIegGG2ps_53pA2ztcCLc,1880
28
+ src/LangAnalyzer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
+ src/LangAnalyzer/Generic/HalSteadAnalyzer.py,sha256=z8h3V7mud5NnzQ67I9G3YhTFKHjO6Z-e_ida2d32YZ4,1845
30
+ src/LangAnalyzer/Generic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
+ src/LangAnalyzer/Php/PhpAnalyzer.py,sha256=j0qorVWBx5tm5c0U5R1XSaNWgRrrVU9bolMrPE43lZI,7379
32
+ src/LangAnalyzer/Php/PhpBasicAstParser.py,sha256=T717e7hM67HBOZ7mvl7Jr4RkCF-Hq-sUMzk__UTheeU,1874
33
+ src/LangAnalyzer/Php/PhpBasicLocAnalyzer.py,sha256=2Vt3pbU0BEy2p8em3ZW_qOe9eGigtpZzVoEhe11S2O8,6229
34
+ src/LangAnalyzer/Php/PhpHalSteadAnalyzer.py,sha256=l6oOqGIss5XHKvKwqqyw4Nu_3v-pRpdlZFIawVIyRCY,1029
35
+ src/LangAnalyzer/Python/PythonAnalyzer.py,sha256=s6Y_DxZEn20ljKFLwY0kLyrx9zAMG_fstPJIktLXbCo,4995
36
+ src/LangAnalyzer/Typescript/TypescriptAnalyzer.py,sha256=7sdcuniPPBqWvJZEuu4q7MWfpwdPLqyqUOxbSTuBVyM,8039
37
+ src/LangAnalyzer/Typescript/TypescriptAstParser.py,sha256=i0AVU1Sx0hJ62eho0wwsUgIRLDJLeAiW_jk_jO8WEKA,2919
38
+ src/LangAnalyzer/Typescript/TypescriptBasicComplexityAnalyzer.py,sha256=zEmqN3ha94XrpQwqtwX6VReNaYrNOkwWH-8igzdFEkE,3800
39
+ src/LangAnalyzer/Typescript/TypescriptBasicLocAnalyzer.py,sha256=hxNqVGDUBb0Dy4cvQFTqfz5cCJTQ8B4uWu9hBnzSO2Y,2336
40
+ src/LangAnalyzer/Typescript/TypescriptHalSteadAnalyzer.py,sha256=b65kNDQaygoHAyG442-mcstYdaj7tlcCuiWslvIj2t0,1270
41
+ src/Metric/ProjectMetrics.py,sha256=qciYncQqQEJiSlX5byKq61HCeRVHi7U1cUfF7xH2bcQ,2054
42
+ src/Metric/Code/AggregatedMetrics.py,sha256=SDpMFLV-hUXkHKFp3tZuCGySRuNGjW2VNkQq8Eqcl9Q,1551
43
+ src/Metric/Code/FileMetrics.py,sha256=NIRRGgmT6eD-cq3DYgwi9vo-v-Eo_cf64eudMu9n6sA,1134
44
+ src/Metric/Code/ModuleMetrics.py,sha256=x45xQbDy56_gSYuKrSPi0iWQFRbE9CPlYpho8_ZdW8c,1169
45
+ src/Metric/Code/SegmentedMetrics.py,sha256=DqXZsagrz5yicAECXGO8e6xvhY9SivkhJvQKH9TKtaw,1730
46
+ src/Metric/FileTree/FileTree.py,sha256=X5KeQ26lCEcUcYoa8q6ITO0kpgqphLmXWlG-NGeXpX0,467
47
+ src/Metric/FileTree/FileTreeParser.py,sha256=AyyyajqXqvttxvT20g6damgeq9ExUCBBettv90fRRWw,1283
48
+ src/Metric/Git/GitCodeHotspot.py,sha256=zdqmXZu9cELpJ7-KGTW3tbmD2so2R6c0w1gYg2OU1jc,1291
49
+ src/Metric/Git/GitContributor.py,sha256=Sn3Rmds7tr1H6CsR8bJ2cfuwG7tRj0vVadD28dKa6OE,1172
50
+ src/Metric/Git/GitKnowledgeSilo.py,sha256=arla_KR2zyfw9O5QPDhxBrkc-bfQ-pvQuA6GUgv2c44,946
51
+ src/Metric/Git/GitMetrics.py,sha256=5gQi2JHjjafZ3fKgLW0pwa6wTCsEMPXc0m_NND-69WY,5745
52
+ src/Report/ReporterFactory.py,sha256=U5wxEuv-Ihi1y7rbVxa1RHaKlZDhCDZJI08iWzTsS7k,857
53
+ src/Report/ReporterInterface.py,sha256=7xLrpTuLPnQRI8uZaovx7-VkLWK2mRIxBLSpmaIgpec,519
54
+ src/Report/Csv/Reporter.py,sha256=N0VJIayP-gakyqJanuQ9vafbGn7d5JRD1R6vCyAruHg,407
55
+ src/Report/Html/Reporter.py,sha256=89eianUFZlhXPSANMHf0yKuMXYhpKwm5Fj-qklUthd8,8598
56
+ src/Report/Json/AbstractJsonReporter.py,sha256=ely5RMqRrIV-kZsWc_-_4JfVDKyQlG5dAytBJkJioO0,334
57
+ src/Report/Json/GitJsonReporter.py,sha256=c45ubLOXpDfEn-3m5re8vx51uhi-yiQJQ8TVrSY4Lno,834
58
+ src/Report/Json/JsonReporter.py,sha256=aPazuX3R1aOpJUDGLG8WDi-7rL_WAN9J_PJ282ftFug,366
59
+ src/Tree/ClassNode.py,sha256=_Ci6B72b5WeQBkv77J3phLw3DRpqQlgk32a-cLeo7v8,908
60
+ src/Tree/FunctionNode.py,sha256=c2T78uGVkNRF_c2jCVmtfAwNFeY3MgASbUApROAsl3c,1520
61
+ src/Tree/ModuleNode.py,sha256=3vrM6ERdh63AGn4Zp06647Fu7KQ3gKenqmjZ72OLWD4,1222
62
+ metripy-0.2.5.dist-info/METADATA,sha256=NShjMgB285S_kVIJUeem3QiJ-TxWpdbidfxZRC0C7ew,3841
63
+ metripy-0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
64
+ metripy-0.2.5.dist-info/entry_points.txt,sha256=G3czqTUzqUsBf_-XbSCVQBp6OIWO9pFjaJa2CATzDks,53
65
+ metripy-0.2.5.dist-info/top_level.txt,sha256=74rtVfumQlgAPzR5_2CgYN24MB0XARCg0t-gzk6gTrM,4
66
+ metripy-0.2.5.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ codemetrics = src.codemetrics:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 CodeMetrics
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ src
@@ -0,0 +1,105 @@
1
+ from Application.Config.ProjectConfig import ProjectConfig
2
+ from Component.Debug.Debugger import Debugger
3
+ from Component.Output.CliOutput import CliOutput
4
+ from Component.Output.ProgressBar import ProgressBar
5
+ from Dependency.Composer.Composer import Composer
6
+ from Dependency.Dependency import Dependency
7
+ from Dependency.Npm.Npm import Npm
8
+ from Dependency.Pip.Pip import Pip
9
+ from Git.GitAnalyzer import GitAnalyzer
10
+ from LangAnalyzer.AbstractLangAnalyzer import AbstractLangAnalyzer
11
+ from LangAnalyzer.Php.PhpAnalyzer import PhpAnalyzer
12
+ from LangAnalyzer.Python.PythonAnalyzer import PythonAnalyzer
13
+ from LangAnalyzer.Typescript.TypescriptAnalyzer import TypescriptAnalyzer
14
+ from Metric.Code.FileMetrics import FileMetrics
15
+ from Metric.Git.GitMetrics import GitMetrics
16
+ from Metric.ProjectMetrics import ProjectMetrics
17
+
18
+
19
+ class Analyzer:
20
+ def __init__(self, config: ProjectConfig, output: CliOutput, debugger: Debugger):
21
+ self.config = config
22
+ self.output = output
23
+ self.debugger = debugger
24
+ self.runners: list[AbstractLangAnalyzer] = [
25
+ PythonAnalyzer(),
26
+ PhpAnalyzer(),
27
+ TypescriptAnalyzer(),
28
+ ]
29
+
30
+ def analyze_git(self) -> GitMetrics:
31
+ self.output.writeln("<info>Analyzing git history...</info>")
32
+ metrics = GitAnalyzer(self.config.git).analyze()
33
+ self.output.writeln("<success>Git history analyzed</success>")
34
+
35
+ return metrics
36
+
37
+ def analyze_code(self, files: list[str]) -> list[FileMetrics]:
38
+ file_metrics = []
39
+
40
+ # for multi language projects, register runner per language
41
+ runner_sizes = []
42
+ for runner in self.runners:
43
+ runner.set_files(files)
44
+ if not runner.is_needed():
45
+ continue
46
+ runner_sizes.append(len(runner.files))
47
+
48
+ self.debugger.debug(len(files))
49
+ self.output.writeln("<info>Analyzing code...</info>")
50
+ progress_bar = ProgressBar(self.output, sum(runner_sizes))
51
+ for runner in self.runners:
52
+ if not runner.is_needed():
53
+ continue
54
+ runner.before_run()
55
+ runner.run(progress_bar)
56
+ runner.after_run()
57
+
58
+ for metric in runner.get_metrics():
59
+ file_metrics.append(metric)
60
+
61
+ self.output.writeln("")
62
+ self.output.writeln("<success>Code analyzed</success>")
63
+
64
+ return file_metrics
65
+
66
+ def analyze_composer(self) -> list[Dependency]:
67
+ self.output.writeln("<info>Analyzing composer packages...</info>")
68
+ dependencies = Composer().get_composer_dependencies(self.config.base_path)
69
+ self.output.writeln("<success>Composer packages analyzed</success>")
70
+
71
+ return dependencies
72
+
73
+ def analyze_pip(self) -> list[Dependency]:
74
+ self.output.writeln("<info>Analyzing pip packages...</info>")
75
+ dependencies = Pip().get_dependencies(self.config.base_path)
76
+ self.output.writeln("<success>Pip packages analyzed</success>")
77
+
78
+ return dependencies
79
+
80
+ def analyze_npm(self) -> list[Dependency]:
81
+ self.output.writeln("<info>Analyzing npm packages...</info>")
82
+ dependencies = Npm().get_dependencies(self.config.base_path)
83
+ self.output.writeln("<success>Npm packages analyzed</success>")
84
+
85
+ return dependencies
86
+
87
+ def run(self, files: list[str]) -> ProjectMetrics:
88
+ git_stats = None
89
+ if self.config.git:
90
+ git_stats = self.analyze_git()
91
+
92
+ file_metrics = []
93
+ if True:
94
+ file_metrics = self.analyze_code(files)
95
+
96
+ # TODO: analyze dependencies: composer, pip, npm, etc etc
97
+ packages = None
98
+ if self.config.composer:
99
+ packages = self.analyze_composer()
100
+ elif self.config.pip:
101
+ packages = self.analyze_pip()
102
+ elif self.config.npm:
103
+ packages = self.analyze_npm()
104
+
105
+ return ProjectMetrics(file_metrics, git_stats, packages)
@@ -0,0 +1,54 @@
1
+ import json
2
+
3
+ from Application.Analyzer import Analyzer
4
+ from Application.Config.Parser import Parser
5
+ from Component.Debug.Debugger import Debugger
6
+ from Component.File.Finder import Finder
7
+ from Component.Output.CliOutput import CliOutput
8
+ from Report.ReporterFactory import ReporterFactory
9
+ from Report.ReporterInterface import ReporterInterface
10
+
11
+
12
+ class Application:
13
+ def run(self, argv) -> None:
14
+ output = CliOutput()
15
+
16
+ # issues and debug
17
+ debugger = Debugger(output).enable()
18
+
19
+ config = Parser().parse(argv)
20
+
21
+ finder = Finder()
22
+ files = finder.fetch(config.project_configs)
23
+
24
+ for project_config in config.project_configs:
25
+ debugger.debug(project_config.name)
26
+ project_files = files[project_config.name]
27
+ debugger.debug(f"Found {len(project_files)} files")
28
+ debugger.debug(json.dumps(project_files))
29
+
30
+ output.writeln(f"<info>Analying Project {project_config.name}...</info>")
31
+ project_metrics = Analyzer(project_config, output, debugger).run(
32
+ project_files
33
+ )
34
+ output.writeln(
35
+ f"<success>Done analying Project {project_config.name}</success>"
36
+ )
37
+
38
+ if not project_config.reports:
39
+ output.writeln(
40
+ f"<success>Skipping reports of {project_config.name}!</success>"
41
+ )
42
+ continue
43
+
44
+ output.writeln(
45
+ f"<info>Generating reports for {project_config.name}...</info>"
46
+ )
47
+ for report_config in project_config.reports:
48
+ reporter: ReporterInterface = ReporterFactory.create(
49
+ report_config, output
50
+ )
51
+ reporter.generate(project_metrics)
52
+ output.writeln(
53
+ f"<success>Reports generated for {project_config.name}</success>"
54
+ )
@@ -0,0 +1,13 @@
1
+ from Application.Config.ProjectConfig import ProjectConfig
2
+
3
+
4
+ class Config:
5
+ def __init__(self):
6
+ self.project_configs: list[ProjectConfig] = []
7
+
8
+ def to_dict(self) -> dict:
9
+ return {
10
+ "project_configs": [
11
+ project_config.to_dict() for project_config in self.project_configs
12
+ ],
13
+ }
@@ -0,0 +1,22 @@
1
+ import os
2
+ import pathlib
3
+
4
+ from Application.Config.File.ConfigFileReaderInterface import ConfigFileReaderInterface
5
+ from Application.Config.File.JsonConfigFileReader import JsonConfigFileReader
6
+
7
+
8
+ class ConfigFileReaderFactory:
9
+ @staticmethod
10
+ def createFromFileName(filename: str) -> ConfigFileReaderInterface:
11
+ if not os.path.isfile(filename):
12
+ raise FileNotFoundError(f"File {filename} does not exist")
13
+
14
+ extension = pathlib.Path(filename).suffix
15
+ if extension == ".json":
16
+ return JsonConfigFileReader(filename)
17
+ elif extension == ".yaml" or extension == ".yml":
18
+ raise NotImplementedError("YAML support is not implemented yet")
19
+ elif extension == ".xml":
20
+ raise NotImplementedError("XML support is not implemented yet")
21
+ else:
22
+ raise NotImplementedError(f"Unsupported file type: {extension}")
@@ -0,0 +1,14 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from Application.Config.Config import Config
4
+
5
+
6
+ class ConfigFileReaderInterface(ABC):
7
+
8
+ @abstractmethod
9
+ def __init__(self, filename: str):
10
+ pass
11
+
12
+ @abstractmethod
13
+ def read(self, config: Config) -> None:
14
+ pass
@@ -0,0 +1,81 @@
1
+ import json
2
+ import os
3
+
4
+ from Application.Config.Config import Config
5
+ from Application.Config.File.ConfigFileReaderInterface import ConfigFileReaderInterface
6
+ from Application.Config.GitConfig import GitConfig
7
+ from Application.Config.ProjectConfig import ProjectConfig
8
+ from Application.Config.ReportConfig import ReportConfig
9
+
10
+
11
+ class JsonConfigFileReader(ConfigFileReaderInterface):
12
+ def __init__(self, filename: str):
13
+ self.filename = filename
14
+
15
+ def read(self, config: Config) -> None:
16
+ with open(self.filename, "r") as file:
17
+ json_data = json.load(file)
18
+
19
+ self.parse_json(json_data, config)
20
+
21
+ def resolve_path(self, path: str) -> str:
22
+ return os.path.join(os.path.dirname(self.filename), path)
23
+
24
+ def parse_json(self, json_data: dict, config: Config) -> None:
25
+
26
+ # configs
27
+ if configs := json_data.get("configs"):
28
+ for project_name, project_config in configs.items():
29
+ project_config = self.parse_config_json(project_name, project_config)
30
+ config.project_configs.append(project_config)
31
+
32
+ def parse_config_json(self, project_name: str, json_data: dict) -> ProjectConfig:
33
+ project_config = ProjectConfig(project_name)
34
+
35
+ # extensions
36
+ if base_path := json_data.get("base_path"):
37
+ project_config.base_path = base_path
38
+
39
+ # includes
40
+ if includes := json_data.get("includes"):
41
+ files = []
42
+ # with config file, includes are relative to the config file
43
+ for include in includes:
44
+ include = self.resolve_path(include)
45
+ files.append(include)
46
+
47
+ project_config.includes = files
48
+
49
+ # extensions
50
+ if extensions := json_data.get("extensions"):
51
+ project_config.extensions = extensions
52
+
53
+ # excludes
54
+ if excludes := json_data.get("excludes"):
55
+ project_config.excludes = excludes
56
+
57
+ # reports
58
+ if reports := json_data.get("reports"):
59
+ for report_type, path in reports.items():
60
+ path = self.resolve_path(path)
61
+ project_config.reports.append(ReportConfig(report_type, path))
62
+
63
+ # git
64
+ if git := json_data.get("git"):
65
+ project_config.git = GitConfig()
66
+ project_config.git.repo = project_config.base_path
67
+ project_config.git.branch = git.get("branch", project_config.git.branch)
68
+
69
+ # composer
70
+ if composer := json_data.get("composer"):
71
+ project_config.composer = composer
72
+
73
+ # pip
74
+ if pip := json_data.get("pip"):
75
+ project_config.pip = pip
76
+
77
+ # npm
78
+ if npm := json_data.get("npm"):
79
+ project_config.npm = npm
80
+
81
+ return project_config
@@ -0,0 +1,10 @@
1
+ class GitConfig:
2
+ def __init__(self):
3
+ self.repo = "./"
4
+ self.branch = "main"
5
+
6
+ def to_dict(self) -> dict:
7
+ return {
8
+ "repo": self.repo,
9
+ "branch": self.branch,
10
+ }
@@ -0,0 +1,30 @@
1
+ import re
2
+
3
+ from Application.Config.Config import Config
4
+ from Application.Config.File.ConfigFileReaderFactory import ConfigFileReaderFactory
5
+
6
+
7
+ class Parser:
8
+ def parse(self, argv: list[str]) -> Config:
9
+ config = Config()
10
+
11
+ if argv[0] == "codemetrics.py" or argv[0] == "codemetrics":
12
+ # TODO, fix when path ends with codemetrics.py
13
+ pass
14
+ argv.pop(0)
15
+
16
+ # check for a config file
17
+ for key, arg in enumerate(argv):
18
+ if matches := re.search(r"^--config=(.+)$", arg):
19
+ fileReader = ConfigFileReaderFactory.createFromFileName(
20
+ matches.group(1)
21
+ )
22
+ fileReader.read(config)
23
+ argv.pop(key)
24
+
25
+ # TODO: add the following
26
+ # arguments with options
27
+ # arguments without options
28
+ # last argument
29
+
30
+ return config
@@ -0,0 +1,27 @@
1
+ from Application.Config.GitConfig import GitConfig
2
+ from Application.Config.ReportConfig import ReportConfig
3
+
4
+
5
+ class ProjectConfig:
6
+ def __init__(self, name: str):
7
+ self.name: str = name
8
+ self.base_path: str = "./"
9
+ self.includes: list[str] = []
10
+ self.excludes: list[str] = []
11
+ self.extensions: list[str] = []
12
+ self.git: GitConfig | None = None
13
+ self.composer: bool = False
14
+ self.pip: bool = False
15
+ self.npm: bool = False
16
+ self.reports: list[ReportConfig] = []
17
+
18
+ def to_dict(self) -> dict:
19
+ return {
20
+ "name": self.name,
21
+ "base_path": self.base_path,
22
+ "includes": self.includes,
23
+ "excludes": self.excludes,
24
+ "extensions": self.extensions,
25
+ "git": self.git.to_dict() if self.git else None,
26
+ "reports": [report.to_dict() for report in self.reports],
27
+ }
@@ -0,0 +1,10 @@
1
+ class ReportConfig:
2
+ def __init__(self, report_type: str, path: str) -> None:
3
+ self.type = report_type
4
+ self.path = path
5
+
6
+ def to_dict(self) -> dict:
7
+ return {
8
+ "type": self.type,
9
+ "path": self.path,
10
+ }
File without changes
@@ -0,0 +1,20 @@
1
+ from typing import Self
2
+
3
+ from Component.Output.CliOutput import CliOutput
4
+
5
+
6
+ class Debugger:
7
+ def __init__(self, output: CliOutput):
8
+ self.enabled = False
9
+ self.output = output
10
+
11
+ def enable(self) -> Self:
12
+ self.enabled = True
13
+
14
+ return self
15
+
16
+ def debug(self, message: str):
17
+ if not self.enabled:
18
+ return
19
+
20
+ self.output.writeln(f"<debug>{message}</debug>")
@@ -0,0 +1,37 @@
1
+ import os
2
+
3
+ from Application.Config.ProjectConfig import ProjectConfig
4
+
5
+
6
+ class Finder:
7
+ def fetch(self, project_configs: list[ProjectConfig]) -> dict[str, list[str]]:
8
+ """returns a list of files per project project_name => [files,...]"""
9
+ project_files = {}
10
+ for project_config in project_configs:
11
+ files = []
12
+
13
+ paths = [
14
+ os.path.join(project_config.base_path, inc)
15
+ for inc in project_config.includes
16
+ ]
17
+ for path in paths:
18
+ if os.path.isdir(path):
19
+ self._search(
20
+ path, project_config.extensions, project_config.excludes, files
21
+ )
22
+ project_files[project_config.name] = files
23
+
24
+ return project_files
25
+
26
+ def _search(
27
+ self, path: str, extensions: list[str], excludes: list[str], results: list[str]
28
+ ):
29
+ if not os.path.isdir(path):
30
+ if path not in excludes and path.endswith(tuple(extensions)):
31
+ results.append(path)
32
+
33
+ for file in os.listdir(path):
34
+ if os.path.isdir(os.path.join(path, file)) and file not in excludes:
35
+ self._search(os.path.join(path, file), extensions, excludes, results)
36
+ elif file not in excludes and file.endswith(tuple(extensions)):
37
+ results.append(os.path.join(path, file))