A command-line application for tracking, reporting on complexity of Python tests and applications.
wily [a]:
quick to think of things, having a very good understanding of situations and possibilities,
and often willing to use tricks to achieve an aim.
Wily uses git to go through each revision (commit) in a branch and run complexity and code-analysis metrics over the code. You can use this to limit your code or report on trends for complexity, length etc.
Wily can be installed via pip from Python 3.10 and above:
$ pip install wilyAlternatively, Wily packages are available on conda-forge:
$ conda install -c conda-forge wilySee the Documentation Site for full usage guides.
Wily can be used via a command line interface, wily.
$ wily --helpHere is a demo of wily analysing a Python project, giving a summary of changes to complexity in the last 10 commits and then showing changes against a specific git revision:
Wily can be used in a CI/CD workflow to compare the complexity of the current files against a particular revision.
By default, wily will compare against the previous revision (for a git-pre-commit hook) but you can also give a Git ref, for example HEAD^1 is the commit before the HEAD reference.
$ wily build src/
$ wily diff src/ -r HEAD^1Or, to compare against
$ wily build src/
$ wily diff src/ -r masterYou can install wily as a pre-commit plugin by adding the following to .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: wily
name: wily
entry: wily diff
verbose: true
language: python
additional_dependencies: [wily]The first step to using wily is to build a wily cache with the statistics of your project.
Usage: wily build [OPTIONS] [TARGETS]...
Build the wily cache
Options:
-n, --max-revisions INTEGER The maximum number of historical commits to
archive
-o, --operators TEXT List of operators, separated by commas
-a, --archiver TEXT Archiver to use, defaults to git if git repo,
else filesystem
--help Show this message and exit.
By default, wily will assume your project folder is a git directory. Wily will not build a cache if the working copy is dirty (has changed files not committed).
$ wily build src/Limit the number of revisions (defaults to 50).
Show a specific metric for a given file, requires that .wily/ exists
wily report will print the metric and the delta between each revision.
Show the ranking for all files in a directory or a single file based on the metric provided, requires that .wily/ exists
wily rank will print a table of files and their metric values.
Similar to wily report but instead of printing in the console, wily will print a graph in a browser.
Show information about the build directory. Requires that .wily/ exists.
wily index will print the configuration to the screen and list all revisions that have been analysed and the operators used.
List the metrics available in the Wily operators. Each one of the metrics can be used in wily graph and wily report
$ wily list-metrics
cyclomatic operator:
complexity Cyclomatic Complexity (float, AimLow)
maintainability operator:
rank Maintainability Ranking (str, Informational)
mi Maintainability Index (float, AimHigh)
raw operator:
loc Lines of Code (int, Informational)
lloc L Lines of Code (int, AimLow)
sloc S Lines of Code (int, AimLow)
comments Multi-line comments (int, AimHigh)
multi Multi lines (int, Informational)
blank blank lines (int, Informational)
single_comments Single comment lines (int, Informational)
halstead operator:
h1 Unique Operators (int, AimLow)
h2 Unique Operands (int, AimLow)
N1 Number of Operators (int, AimLow)
N2 Number of Operands (int, AimLow)
vocabulary Unique vocabulary (int, AimLow)
length Length of application (int, AimLow)
volume Code volume (float, AimLow)
difficulty Difficulty (float, AimLow)
effort Effort (float, AimLow)
cognitive operator:
cognitive_complexity Cognitive Complexity (float, AimLow)You can put a wily.cfg file in your project directory and wily will override the runtime settings. Here are the available options:
[wily]
# list of operators, choose from cyclomatic, cognitive, maintainability, halstead and raw
operators = cyclomatic,raw
# archiver to use, defaults to git
archiver = git
# path to analyse, defaults to .
path = /path/to/target
# max revisions to archive, defaults to 50
max_revisions = 20
# override the default cache path
cache_path = /path/to/cache
# enable/disable scanning of Jupyter notebooks, defaults to true
include_ipynb = true
# enable/disable reporting on individual notebook cells, defaults to true
ipynb_cells = trueYou can also override the path to the configuration with the --config flag on the command-line.
Wily will detect and scan all Python code in .ipynb files automatically.
You can disable this behaviour if you require by setting include_ipynb = false in the configuration.
You can also disable the behaviour of reporting on individual cells by setting ipynb_cells = false.
- @wcooley (Wil Cooley)
- @DahlitzFlorian (Florian Dahlitz)
- @alegonz
- @DanielChabrowski
- @jwattier
- @skarzi
"cute animal doing dabbing" Designed by Freepik






