[![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](MIT_LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/finklabs/metrics.svg?maxAge=2592000)](https://github.com/finklabs/metrics/issues)
# metrics
The original idea of metrics was a platform that can be extended with many different metrics. At the time I will focus only on SLOC and McCabe complexity metrics. *metrics* is build in a way to support many, many languages [supported languages](http://pygments.org/languages/). Currently we test support for Python, C, C++, Go and JavaScript.
The SLOC metric counts the lines but excludes empty lines and comments. This is sometimes referred to as the *source lines of code* (SLOC). In literature this is often also referred as physical lines of code. I simplified it to something which to my understanding is the common denominator for the metric packages I looked into (CCCC, SLOCCount, PyMetrics, Eclipse-Metrics, Ohcount).
# installation
**metrics** is released as a Python package so you can apply the std. Python
mechanism for installation:
``` bash
$ pip install metrics
```
Some plugins are available to collect information from a typical development environment.
If you have a similar environment you can install them as well in one go:
``` bash
$ pip install metrics metrics.bumpversion metrics.gitinfo metrics.pylint metrics.pytest-cov
```
# Sample use
Get an overview on a package (number of files, used languages, and metrics):
``` bash
$ metrics **/*
Metrics Summary:
Files Language SLOC Comment McCabe
----- ------------------------------ ----------- ------- ------
6 C 14 3 0
3 C++ 1114 236 108
1 INI 5 0 0
2 Java 27 8 1
3 JavaScript 1453 54 169
1 markdown 7 0 0
18 Python 1038 425 238
11 Text only 0 0 0
----- ------------------------------ ----------- ------- ------
45 Total 3658 726 516
```
Note how you can use glob file pattern or a list of files...
Usage help:
``` bash
$ metrics --help
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-f IN_FILE_LIST, --files=IN_FILE_LIST
File containing list of path names to modules for
analysis.
-q, --quiet suppress normal summary output to stdout. (Default is
False)
--format=OUTPUT_FORMAT_STR
Choose an output format for a parser to read. Valid
choices: xml, csv, json
```
Get a detailed report:
``` bash
$ metrics -q --format=csv metrics/metrics.py
filename,sloc,comments,ratio_comment_to_code,mccabe,language
metrics/metrics.py,21,14,0.67,1,Python
```
Same detailed report but output to csv file:
``` bash
$ metrics -q --format=csv metrics/metrics.py > output.csv
```
# Plugins for metrics
Some plugins are available to collect information from a typical development environment.
Please visit the plugin page for details:
* [version from .bumpversion.cfg](https://github.com/markfink/metrics.bumpversion)
* [Git changes, commiters, ...](https://github.com/markfink/metrics.gitinfo)
* [Pylint lint score](https://github.com/markfink/metrics.pylint)
* [test coverage](https://github.com/markfink/metrics.pytest-cov)
Sample ".metrics" file results (with plugins installed)
``` json
{
"build": {
"active_branch": "master",
"committed_datetime": "2018-04-28T12:19:14+02:00",
"committed_ts": 1524910754,
"committers": [
"mark"
],
"origin": "[email protected]:markfink/metrics.gitinfo.git",
"sha": "4c355c2f6ffef88252e565f6ef5006468e410187",
"sha_start": "f7ba6f27ee8c34991acd3cd6ef14c8bd6ed9c34e",
"summary": "Bump version: 0.0.4 \u2192 0.0.5",
"version": "0.0.5"
},
"files": {
"metrics_gitinfo/__init__.py": {
"age_days": 25.81871527777778,
"block_positions": [],
"change_frequency": 6,
"comments": 1,
"committers_count": 1,
"language": "Python",
"lines_added": [
3
],
"lines_deleted": [
3
],
"mccabe": 0,
"pylint_score": 5.0,
"ratio_comment_to_code": 0.5,
"sloc": 2,
"test_coverage": 0.0,
"test_missing": "2-3"
},
"metrics_gitinfo/file_info.py": {
"age_days": 0.01931712962962963,
"block_positions": [
{
"end": 17,
"name": "get_file_info",
"start": 5,
"type": "Function"
}
],
"change_frequency": 1,
"comments": 4,
"committers_count": 1,
"language": "Python",
"mccabe": 1,
"pylint_score": 10.0,
"ratio_comment_to_code": 0.44,
"sloc": 9,
"test_coverage": 0.0,
"test_missing": "2-17"
},
"metrics_gitinfo/git_diff_muncher.py": {
"age_days": 24.06056712962963,
"block_positions": [
{
"end": 17,
"name": "GitDiffError",
"start": 10,
"type": "Class"
},
{
"end": 81,
"name": "parse_diff_lines",
"start": 18,
"type": "Function"
},
{
"end": 111,
"name": "_parse_hunk_line",
"start": 82,
"type": "Function"
}
],
"change_frequency": 1,
"comments": 50,
"committers_count": 1,
"language": "Python",
"mccabe": 15,
"pylint_score": 9.56,
"ratio_comment_to_code": 1.02,
"sloc": 49,
"test_coverage": 0.0,
"test_missing": "2-129"
},
"metrics_gitinfo/gitinfo.py": {
"age_days": 25.81871527777778,
"block_positions": [
{
"end": 17,
"name": "get_file_processors",
"start": 13,
"type": "Function"
},
{
"end": 22,
"name": "get_build_processors",
"start": 18,
"type": "Function"
},
{
"end": 113,
"methods": [
{
"end": 35,
"name": "_get_commits_contained",
"start": 31,
"type": "Function"
},
{
"end": 41,
"name": "_get_source_target",
"start": 36,
"type": "Function"
},
{
"end": 56,
"name": "_extract_info",
"start": 52,
"type": "Function"
},
{
"end": 88,
"name": "reset",
"start": 84,
PyPI 官网下载 | metrics-0.3.3.tar.gz
版权申诉
6 浏览量
2022-01-13
05:07:01
上传
评论
收藏 18KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈