A collection of code maintenance tools for Python projects, intended to be used within git hooks.
Project description
🪝 Gadzooks 🪝
A collection of code maintenance tools for Python projects. These are especially useful as pre-commit hooks.
Table of Contents
Installation
pip install py-gadzooks
Requires Python 3.9 or higher.
Usage
Once installed, gadzooks
will be available as a command-line executable.
Different tools can be called as subcommands, which are as follows:
Subcommand | Description |
---|---|
check-version |
Check version consistency |
loc-summarize |
Summarize lines of code |
To view the help and options for a particular subcommand, do:
gadzooks <SUBCOMMAND> --help
check-version
Versions may appear in multiple locations within a project, including:
- A source file such as
__init__.py
or__version__.py
- Git tag
- Locally built wheels
- Can be useful for ensuring you have remembered to build the latest version and publish it to PyPI
- An entry in a CHANGELOG file
This subcommand checks for consistency across these locations.
For now, a valid version string is required to be a sequence of three integers separated by .
, for example, 3.7.1
. In the future, the format of version strings will become more flexible.
A valid Git tag may be a version string, optionally prefixed with v
, for example, v3.7.1
.
Option | Description | Default |
---|---|---|
--pkg-name PKG_NAME |
Name of package | Current directory |
--version-path VERSION_PATH |
Path to file where package version is defined | <PKG_NAME>/__init__.py |
--check-tag |
Check that latest tag is valid | |
--check-dist |
Check version of latest built wheel | |
--dist-dir DIST_DIR |
Directory where wheels are built | dist |
--changelog CHANGELOG |
Changelog file | |
--changelog-version-regex |
Pattern to match to find version in changelog file ({version} within the pattern marks the target version) |
{version} |
loc-summarize
Computes various lines-of-code metrics such as LOC (lines of code), LLOC (logical lines of code), and SLOC (source lines of code). Uses the radon
tool to do this.
The input argument is a path or list of paths to look for Python source files.
Example:
gadzooks loc-summarize .
Output:
Checked 4 source file(s)
LINE STATS
----------
LOC: 244
LLOC: 198
SLOC: 182
Comments: 6
Single comments: 15
Multi: 10
Blank: 37
Pre-commit hooks
You can set up individual gadzooks
subcommands to run as pre-commit hooks by configuring your .pre-commit-config.yaml
file to point to this Github repo, specifying your desired subcommand by id
, along with the command-line arguments.
You should also set pass_filenames
to false
to avoid passing filenames as command-line arguments by default, and verbose
to true
so that gadzooks
output will be visible.
Here is an example of a section of a .pre-commit-config.yaml
file:
- repo: https://github.com/jeremander/gadzooks
rev: v0.2.0
hooks:
- id: loc-summarize
args: ['.']
pass_filenames: false
verbose: true
# before pushing, require the git tag match the package version
- id: check-version
args: ['--check-tag']
pass_filenames: false
verbose: true
stages: [push]
License
gadzooks
is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for py_gadzooks-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbbff2345a3116be523fb571dedf16a1f84be2bc3913e2c7112a7a8f5e84490f |
|
MD5 | cd1bef14432cd6d72633bc26b7a002c2 |
|
BLAKE2b-256 | ef87d027a57c40d59f7f2e91179c4e349e68ca20d9a6ca4698e0615710182955 |