Skip to main content

SCM mining utility classes

Project description

PyPi version Python compatibility GitHub Workflow Python application AppVeyor main status Libraries.io dependency status for latest release Documentation Coverage Codacy

codemetrics

Mine your SCM for insight on your software. A work of love inspired by Adam 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 from cloc

  • For now, only Subversion and git are supported.

Installation

To install codemetrics, simply use pip:

pip install codemetrics

Usage

This 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)

See module documentation for more advanced functions or the example notebook where codemetrics is applied to pandas.

There is also an example notebook running codemetrics on the pandas code base, and the example html export of that notebook output (some features are missing like the display of file names when hovering on the circles).

License

Licensed under the term of MIT License. See attached file LICENSE.txt.

Credits

History

See CHANGELOG.md for later changes

0.11.6 (2022-03-22)

  • Added support for Python 3.10

0.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(). See https://github.com/elmotec/codemetrics/issues/1.

  • Factored common logic between git and svn. Bug fixes.

  • Fixed test_core following https://github.com/pandas-dev/pandas/pull/24748 (Pandas 0.25.X)

  • Added script cm_func_stats that 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 in get_mass_changes.

  • Fixed handling of removed files in svn.get_diff_stats.

  • Fixed handling of branches in svn.get_diff_stats.

  • Started changing interfaces to leverage apply and groupby.

  • Added lines added/removed for Subversion.

0.8 (2019-02-26)

  • Added svn.get_diff_stats to 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 License

Copyright (c) 2012-2019 elmotec

Permission 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codemetrics-0.11.7.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

codemetrics-0.11.7-py2.py3-none-any.whl (29.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file codemetrics-0.11.7.tar.gz.

File metadata

  • Download URL: codemetrics-0.11.7.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.4

File hashes

Hashes for codemetrics-0.11.7.tar.gz
Algorithm Hash digest
SHA256 6244f0df0c806408249ae1b4eff1b34b5330ad15d8e3ff88d60abc2b5a512c52
MD5 84f01ff1a5b0d0ca1c38deb1fb773642
BLAKE2b-256 33647428c6fa056a7df9481158c681c11b854f7c5aab4f6e125d2de0606c4b68

See more details on using hashes here.

File details

Details for the file codemetrics-0.11.7-py2.py3-none-any.whl.

File metadata

  • Download URL: codemetrics-0.11.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.4

File hashes

Hashes for codemetrics-0.11.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3200239b8eca8c6ab97650784fdb9ae9b41461ce489c30ce1ac9b27cdae163d7
MD5 25d3ae5ec6dda8fcad6013ec0d1b9ad7
BLAKE2b-256 b3a7d9f8ed729bac7e48630b6b336e3f0cf03fa15447cf47bdf07ae270c79659

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page