# multimetric
![Build status](https://github.com/priv-kweihmann/multimetric/workflows/Build/badge.svg)
[![PyPI version](https://badge.fury.io/py/multimetric.svg)](https://badge.fury.io/py/multimetric)
[![Python version](https://img.shields.io/pypi/pyversions/multimetric)](https://img.shields.io/pypi/pyversions/multimetric)
[![Downloads](https://img.shields.io/pypi/dm/multimetric)](https://img.shields.io/pypi/dm/multimetric)
Calculate code metrics in various languages
## Purpose
This tool tries to calculate the following metrics for many, many programming languages
* Comment to Code percentage
* Cyclomatic complexity according to McCabe
* Difficulty according to Halstead
* Effort according to Halstead
* Fan-Out
* Lines of code
* Maintainability index
* Metric according to pylint
* Metric according to TIOBE
* Number of delivered bugs according to Halstead
* Time required to program according to Halstead
* Volume according to Halstead
This tool was heavily inspired by [metrics](https://github.com/markfink/metrics)
## Fully supported languages
For the following programming language we do offer the complete feature set.
* Bash/Shell
* C
* CoffeeScript
* C++
* C#
* Dart
* Go
* Groovy
* Haskell
* Java
* JavaScript
* Julia
* Kotlin
* Lisp
* Lua
* Objective-C
* Perl
* PHP
* Python
* Ruby
* Rust
* TCL
* TypeScript
* Zig
Other languages work too, but might have a more limited support of what metrics can be extracted.
## Requirements
* python3
* [chardet](https://pypi.org/project/chardet/)
* [Pygments](http://pygments.org/)
## Installation
### PyPi
simply run
```sh
pip3 install multimetric
```
### From source
* git clone this repository
* cd to \<clone folder\>
* Install the needed requirements by running ```pip3 install -r requirements.txt```
* run `python3 setup.py build`
## Usage
```text
usage: multimetric [-h] [--warn_compiler WARN_COMPILER] [--warn_duplication WARN_DUPLICATION] [--warn_functional WARN_FUNCTIONAL] [--warn_standard WARN_STANDARD]
[--warn_security WARN_SECURITY] [--coverage COVERAGE] [--dump] [--verbose] [--jobs JOBS] [--bugpredict {old,new}] [--maintindex {sei,classic,microsoft}]
files [files ...]
Calculate code metrics in various languages
positional arguments:
files Files to parse
options:
-h, --help show this help message and exit
--warn_compiler WARN_COMPILER
File(s) holding information about compiler warnings
--warn_duplication WARN_DUPLICATION
File(s) holding information about code duplications
--warn_functional WARN_FUNCTIONAL
File(s) holding information about static code analysis findings
--warn_standard WARN_STANDARD
File(s) holding information about language standard violations
--warn_security WARN_SECURITY
File(s) File(s) holding information about found security issue
--coverage COVERAGE File(s) with compiler warningsFile(s) holding information about testing coverage
--dump Just dump the token tree
--verbose Verbose logging output
--jobs JOBS Run x jobs in parallel
--bugpredict {old,new}
Method how to calculate the bug prediction
--maintindex {sei,classic,microsoft}
Method how to calculate the maintainability index
Currently you could import files of the following types for --warn_* or --coverage
Following information can be read
<file> = full path to file
<severity> = severity [error, warning, info]
<content> = optional string
Note: you could also add a single line, then <content>
has to be a number reflecting to total number of findings
File formats
csv: CSV file of following line format
<file>,<severity>,[<content>]
json: JSON file
<file>: {
["content": <content>,]
"severity": <severity>
}
```
By default tool guesses the content type by the filename, if that doesn't work for you please see below
## Output
Output will be written to stdout as json.
### Output structure
* `files` contains a list of each file passed by CLI
* `overall` contains the calculated values for all passed files
* `stats` contains the statistically calculated values over all files passed [see Statistical additions](#statistics)
#### Item structure
| item | description | range | recommendation |
| --------------------- | ---------------------------------------------- | -------- | -------------- |
| comment_ratio | Comment to Code percentage | 0..100 | > 30.0 |
| cyclomatic_complexity | Cyclomatic complexity according to McCabe | 0..(inf) | < 10 |
| fanout_external | Number imports from out of tree modules | 0..(inf) | |
| fanout_internal | Number imports from same source tree modules | 0..(inf) | |
| halstead_bugprop | Number of delivered bugs according to Halstead | 0..(inf) | < 0.05 |
| halstead_difficulty | Difficulty according to Halstead | 0..(inf) | |
| halstead_effort | Effort according to Halstead | 0..(inf) | |
| halstead_timerequired | Time required to program according to Halstead | 0..(inf) | |
| halstead_volume | Volume according to Halstead | 0..(inf) | |
| lang | list of identified programming languages | list | |
| loc | Lines of code | 1..(inf) | |
| maintainability_index | Maintainability index | 0..100 | > 80.0 |
| operands_sum | Number of used operands | 1..(inf) | |
| operands_uniq | Number of unique used operands | 1..(inf) | |
| operators_sum | Number of used operators | 1..(inf) | |
| operators_uniq | Number of unique used operators | 1..(inf) | |
| pylint | General quality score according to pylint | 0..100 | > 80.0 |
| tiobe_compiler | Compiler warnings score according to TIOBE | 0..100 | > 90.0 |
| tiobe_complexity | Complexity according to TIOBE | 0..100 | > 80.0 |
| tiobe_coverage | Coverage according to TIOBE | 0..100 | > 80.0 |
| tiobe_duplication | Code duplications score according to TIOBE | 0..100 | > 80.0 |
| tiobe_fanout | Fan-Out score according to TIOBE | 0..100 | > 80.0 |
| tiobe_functional | Functional defect score according to TIOBE | 0..100 | > 90.0 |
| tiobe_security | Security score according to TIOBE | 0..100 | > 90.0 |
| tiobe_standard | Language standard score according to TIOBE | 0..100 | > 80.0 |
| tiobe | General quality score according to TIOBE | 0..100 | > 80.0 |
#### Statistics
The item `stats` contains in addition to the above mentioned the following items, which by themselves contain all the items mentioned at [Item structure](#item-structure)
* `max` = the maximum value of all items of the metric
* `mean` = statistical mean over all items of the metric
* `median` = statistical median over all items of the metric
* `min` = the minimum value of all items of the metric
* `sd` = standard deviation over all items of the metric (needs more than one file to be passed by CLI)
## Further reading
* [Pygments](http://pygments.org/)
## Bugs & Contribution
Feel free to create issues or pull requests
### Contribution
```mermaid
flowchart TD
A[I want to contribute!] --> C(Code your changes)
C -->|Flake8 successful| E[Open PR]
C -->|pytest successful| E[Open PR]
C -->|Contribution guideline accepted| E[Open PR]
C -->|README updated| E[Open PR]
```
### Contribute settings for a new language
```mermaid
flowchart TD
A[I want to contribute a new language config!] --> A1(Find permissively licensed test code)
A1 --> B(Pygments contains a lexer for the language)
B --> C(Create fanout settings)
C --> D[Code your changes]
D -->|Flake8 successful| E[Open PR]
D -->|pytest successful| E[Open PR]
D -->|Contribution guideline accepted| E[Open PR]
D -->|README updated| E[Open PR]
```
Raw data
{
"_id": null,
"home_page": "https://github.com/priv-kweihmann/multimetric",
"name": "multimetric",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Konrad Weihmann",
"author_email": "kweihmann@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/ce/c3/c32baa5b61af69ae3cdb13b82bfdea283183653376f0ccd8bc57b59986ba/multimetric-2.2.1.tar.gz",
"platform": null,
"description": "# multimetric\n\n![Build status](https://github.com/priv-kweihmann/multimetric/workflows/Build/badge.svg)\n[![PyPI version](https://badge.fury.io/py/multimetric.svg)](https://badge.fury.io/py/multimetric)\n[![Python version](https://img.shields.io/pypi/pyversions/multimetric)](https://img.shields.io/pypi/pyversions/multimetric)\n[![Downloads](https://img.shields.io/pypi/dm/multimetric)](https://img.shields.io/pypi/dm/multimetric)\n\nCalculate code metrics in various languages\n\n## Purpose\n\nThis tool tries to calculate the following metrics for many, many programming languages\n\n* Comment to Code percentage\n* Cyclomatic complexity according to McCabe\n* Difficulty according to Halstead\n* Effort according to Halstead\n* Fan-Out\n* Lines of code\n* Maintainability index\n* Metric according to pylint\n* Metric according to TIOBE\n* Number of delivered bugs according to Halstead\n* Time required to program according to Halstead\n* Volume according to Halstead\n\nThis tool was heavily inspired by [metrics](https://github.com/markfink/metrics)\n\n## Fully supported languages\n\nFor the following programming language we do offer the complete feature set.\n\n* Bash/Shell\n* C\n* CoffeeScript\n* C++\n* C#\n* Dart\n* Go\n* Groovy\n* Haskell\n* Java\n* JavaScript\n* Julia\n* Kotlin\n* Lisp\n* Lua\n* Objective-C\n* Perl\n* PHP\n* Python\n* Ruby\n* Rust\n* TCL\n* TypeScript\n* Zig\n\nOther languages work too, but might have a more limited support of what metrics can be extracted.\n\n## Requirements\n\n* python3\n* [chardet](https://pypi.org/project/chardet/)\n* [Pygments](http://pygments.org/)\n\n## Installation\n\n### PyPi\n\nsimply run\n\n```sh\npip3 install multimetric\n```\n\n### From source\n\n* git clone this repository\n* cd to \\<clone folder\\>\n* Install the needed requirements by running ```pip3 install -r requirements.txt```\n* run `python3 setup.py build`\n\n## Usage\n\n```text\nusage: multimetric [-h] [--warn_compiler WARN_COMPILER] [--warn_duplication WARN_DUPLICATION] [--warn_functional WARN_FUNCTIONAL] [--warn_standard WARN_STANDARD]\n [--warn_security WARN_SECURITY] [--coverage COVERAGE] [--dump] [--verbose] [--jobs JOBS] [--bugpredict {old,new}] [--maintindex {sei,classic,microsoft}]\n files [files ...]\n\nCalculate code metrics in various languages\n\npositional arguments:\n files Files to parse\n\noptions:\n -h, --help show this help message and exit\n --warn_compiler WARN_COMPILER\n File(s) holding information about compiler warnings\n --warn_duplication WARN_DUPLICATION\n File(s) holding information about code duplications\n --warn_functional WARN_FUNCTIONAL\n File(s) holding information about static code analysis findings\n --warn_standard WARN_STANDARD\n File(s) holding information about language standard violations\n --warn_security WARN_SECURITY\n File(s) File(s) holding information about found security issue\n --coverage COVERAGE File(s) with compiler warningsFile(s) holding information about testing coverage\n --dump Just dump the token tree\n --verbose Verbose logging output\n --jobs JOBS Run x jobs in parallel\n --bugpredict {old,new}\n Method how to calculate the bug prediction\n --maintindex {sei,classic,microsoft}\n Method how to calculate the maintainability index\n\nCurrently you could import files of the following types for --warn_* or --coverage\n\nFollowing information can be read\n\n <file> = full path to file\n <severity> = severity [error, warning, info]\n <content> = optional string\n\n Note: you could also add a single line, then <content>\n has to be a number reflecting to total number of findings\n\nFile formats\n\ncsv: CSV file of following line format\n <file>,<severity>,[<content>]\n\njson: JSON file\n <file>: {\n [\"content\": <content>,]\n \"severity\": <severity>\n }\n```\n\nBy default tool guesses the content type by the filename, if that doesn't work for you please see below\n\n## Output\n\nOutput will be written to stdout as json.\n\n### Output structure\n\n* `files` contains a list of each file passed by CLI\n* `overall` contains the calculated values for all passed files\n* `stats` contains the statistically calculated values over all files passed [see Statistical additions](#statistics)\n\n#### Item structure\n\n| item | description | range | recommendation |\n| --------------------- | ---------------------------------------------- | -------- | -------------- |\n| comment_ratio | Comment to Code percentage | 0..100 | > 30.0 |\n| cyclomatic_complexity | Cyclomatic complexity according to McCabe | 0..(inf) | < 10 |\n| fanout_external | Number imports from out of tree modules | 0..(inf) | |\n| fanout_internal | Number imports from same source tree modules | 0..(inf) | |\n| halstead_bugprop | Number of delivered bugs according to Halstead | 0..(inf) | < 0.05 |\n| halstead_difficulty | Difficulty according to Halstead | 0..(inf) | |\n| halstead_effort | Effort according to Halstead | 0..(inf) | |\n| halstead_timerequired | Time required to program according to Halstead | 0..(inf) | |\n| halstead_volume | Volume according to Halstead | 0..(inf) | |\n| lang | list of identified programming languages | list | |\n| loc | Lines of code | 1..(inf) | |\n| maintainability_index | Maintainability index | 0..100 | > 80.0 |\n| operands_sum | Number of used operands | 1..(inf) | |\n| operands_uniq | Number of unique used operands | 1..(inf) | |\n| operators_sum | Number of used operators | 1..(inf) | |\n| operators_uniq | Number of unique used operators | 1..(inf) | |\n| pylint | General quality score according to pylint | 0..100 | > 80.0 |\n| tiobe_compiler | Compiler warnings score according to TIOBE | 0..100 | > 90.0 |\n| tiobe_complexity | Complexity according to TIOBE | 0..100 | > 80.0 |\n| tiobe_coverage | Coverage according to TIOBE | 0..100 | > 80.0 |\n| tiobe_duplication | Code duplications score according to TIOBE | 0..100 | > 80.0 |\n| tiobe_fanout | Fan-Out score according to TIOBE | 0..100 | > 80.0 |\n| tiobe_functional | Functional defect score according to TIOBE | 0..100 | > 90.0 |\n| tiobe_security | Security score according to TIOBE | 0..100 | > 90.0 |\n| tiobe_standard | Language standard score according to TIOBE | 0..100 | > 80.0 |\n| tiobe | General quality score according to TIOBE | 0..100 | > 80.0 |\n\n#### Statistics\n\nThe item `stats` contains in addition to the above mentioned the following items, which by themselves contain all the items mentioned at [Item structure](#item-structure)\n\n* `max` = the maximum value of all items of the metric\n* `mean` = statistical mean over all items of the metric\n* `median` = statistical median over all items of the metric\n* `min` = the minimum value of all items of the metric\n* `sd` = standard deviation over all items of the metric (needs more than one file to be passed by CLI)\n\n## Further reading\n\n* [Pygments](http://pygments.org/)\n\n## Bugs & Contribution\n\nFeel free to create issues or pull requests\n\n### Contribution\n\n```mermaid\nflowchart TD\n A[I want to contribute!] --> C(Code your changes)\n C -->|Flake8 successful| E[Open PR]\n C -->|pytest successful| E[Open PR]\n C -->|Contribution guideline accepted| E[Open PR]\n C -->|README updated| E[Open PR]\n```\n\n### Contribute settings for a new language\n\n```mermaid\nflowchart TD\n A[I want to contribute a new language config!] --> A1(Find permissively licensed test code)\n A1 --> B(Pygments contains a lexer for the language)\n B --> C(Create fanout settings)\n C --> D[Code your changes]\n D -->|Flake8 successful| E[Open PR]\n D -->|pytest successful| E[Open PR]\n D -->|Contribution guideline accepted| E[Open PR]\n D -->|README updated| E[Open PR]\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Calculate code metrics in various languages",
"version": "2.2.1",
"project_urls": {
"Homepage": "https://github.com/priv-kweihmann/multimetric"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a1883e19ba0c98d1ed62971db67e1873ced2ca4fc515c80f7ece60aec7ec3a66",
"md5": "22577fa21af7c4386c9caaa0cba70cec",
"sha256": "5c94b03c0dcc9d0aacdf182d9b9c979f2fea99fdc61cdfd91f69732fd2366fd4"
},
"downloads": -1,
"filename": "multimetric-2.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "22577fa21af7c4386c9caaa0cba70cec",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 26808,
"upload_time": "2024-05-07T05:32:59",
"upload_time_iso_8601": "2024-05-07T05:32:59.586285Z",
"url": "https://files.pythonhosted.org/packages/a1/88/3e19ba0c98d1ed62971db67e1873ced2ca4fc515c80f7ece60aec7ec3a66/multimetric-2.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cec3c32baa5b61af69ae3cdb13b82bfdea283183653376f0ccd8bc57b59986ba",
"md5": "36a1cd9f7827d58c602b55119447ca8f",
"sha256": "a12bb18aea0a5cb3d71d2368c10ee46185c4de615636de12fb0fce164563c66c"
},
"downloads": -1,
"filename": "multimetric-2.2.1.tar.gz",
"has_sig": false,
"md5_digest": "36a1cd9f7827d58c602b55119447ca8f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 27748,
"upload_time": "2024-05-07T05:33:01",
"upload_time_iso_8601": "2024-05-07T05:33:01.719747Z",
"url": "https://files.pythonhosted.org/packages/ce/c3/c32baa5b61af69ae3cdb13b82bfdea283183653376f0ccd8bc57b59986ba/multimetric-2.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-07 05:33:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "priv-kweihmann",
"github_project": "multimetric",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "multimetric"
}