Python、C、C++、GO和JavaScript代码(PyLink、PyTestCo和Git的插件)的度量

metrics的Python项目详细描述


LicenseGitHub issues

指标

度量的最初想法是一个平台,可以用 许多不同的指标。当时我只关注SLOC和McCabe 复杂性度量。metrics的构建方式支持许多 语言supported languages。 目前,我们测试支持Python、C、C++、GO和JavaScript。

sloc度量计算行数,但不包括空行和注释。 这有时被称为源代码行(sloc)。在 文献这通常也被称为物理代码行。我 把它简化成我所理解的 我查过的度量包的分母(cccc,sloccount, pymetrics、eclipse metrics、ohcount)。

安装

metrics是作为一个python包发布的,因此您可以应用std。 python安装机制:

$ pip install metrics

有些插件可以从一个典型的 发展环境。如果你有一个相似的环境,你可以 一次安装即可:

$ pip install metrics metrics.bumpversion metrics.gitinfo metrics.pylint metrics.pytest-cov

样品使用

获取包的概述(文件数、使用的语言和 指标):

$ metrics **/*
Metrics Summary:
Files                       Language        SLOC Comment McCabe
----- ------------------------------ ----------- ------- ------
    6                              C          14303                            C++        11142361081                            INI           5002                           Java          27813                     JavaScript        1453541691                       markdown           70018                         Python        103842523811                      Text only           000
----- ------------------------------ ----------- ------- ------
   45                          Total        3658726516

注意如何使用全局文件模式或文件列表…

使用帮助:

$ 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

获取详细报告:

$ 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

相同的详细报告,但输出到csv文件:

$ metrics -q --format=csv metrics/metrics.py > output.csv

度量插件

有些插件可以从一个典型的 发展环境。有关详细信息,请访问插件页:

示例“.metrics”文件结果(安装了插件)

{"build":{"active_branch":"master","committed_datetime":"2018-04-28T12:19:14+02:00","committed_ts":1524910754,"committers":["mark"],"origin":"git@github.com: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,"type":"Function"},{"end":105,"name":"process_file","start":89,"type":"Function"},{"end":108,"name":"get_metrics","start":106,"type":"Function"},{"end":113,"name":"get_build_metrics","start":109,"type":"Function"}],"name":"GitMetric","start":23,"type":"Class"}],"change_frequency":7,"comments":9,"committers_count":1,"language":"Python","lines_added":[96],"lines_deleted":[66,94,97],"mccabe":8,"pylint_score":9.06,"ratio_comment_to_code":0.11,"sloc":83,"test_coverage":0.0,"test_missing":"2-113"},"tests/__init__.py":{"age_days":24.099988425925925,"block_positions":[{"end":10,"name":"here","start":9,"type":"Function"}],"change_frequency":1,"comments":1,"committers_count":1,"language":"Python","mccabe":0,"pylint_score":3.33,"ratio_comment_to_code":0.17,"sloc":6,"test_coverage":83.33,"test_missing":"10"},"tests/test_metrics_gitinfo.py":{"age_days":22.091909722222223,"block_positions":[{"end":19,"name":"tempfolder","start":11,"type":"Function"},{"end":29,"name":"test_metrics_gitinfo_no_git_repo","start":20,"type":"Function"},{"end":39,"name":"test_metrics_gitinfo","start":30,"type":"Function"},{"end":47,"name":"test_metrics_gitinfo_no_lastrun","start":40,"type":"Function"}],"change_frequency":1,"comments":2,"committers_count":1,"language":"Python","mccabe":6,"pylint_score":4.64,"ratio_comment_to_code":0.07,"sloc":29,"test_coverage":100.0}}}

致谢

  • 代码库最初基于jurgen hermann(2001)的grop.py
  • 也基于Pymetrics by Reg。查尼做Python复杂性 测量(2007)
  • 我们为来自 Ohcount和Firefox

许可证

版权所有(c)2017、2018 Fink Labs GmbH及其他。指标发布 根据麻省理工学院的许可证(见麻省理工学院的许可证)。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java我想访问同一类的不同函数中的函数变量   创建字段/值哈希映射的java反射   java Velocity工具向后兼容性?   cmd JAVA运行时错误:发生JNI错误   java spring引导示例hateoas不工作   java为什么Android Studio和gradle可以使用不同的类路径进行单元测试?   java Selenium Firefox驱动程序初始化   java如何在jar中重新定位gradle依赖项的包   java为什么我的单线程hello world应用程序使用22个OS线程?   正则表达式替换Java字符串中的特殊字符   在任何派生类的构造函数之后运行方法的java   java从输入字符串中找出日期   带有libGdx(Java)音乐的安卓studio可以在Android模拟器上工作,但不能在桌面上工作   java我在getconnection的参数方面有错误吗?   java使用JFileChooser访问选定文件   java如何将Json解析为另一个活动   java使用Resources for html和rest server   java更新列表,列表内容来自循环中的方法   java如何在GLSL中读取完整范围的32位整数纹理