metripy 0.2.7__tar.gz
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.
- metripy-0.2.7/LICENSE +21 -0
- metripy-0.2.7/PKG-INFO +113 -0
- metripy-0.2.7/README.md +74 -0
- metripy-0.2.7/metripy/Application/Analyzer.py +106 -0
- metripy-0.2.7/metripy/Application/Application.py +54 -0
- metripy-0.2.7/metripy/Application/Config/Config.py +13 -0
- metripy-0.2.7/metripy/Application/Config/File/ConfigFileReaderFactory.py +24 -0
- metripy-0.2.7/metripy/Application/Config/File/ConfigFileReaderInterface.py +14 -0
- metripy-0.2.7/metripy/Application/Config/File/JsonConfigFileReader.py +82 -0
- metripy-0.2.7/metripy/Application/Config/GitConfig.py +10 -0
- metripy-0.2.7/metripy/Application/Config/Parser.py +31 -0
- metripy-0.2.7/metripy/Application/Config/ProjectConfig.py +27 -0
- metripy-0.2.7/metripy/Application/Config/ReportConfig.py +10 -0
- metripy-0.2.7/metripy/Application/__init__.py +0 -0
- metripy-0.2.7/metripy/Component/Debug/Debugger.py +20 -0
- metripy-0.2.7/metripy/Component/File/Finder.py +37 -0
- metripy-0.2.7/metripy/Component/Output/CliOutput.py +49 -0
- metripy-0.2.7/metripy/Component/Output/ProgressBar.py +27 -0
- metripy-0.2.7/metripy/Dependency/Composer/Composer.py +30 -0
- metripy-0.2.7/metripy/Dependency/Composer/Packegist.py +55 -0
- metripy-0.2.7/metripy/Dependency/Dependency.py +30 -0
- metripy-0.2.7/metripy/Dependency/Npm/Npm.py +30 -0
- metripy-0.2.7/metripy/Dependency/Npm/NpmOrg.py +47 -0
- metripy-0.2.7/metripy/Dependency/Pip/Pip.py +69 -0
- metripy-0.2.7/metripy/Dependency/Pip/PyPi.py +49 -0
- metripy-0.2.7/metripy/Git/GitAnalyzer.py +86 -0
- metripy-0.2.7/metripy/LangAnalyzer/AbstractLangAnalyzer.py +65 -0
- metripy-0.2.7/metripy/LangAnalyzer/Generic/HalSteadAnalyzer.py +58 -0
- metripy-0.2.7/metripy/LangAnalyzer/Generic/__init__.py +0 -0
- metripy-0.2.7/metripy/LangAnalyzer/Php/PhpAnalyzer.py +193 -0
- metripy-0.2.7/metripy/LangAnalyzer/Php/PhpBasicAstParser.py +56 -0
- metripy-0.2.7/metripy/LangAnalyzer/Php/PhpBasicLocAnalyzer.py +174 -0
- metripy-0.2.7/metripy/LangAnalyzer/Php/PhpHalSteadAnalyzer.py +44 -0
- metripy-0.2.7/metripy/LangAnalyzer/Python/PythonAnalyzer.py +129 -0
- metripy-0.2.7/metripy/LangAnalyzer/Typescript/TypescriptAnalyzer.py +208 -0
- metripy-0.2.7/metripy/LangAnalyzer/Typescript/TypescriptAstParser.py +68 -0
- metripy-0.2.7/metripy/LangAnalyzer/Typescript/TypescriptBasicComplexityAnalyzer.py +114 -0
- metripy-0.2.7/metripy/LangAnalyzer/Typescript/TypescriptBasicLocAnalyzer.py +69 -0
- metripy-0.2.7/metripy/LangAnalyzer/Typescript/TypescriptHalSteadAnalyzer.py +55 -0
- metripy-0.2.7/metripy/LangAnalyzer/__init__.py +0 -0
- metripy-0.2.7/metripy/Metric/Code/AggregatedMetrics.py +42 -0
- metripy-0.2.7/metripy/Metric/Code/FileMetrics.py +33 -0
- metripy-0.2.7/metripy/Metric/Code/ModuleMetrics.py +32 -0
- metripy-0.2.7/metripy/Metric/Code/SegmentedMetrics.py +65 -0
- metripy-0.2.7/metripy/Metric/FileTree/FileTree.py +15 -0
- metripy-0.2.7/metripy/Metric/FileTree/FileTreeParser.py +42 -0
- metripy-0.2.7/metripy/Metric/Git/GitCodeHotspot.py +37 -0
- metripy-0.2.7/metripy/Metric/Git/GitContributor.py +37 -0
- metripy-0.2.7/metripy/Metric/Git/GitKnowledgeSilo.py +27 -0
- metripy-0.2.7/metripy/Metric/Git/GitMetrics.py +148 -0
- metripy-0.2.7/metripy/Metric/ProjectMetrics.py +55 -0
- metripy-0.2.7/metripy/Report/Csv/Reporter.py +12 -0
- metripy-0.2.7/metripy/Report/Html/Reporter.py +210 -0
- metripy-0.2.7/metripy/Report/Json/AbstractJsonReporter.py +11 -0
- metripy-0.2.7/metripy/Report/Json/GitJsonReporter.py +21 -0
- metripy-0.2.7/metripy/Report/Json/JsonReporter.py +12 -0
- metripy-0.2.7/metripy/Report/ReporterFactory.py +22 -0
- metripy-0.2.7/metripy/Report/ReporterInterface.py +17 -0
- metripy-0.2.7/metripy/Tree/ClassNode.py +32 -0
- metripy-0.2.7/metripy/Tree/FunctionNode.py +49 -0
- metripy-0.2.7/metripy/Tree/ModuleNode.py +42 -0
- metripy-0.2.7/metripy/__init__.py +0 -0
- metripy-0.2.7/metripy/metripy.py +15 -0
- metripy-0.2.7/metripy.egg-info/PKG-INFO +113 -0
- metripy-0.2.7/metripy.egg-info/SOURCES.txt +69 -0
- metripy-0.2.7/metripy.egg-info/dependency_links.txt +1 -0
- metripy-0.2.7/metripy.egg-info/entry_points.txt +2 -0
- metripy-0.2.7/metripy.egg-info/requires.txt +19 -0
- metripy-0.2.7/metripy.egg-info/top_level.txt +1 -0
- metripy-0.2.7/pyproject.toml +84 -0
- metripy-0.2.7/setup.cfg +4 -0
metripy-0.2.7/LICENSE
ADDED
|
@@ -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.
|
metripy-0.2.7/PKG-INFO
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: metripy
|
|
3
|
+
Version: 0.2.7
|
|
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
|
+
Requires-Dist: isort==7.0.0; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# Codemetrics
|
|
41
|
+
A multilanguage, multi project code metrics analysis tool.
|
|
42
|
+
|
|
43
|
+
# Languages
|
|
44
|
+
Supported languages
|
|
45
|
+
- Python (with radon)
|
|
46
|
+
- Php (experimental)
|
|
47
|
+
- Typescript (experimental)
|
|
48
|
+
- TBD
|
|
49
|
+
|
|
50
|
+
# Analysis types
|
|
51
|
+
|
|
52
|
+
## Code analysis
|
|
53
|
+
Analyses code with cyclomatic complexity, maintainability index, halstead metrics.
|
|
54
|
+
|
|
55
|
+
## Git analysis
|
|
56
|
+
Analyses git stats of the past months
|
|
57
|
+
|
|
58
|
+
## Dependeny analysis
|
|
59
|
+
Analyzses composer, npm or pip dependencies
|
|
60
|
+
|
|
61
|
+
More dependencies TBD
|
|
62
|
+
|
|
63
|
+
# Report formats
|
|
64
|
+
|
|
65
|
+
## Html
|
|
66
|
+
Generates an easy to read dashboard
|
|
67
|
+
|
|
68
|
+
TODO: as this application generates multi project reports, add central dashboard to have project specific insights at first glance
|
|
69
|
+
|
|
70
|
+
## Csv
|
|
71
|
+
Coming soon...
|
|
72
|
+
|
|
73
|
+
## Json
|
|
74
|
+
Coming soon...
|
|
75
|
+
|
|
76
|
+
## Cli
|
|
77
|
+
Coming soon...
|
|
78
|
+
|
|
79
|
+
# Configuration
|
|
80
|
+
Configuration is for the moment only possible with the `--config=<file>.json` option. More TBD
|
|
81
|
+
|
|
82
|
+
Sample configuraiton:
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"configs": {
|
|
86
|
+
"metripy": {
|
|
87
|
+
"base_path": "./", // base path to look at
|
|
88
|
+
"includes": [
|
|
89
|
+
"metripy/" // paths to include from the base path on
|
|
90
|
+
],
|
|
91
|
+
"excludes": [
|
|
92
|
+
"__pycache__" // exclude patterns of paths / files
|
|
93
|
+
],
|
|
94
|
+
"extensions": [
|
|
95
|
+
"py" // file extensions to look at
|
|
96
|
+
],
|
|
97
|
+
"git": { // if git is set, analyzes git history
|
|
98
|
+
"branch": "main" // git branch to look at
|
|
99
|
+
},
|
|
100
|
+
"composer": true, // looks for base_path/composer.json and analyzes dependencies - for php projects
|
|
101
|
+
"npm": true, // looks for base_path/package.json and analyzes dependencies - for ts/js projects
|
|
102
|
+
"pip": true,
|
|
103
|
+
// looks for base_path/requirements.txt or base_path/pyproject.toml and analyzes dependencies - for python projects
|
|
104
|
+
"reports": {
|
|
105
|
+
"html": "./build/report/codemetrics", // report should be put into this directory
|
|
106
|
+
"json-git": "./build/json-report/codemetrics-git.json" // file where to put git json report
|
|
107
|
+
// more types of reports TBA
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
// next project name: { next config... }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
metripy-0.2.7/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Codemetrics
|
|
2
|
+
A multilanguage, multi project code metrics analysis tool.
|
|
3
|
+
|
|
4
|
+
# Languages
|
|
5
|
+
Supported languages
|
|
6
|
+
- Python (with radon)
|
|
7
|
+
- Php (experimental)
|
|
8
|
+
- Typescript (experimental)
|
|
9
|
+
- TBD
|
|
10
|
+
|
|
11
|
+
# Analysis types
|
|
12
|
+
|
|
13
|
+
## Code analysis
|
|
14
|
+
Analyses code with cyclomatic complexity, maintainability index, halstead metrics.
|
|
15
|
+
|
|
16
|
+
## Git analysis
|
|
17
|
+
Analyses git stats of the past months
|
|
18
|
+
|
|
19
|
+
## Dependeny analysis
|
|
20
|
+
Analyzses composer, npm or pip dependencies
|
|
21
|
+
|
|
22
|
+
More dependencies TBD
|
|
23
|
+
|
|
24
|
+
# Report formats
|
|
25
|
+
|
|
26
|
+
## Html
|
|
27
|
+
Generates an easy to read dashboard
|
|
28
|
+
|
|
29
|
+
TODO: as this application generates multi project reports, add central dashboard to have project specific insights at first glance
|
|
30
|
+
|
|
31
|
+
## Csv
|
|
32
|
+
Coming soon...
|
|
33
|
+
|
|
34
|
+
## Json
|
|
35
|
+
Coming soon...
|
|
36
|
+
|
|
37
|
+
## Cli
|
|
38
|
+
Coming soon...
|
|
39
|
+
|
|
40
|
+
# Configuration
|
|
41
|
+
Configuration is for the moment only possible with the `--config=<file>.json` option. More TBD
|
|
42
|
+
|
|
43
|
+
Sample configuraiton:
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"configs": {
|
|
47
|
+
"metripy": {
|
|
48
|
+
"base_path": "./", // base path to look at
|
|
49
|
+
"includes": [
|
|
50
|
+
"metripy/" // paths to include from the base path on
|
|
51
|
+
],
|
|
52
|
+
"excludes": [
|
|
53
|
+
"__pycache__" // exclude patterns of paths / files
|
|
54
|
+
],
|
|
55
|
+
"extensions": [
|
|
56
|
+
"py" // file extensions to look at
|
|
57
|
+
],
|
|
58
|
+
"git": { // if git is set, analyzes git history
|
|
59
|
+
"branch": "main" // git branch to look at
|
|
60
|
+
},
|
|
61
|
+
"composer": true, // looks for base_path/composer.json and analyzes dependencies - for php projects
|
|
62
|
+
"npm": true, // looks for base_path/package.json and analyzes dependencies - for ts/js projects
|
|
63
|
+
"pip": true,
|
|
64
|
+
// looks for base_path/requirements.txt or base_path/pyproject.toml and analyzes dependencies - for python projects
|
|
65
|
+
"reports": {
|
|
66
|
+
"html": "./build/report/codemetrics", // report should be put into this directory
|
|
67
|
+
"json-git": "./build/json-report/codemetrics-git.json" // file where to put git json report
|
|
68
|
+
// more types of reports TBA
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
// next project name: { next config... }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from metripy.Application.Config.ProjectConfig import ProjectConfig
|
|
2
|
+
from metripy.Component.Debug.Debugger import Debugger
|
|
3
|
+
from metripy.Component.Output.CliOutput import CliOutput
|
|
4
|
+
from metripy.Component.Output.ProgressBar import ProgressBar
|
|
5
|
+
from metripy.Dependency.Composer.Composer import Composer
|
|
6
|
+
from metripy.Dependency.Dependency import Dependency
|
|
7
|
+
from metripy.Dependency.Npm.Npm import Npm
|
|
8
|
+
from metripy.Dependency.Pip.Pip import Pip
|
|
9
|
+
from metripy.Git.GitAnalyzer import GitAnalyzer
|
|
10
|
+
from metripy.LangAnalyzer.AbstractLangAnalyzer import AbstractLangAnalyzer
|
|
11
|
+
from metripy.LangAnalyzer.Php.PhpAnalyzer import PhpAnalyzer
|
|
12
|
+
from metripy.LangAnalyzer.Python.PythonAnalyzer import PythonAnalyzer
|
|
13
|
+
from metripy.LangAnalyzer.Typescript.TypescriptAnalyzer import \
|
|
14
|
+
TypescriptAnalyzer
|
|
15
|
+
from metripy.Metric.Code.FileMetrics import FileMetrics
|
|
16
|
+
from metripy.Metric.Git.GitMetrics import GitMetrics
|
|
17
|
+
from metripy.Metric.ProjectMetrics import ProjectMetrics
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Analyzer:
|
|
21
|
+
def __init__(self, config: ProjectConfig, output: CliOutput, debugger: Debugger):
|
|
22
|
+
self.config = config
|
|
23
|
+
self.output = output
|
|
24
|
+
self.debugger = debugger
|
|
25
|
+
self.runners: list[AbstractLangAnalyzer] = [
|
|
26
|
+
PythonAnalyzer(),
|
|
27
|
+
PhpAnalyzer(),
|
|
28
|
+
TypescriptAnalyzer(),
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
def analyze_git(self) -> GitMetrics:
|
|
32
|
+
self.output.writeln("<info>Analyzing git history...</info>")
|
|
33
|
+
metrics = GitAnalyzer(self.config.git).analyze()
|
|
34
|
+
self.output.writeln("<success>Git history analyzed</success>")
|
|
35
|
+
|
|
36
|
+
return metrics
|
|
37
|
+
|
|
38
|
+
def analyze_code(self, files: list[str]) -> list[FileMetrics]:
|
|
39
|
+
file_metrics = []
|
|
40
|
+
|
|
41
|
+
# for multi language projects, register runner per language
|
|
42
|
+
runner_sizes = []
|
|
43
|
+
for runner in self.runners:
|
|
44
|
+
runner.set_files(files)
|
|
45
|
+
if not runner.is_needed():
|
|
46
|
+
continue
|
|
47
|
+
runner_sizes.append(len(runner.files))
|
|
48
|
+
|
|
49
|
+
self.debugger.debug(len(files))
|
|
50
|
+
self.output.writeln("<info>Analyzing code...</info>")
|
|
51
|
+
progress_bar = ProgressBar(self.output, sum(runner_sizes))
|
|
52
|
+
for runner in self.runners:
|
|
53
|
+
if not runner.is_needed():
|
|
54
|
+
continue
|
|
55
|
+
runner.before_run()
|
|
56
|
+
runner.run(progress_bar)
|
|
57
|
+
runner.after_run()
|
|
58
|
+
|
|
59
|
+
for metric in runner.get_metrics():
|
|
60
|
+
file_metrics.append(metric)
|
|
61
|
+
|
|
62
|
+
self.output.writeln("")
|
|
63
|
+
self.output.writeln("<success>Code analyzed</success>")
|
|
64
|
+
|
|
65
|
+
return file_metrics
|
|
66
|
+
|
|
67
|
+
def analyze_composer(self) -> list[Dependency]:
|
|
68
|
+
self.output.writeln("<info>Analyzing composer packages...</info>")
|
|
69
|
+
dependencies = Composer().get_composer_dependencies(self.config.base_path)
|
|
70
|
+
self.output.writeln("<success>Composer packages analyzed</success>")
|
|
71
|
+
|
|
72
|
+
return dependencies
|
|
73
|
+
|
|
74
|
+
def analyze_pip(self) -> list[Dependency]:
|
|
75
|
+
self.output.writeln("<info>Analyzing pip packages...</info>")
|
|
76
|
+
dependencies = Pip().get_dependencies(self.config.base_path)
|
|
77
|
+
self.output.writeln("<success>Pip packages analyzed</success>")
|
|
78
|
+
|
|
79
|
+
return dependencies
|
|
80
|
+
|
|
81
|
+
def analyze_npm(self) -> list[Dependency]:
|
|
82
|
+
self.output.writeln("<info>Analyzing npm packages...</info>")
|
|
83
|
+
dependencies = Npm().get_dependencies(self.config.base_path)
|
|
84
|
+
self.output.writeln("<success>Npm packages analyzed</success>")
|
|
85
|
+
|
|
86
|
+
return dependencies
|
|
87
|
+
|
|
88
|
+
def run(self, files: list[str]) -> ProjectMetrics:
|
|
89
|
+
git_stats = None
|
|
90
|
+
if self.config.git:
|
|
91
|
+
git_stats = self.analyze_git()
|
|
92
|
+
|
|
93
|
+
file_metrics = []
|
|
94
|
+
if True:
|
|
95
|
+
file_metrics = self.analyze_code(files)
|
|
96
|
+
|
|
97
|
+
# TODO: analyze dependencies: composer, pip, npm, etc etc
|
|
98
|
+
packages = None
|
|
99
|
+
if self.config.composer:
|
|
100
|
+
packages = self.analyze_composer()
|
|
101
|
+
elif self.config.pip:
|
|
102
|
+
packages = self.analyze_pip()
|
|
103
|
+
elif self.config.npm:
|
|
104
|
+
packages = self.analyze_npm()
|
|
105
|
+
|
|
106
|
+
return ProjectMetrics(file_metrics, git_stats, packages)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from metripy.Application.Analyzer import Analyzer
|
|
4
|
+
from metripy.Application.Config.Parser import Parser
|
|
5
|
+
from metripy.Component.Debug.Debugger import Debugger
|
|
6
|
+
from metripy.Component.File.Finder import Finder
|
|
7
|
+
from metripy.Component.Output.CliOutput import CliOutput
|
|
8
|
+
from metripy.Report.ReporterFactory import ReporterFactory
|
|
9
|
+
from metripy.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 metripy.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,24 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
|
|
4
|
+
from metripy.Application.Config.File.ConfigFileReaderInterface import \
|
|
5
|
+
ConfigFileReaderInterface
|
|
6
|
+
from metripy.Application.Config.File.JsonConfigFileReader import \
|
|
7
|
+
JsonConfigFileReader
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ConfigFileReaderFactory:
|
|
11
|
+
@staticmethod
|
|
12
|
+
def createFromFileName(filename: str) -> ConfigFileReaderInterface:
|
|
13
|
+
if not os.path.isfile(filename):
|
|
14
|
+
raise FileNotFoundError(f"File {filename} does not exist")
|
|
15
|
+
|
|
16
|
+
extension = pathlib.Path(filename).suffix
|
|
17
|
+
if extension == ".json":
|
|
18
|
+
return JsonConfigFileReader(filename)
|
|
19
|
+
elif extension == ".yaml" or extension == ".yml":
|
|
20
|
+
raise NotImplementedError("YAML support is not implemented yet")
|
|
21
|
+
elif extension == ".xml":
|
|
22
|
+
raise NotImplementedError("XML support is not implemented yet")
|
|
23
|
+
else:
|
|
24
|
+
raise NotImplementedError(f"Unsupported file type: {extension}")
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
from metripy.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,82 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from metripy.Application.Config.Config import Config
|
|
5
|
+
from metripy.Application.Config.File.ConfigFileReaderInterface import \
|
|
6
|
+
ConfigFileReaderInterface
|
|
7
|
+
from metripy.Application.Config.GitConfig import GitConfig
|
|
8
|
+
from metripy.Application.Config.ProjectConfig import ProjectConfig
|
|
9
|
+
from metripy.Application.Config.ReportConfig import ReportConfig
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class JsonConfigFileReader(ConfigFileReaderInterface):
|
|
13
|
+
def __init__(self, filename: str):
|
|
14
|
+
self.filename = filename
|
|
15
|
+
|
|
16
|
+
def read(self, config: Config) -> None:
|
|
17
|
+
with open(self.filename, "r") as file:
|
|
18
|
+
json_data = json.load(file)
|
|
19
|
+
|
|
20
|
+
self.parse_json(json_data, config)
|
|
21
|
+
|
|
22
|
+
def resolve_path(self, path: str) -> str:
|
|
23
|
+
return os.path.join(os.path.dirname(self.filename), path)
|
|
24
|
+
|
|
25
|
+
def parse_json(self, json_data: dict, config: Config) -> None:
|
|
26
|
+
|
|
27
|
+
# configs
|
|
28
|
+
if configs := json_data.get("configs"):
|
|
29
|
+
for project_name, project_config in configs.items():
|
|
30
|
+
project_config = self.parse_config_json(project_name, project_config)
|
|
31
|
+
config.project_configs.append(project_config)
|
|
32
|
+
|
|
33
|
+
def parse_config_json(self, project_name: str, json_data: dict) -> ProjectConfig:
|
|
34
|
+
project_config = ProjectConfig(project_name)
|
|
35
|
+
|
|
36
|
+
# extensions
|
|
37
|
+
if base_path := json_data.get("base_path"):
|
|
38
|
+
project_config.base_path = base_path
|
|
39
|
+
|
|
40
|
+
# includes
|
|
41
|
+
if includes := json_data.get("includes"):
|
|
42
|
+
files = []
|
|
43
|
+
# with config file, includes are relative to the config file
|
|
44
|
+
for include in includes:
|
|
45
|
+
include = self.resolve_path(include)
|
|
46
|
+
files.append(include)
|
|
47
|
+
|
|
48
|
+
project_config.includes = files
|
|
49
|
+
|
|
50
|
+
# extensions
|
|
51
|
+
if extensions := json_data.get("extensions"):
|
|
52
|
+
project_config.extensions = extensions
|
|
53
|
+
|
|
54
|
+
# excludes
|
|
55
|
+
if excludes := json_data.get("excludes"):
|
|
56
|
+
project_config.excludes = excludes
|
|
57
|
+
|
|
58
|
+
# reports
|
|
59
|
+
if reports := json_data.get("reports"):
|
|
60
|
+
for report_type, path in reports.items():
|
|
61
|
+
path = self.resolve_path(path)
|
|
62
|
+
project_config.reports.append(ReportConfig(report_type, path))
|
|
63
|
+
|
|
64
|
+
# git
|
|
65
|
+
if git := json_data.get("git"):
|
|
66
|
+
project_config.git = GitConfig()
|
|
67
|
+
project_config.git.repo = project_config.base_path
|
|
68
|
+
project_config.git.branch = git.get("branch", project_config.git.branch)
|
|
69
|
+
|
|
70
|
+
# composer
|
|
71
|
+
if composer := json_data.get("composer"):
|
|
72
|
+
project_config.composer = composer
|
|
73
|
+
|
|
74
|
+
# pip
|
|
75
|
+
if pip := json_data.get("pip"):
|
|
76
|
+
project_config.pip = pip
|
|
77
|
+
|
|
78
|
+
# npm
|
|
79
|
+
if npm := json_data.get("npm"):
|
|
80
|
+
project_config.npm = npm
|
|
81
|
+
|
|
82
|
+
return project_config
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from metripy.Application.Config.Config import Config
|
|
4
|
+
from metripy.Application.Config.File.ConfigFileReaderFactory import \
|
|
5
|
+
ConfigFileReaderFactory
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Parser:
|
|
9
|
+
def parse(self, argv: list[str]) -> Config:
|
|
10
|
+
config = Config()
|
|
11
|
+
|
|
12
|
+
if argv[0] == "codemetrics.py" or argv[0] == "codemetrics":
|
|
13
|
+
# TODO, fix when path ends with codemetrics.py
|
|
14
|
+
pass
|
|
15
|
+
argv.pop(0)
|
|
16
|
+
|
|
17
|
+
# check for a config file
|
|
18
|
+
for key, arg in enumerate(argv):
|
|
19
|
+
if matches := re.search(r"^--config=(.+)$", arg):
|
|
20
|
+
fileReader = ConfigFileReaderFactory.createFromFileName(
|
|
21
|
+
matches.group(1)
|
|
22
|
+
)
|
|
23
|
+
fileReader.read(config)
|
|
24
|
+
argv.pop(key)
|
|
25
|
+
|
|
26
|
+
# TODO: add the following
|
|
27
|
+
# arguments with options
|
|
28
|
+
# arguments without options
|
|
29
|
+
# last argument
|
|
30
|
+
|
|
31
|
+
return config
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from metripy.Application.Config.GitConfig import GitConfig
|
|
2
|
+
from metripy.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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from typing import Self
|
|
2
|
+
|
|
3
|
+
from metripy.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 metripy.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))
|