Skip to main content

Architect's collection of codebase health probes

Project description

PyPI - License Pipeline status Test code coverage PyPI

Wilt

Wilt is an architect’s collection of codebase health probes. The name of the package is inspired by the simplest possible code metric:

W Whitespace
I Integrated over
L Lines of
T Text

It comes from a great talk by Robert Smallshire called Confronting Complexity [1] [2]. In the talk there are a few other ideas for codebase health analysis and visualisation that inspire development of this package.

Install with:

pipx install Wilt

Code quality

Wilt

An implementation of WILT itself. The metric can be calculated like:

$ wilt cq.wilt /usr/lib/python3.12/unittest/case.py
2677.75

$ wilt cq.wilt '/usr/lib/python3.12/**/*.py'
346219.0

$ echo "    foo" | wilt cq.wilt -i 2 -
2.0

Continuous integration

REST HTTP API resource synchronisation

This feature allows synchronising collections of CI HTTP API resources in a SQLite database for analysis in SQL. The main use case is GitLab CI pipelines. Create a file called resmapfile.py like the following:

from wilt.resdb import resmap_api as rm


api = rm.Api(
    base_url='https://gitlab.com/api/v4/projects/4961127',
    default_headers={'PRIVATE-TOKEN': 'S3Cr3t'},
)

resources = [
    rm.Resmap(
        rm.SourceResourceCollection(
            '/jobs',
            request_params={'per_page': 100, 'sort': 'desc'},
            resource_id_key='id',
            resource_timestamp_key='created_at',
        ),
        rm.TargetTable(
            'job',
            extract_columns=[
                rm.ExtractColumn(
                    'id', rm.ColumnType.integer, name='job_id', pk=True
                ),
                rm.ExtractColumn('name', rm.ColumnType.text),
                rm.ExtractColumn('created_at', rm.ColumnType.datetime),
                rm.ExtractColumn('duration', rm.ColumnType.numeric),
                rm.ExtractColumn('status', rm.ColumnType.text),
                rm.ExtractColumn('pipeline.id', rm.ColumnType.integer),
            ],
        ),
        load_interval=rm.timedelta(days=2 * 365),
        sync_lookbehind=rm.timedelta(hours=6),
    ),
]

Then run wilt -v ci.rest sync-db to create and then synchronise a SQLite database with the HTTP API resources according to the mapping.

GitLab CI visualisation

Assuming the following pipeline synchronisation:

resources = [
    rm.Resmap(
        rm.SourceResourceCollection(
            '/pipelines',
            request_params={'per_page': 10, 'sort': 'desc'},
            page_size=10,
        ),
        rm.TargetTable(
            'pipeline_short',
            extract_columns=[
                rm.ExtractColumn(
                    'id', rm.ColumnType.integer, name='pipeline_short_id', pk=True
                ),
                rm.ExtractColumn('created_at', rm.ColumnType.datetime),
            ],
        ),
        subresources=[
            rm.SubResmap(
                rm.SourceSubresource('/pipelines/{id}', 'pipeline_id'),
                rm.TargetTable(
                    'pipeline',
                    extract_columns=[
                        rm.ExtractColumn(
                            'id', rm.ColumnType.integer, name='pipeline_id', pk=True
                        ),
                        rm.ExtractColumn('created_at', rm.ColumnType.datetime),
                        rm.ExtractColumn('duration', rm.ColumnType.numeric),
                        rm.ExtractColumn('ref', rm.ColumnType.text),
                    ],
                ),
            ),
        ],
    ),
]

the pipeline runtime can be visualised with a command like:

wilt ci.gitlab pipeline-runtime --clamp-max 3600 --after 2023-01-01T00:00:00

This produces plot.html file with interactive Plotly visualisation. See wilt ci.gitlab pipeline-runtime --help for more details.


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

Wilt-0.0.2.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Wilt-0.0.2-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file Wilt-0.0.2.tar.gz.

File metadata

  • Download URL: Wilt-0.0.2.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for Wilt-0.0.2.tar.gz
Algorithm Hash digest
SHA256 3fc455e155a1fd8c7e888ced0f5c45096ff3ab93d219d36eccc9dea1139e5b0f
MD5 8a97014808c487b1daf54b32a6634fd8
BLAKE2b-256 c9e5e22f03e228eb4076e745a0659f1d4e4c6ba19ad935ac18a73faa20bd24a6

See more details on using hashes here.

File details

Details for the file Wilt-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: Wilt-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for Wilt-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 720cd6467fc60084fb7d76714c5f8f014732b0019043a74a157a08d3844b6894
MD5 381180968ab6bd7d47d1196042209c6c
BLAKE2b-256 1feb17e5751a3f2ddd124f3aba41c45a07325f898429300eeba7470c1fdb1dba

See more details on using hashes here.

Supported by

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