git-code-debt
A dashboard for monitoring code debt in a git repository.
Installation
pip install git-code-debt
Usage
Basic / tl;dr Usage
make a generate_config.yaml
# required: repository to clone (can be anything `git clone` understands) even
# a repository already on disk
repo: git@github.com:asottile/git-code-debt
# required: database generation path
database: database.db
# optional: default False
skip_default_metrics: false
# optional: default []
metric_package_names: []
# optional: default ^$ (python regex) to exclude paths such as '^vendor/'
exclude: ^$
invoke the cli
# Generate code metric data (substitute your own repo path)
$ git-code-debt-generate
# Start the server
$ git-code-debt-server database.db
Updating data on an existing database
Adding data to the database is as simple as running generate again.
git-code-debt will pick up in the git history from where data was generated
previously.
$ git-code-debt-generate
Creating your own metrics
- Create a python project which adds
git-code-debtas a dependency. - Create a package where you'll write your metrics
- Add your package to
metric_package_namesin yourgenerate_config.yaml
The simplest way to write your own custom metrics is to extend
git_code_debt.metrics.base.SimpleLineCounterBase.
Here's what the base class looks like
class SimpleLineCounterBase(DiffParserBase):
# ...
def should_include_file(self, file_diff_stat: FileDiffStat) -> bool:
"""Implement me to return whether a filename should be included.
By default, this returns True.
:param FileDiffStat file_diff_stat:
"""
return True
def line_matches_metric(self, line: bytes, file_diff_stat: FileDiffStat) -> bool:
"""Implement me to return whether a line matches the metric.
:param bytes line: Line in the file
:param FileDiffStat file_diff_stat:
"""
raise NotImplementedError
Here's an example metric
from git_code_debt.metrics.base import SimpleLineCounterBase
class Python__init__LineCount(SimpleLineCounterBase):
"""Counts the number of lines in __init__.py"""
def should_include_file(self, file_diff_stat: FileDiffStat) -> bool:
return file_diff_stat.filename == b'__init__.py'
def line_matches_metric(self, line: bytes, file_diff_stat -> FileDiffStat) -> bool:
# All lines in __init__.py match
return True
An additional class is provided which feeds lines as text
(SimpleLineCounterBase presents them as bytes): TextLineCounterBase.
Here is an example metric using that base class:
from git_code_debt.metrics.base import TextLineCounterBase
class XXXLineCount(TextLineCounterBase):
"""Counts the number of lines which are XXX comments"""
def text_line_matches_metric(self, line: str, file_diff_stat: FileDiffStat) -> bool:
return '# XXX' in line
More complex metrics can extend DiffParserBase
class DiffParserBase(object):
# Specify __metric__ = False to not be included (useful for base classes)
__metric__ = False
def get_metrics_from_stat(self, commit: Commit, file_diff_stats: Tuple[FileDiffStat, ...]) -> bool:
"""Implement me to yield Metric objects from the input list of
FileStat objects.
Args:
commit - Commit object
file_diff_stats - list of FileDiffStat objects
Returns:
generator of Metric objects
"""
raise NotImplementedError
def get_metrics_info(self) -> List[MetricInfo]:
"""Implement me to yield `MetricInfo` objects."""
raise NotImplementedError
Some screenshots
Index
Graph
Metadata
Release files for git-code-debt 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| git_code_debt-1.2.0.tar.gz | 56.0 kB | Without provenance | Details for git_code_debt-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| git_code_debt-1.2.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for git_code_debt-1.2.0-py2.py3-none-any.whl |
Total release size: 126.1 kB
Release files / git_code_debt-1.2.0.tar.gz
| Download URL | git_code_debt-1.2.0.tar.gz |
|---|---|
| Size | 56.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c11caf38468960a1b71c13b90058a14a8614786d7a19d56cf1a6b1b580aff2fa
|
|
BLAKE2b-256 checksum How to use checksums |
5714f12ee2a994bc5035596527582fa03fdba084f01c74cf9e55ee655f81ea77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / git_code_debt-1.2.0-py2.py3-none-any.whl
| Download URL | git_code_debt-1.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 70.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
af295bd69f33fb6000549af0daae32cef5b2953831dafedf0ae92166712a0cdc
|
|
BLAKE2b-256 checksum How to use checksums |
a47ccdc68a30e0916875350d4bfaf642436aee7ae62a341f51f64fddaa9d40f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for git-code-debt 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.