Package: metrics
metricsThe 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.metricsis build in a way to support many, many
languagessupported 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 thesource 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).installationmetricsis released as a Python package so you can apply the std.
Python mechanism for installation:$pipinstallmetricsSome 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:$pipinstallmetricsmetrics.bumpversionmetrics.gitinfometrics.pylintmetrics.pytest-covSample useGet an overview on a package (number of files, used languages, and
metrics):$metrics**/*MetricsSummary:FilesLanguageSLOCCommentMcCabe-----------------------------------------------------------6C14303C++11142361081INI5002Java27813JavaScript1453541691markdown70018Python103842523811Textonly000-----------------------------------------------------------45Total3658726516Note how you can use glob file pattern or a list of files…Usage help:$metrics--helpOptions:--versionshowprogram'sversionnumberandexit-h,--helpshowthishelpmessageandexit-fIN_FILE_LIST,--files=IN_FILE_LISTFilecontaininglistofpathnamestomodulesforanalysis.-q,--quietsuppressnormalsummaryoutputtostdout.(DefaultisFalse)--format=OUTPUT_FORMAT_STRChooseanoutputformatforaparsertoread.Validchoices:xml,csv,jsonGet a detailed report:$metrics-q--format=csvmetrics/metrics.pyfilename,sloc,comments,ratio_comment_to_code,mccabe,languagemetrics/metrics.py,21,14,0.67,1,PythonSame detailed report but output to csv file:$metrics-q--format=csvmetrics/metrics.py>output.csvPlugins for metricsSome plugins are available to collect information from a typical
development environment. Please visit the plugin page for details:version from
.bumpversion.cfgGit changes, commiters,
…Pylint lint scoretest coverageSample “.metrics” file results (with plugins installed){"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}}}Acknowledgementscodebase originally based on grop.py by Jurgen Hermann (2001)also based on PyMetrics by Reg. Charney to do Python complexity
measurements (2007)we use some sample programming language files for the test cases from
Ohcount and FirefoxLicenseCopyright (c) 2017, 2018 Fink Labs GmbH and others. metrics is released
under the MIT License (see MIT_LICENSE).