Package: codemetrics
codemetricsMine your SCM for insight on your software. A work of love
inspired byAdam Tornhill’s books.Code metrics is a simple Python module that leverage pandas and your source control management (SCM) tool togenerate
insight on your code base.pandas: for data munching.lizard: for code complexity calculation.cloc.pl (script): for line counts fromclocFor now, only Subversion and git are supported.InstallationTo install codemetrics, simply use pip:pip install codemetricsUsageThis is a simple tool that makes it easy to retrieve information from your
Source Control Management (SCM) repository and hopefully gain insight from it.import codemetrics as cm
import cm.git

project = cm.GitProject('path/to/project')
loc_df = cm.get_cloc(project, cloc_program='/path/to/cloc')
log_df = cm.get_log(project)
ages_df = cm.get_ages(log_df)To retrieve the number of lines changed by revision with Subversion:import codemetrics as cm
import cm.git

project = cm.SvnProject('path/to/project')
log_df = cm.get_log(project).set_index(['revision', 'path'])
log_df.loc[:, ['added', 'removed']] = log_df.reset_index().\
                                         groupby('revision').\
                                         apply(cm.svn.get_diff_stats, chunks=False)Seemodule documentationfor more advanced functions or theexample notebookwhere codemetrics is applied to pandas.There is also anexample notebookrunning codemetrics on the pandas code base, and
theexample html exportof that notebook output (some features are missing like
the display of file names when hovering on the circles).LicenseLicensed under the term ofMIT License. See attached file LICENSE.txt.CreditsThis package was inspired byAdam Tornhill’s books.This package was created withCookiecutter.HistorySee CHANGELOG.md for later changes0.11.6  (2022-03-22)Added support for Python 3.100.11.5  (2021-07-24)Fixed handling of files with spaces (credit: @Wonshtrum).0.11.4  (2021-05-31)Now handles errors generated by git show (e.g. attempt to retrieve content for deleted file).0.11.3  (2021-01-30)Added cm.get_log function for concistency with the rest of the interface.0.11 (2021-01-16)Introduced GitProject and SvnProject to ease reference the tree, client and utility functions.0.10 (2020-12-12)Fixed handling of files with commas in the name.Fixed visualization of pandas example as html.Leveraged new pandas dtypes.Introduced type hints in code base.Switched backend to GitHub actions from travis-ci.0.9 (2019-09-29)Fixed incorrect usage of subprocess.run(). Seehttps://github.com/elmotec/codemetrics/issues/1.Factored common logic between git and svn. Bug fixes.Fixed test_core followinghttps://github.com/pandas-dev/pandas/pull/24748(Pandas 0.25.X)Added scriptcm_func_statsthat generates statistics on the function passed as argument.Added appveyor support for Windows.Documentation.Fixed retrieval of added and removed lines when there are spaces in a file name.Fixed indexed input inget_mass_changes.Fixed handling of removed files insvn.get_diff_stats.Fixed handling of branches insvn.get_diff_stats.Started changing interfaces to leverage apply and groupby.Added lines added/removed for Subversion.0.8 (2019-02-26)Addedsvn.get_diff_statsto retrieve line changes stats per diff.Integrated lizard to calculate average and function level cyclomatic complexity.0.7 (2019-01-09)Function oriented interface.Visualization via Vega, Altair.Documentation.0.5 (2018-05-12)First release on PyPI.MIT LicenseCopyright (c) 2012-2019 elmotecPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.