-- -- --- --- --- --- --- --- ------- ------- ------- |
# -*- coding: UTF-8 -*-
-- -- --- --- --- --- --- --- ------- ------- ------- |
"""Main command line."""
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
import click
-- -- --- --- --- --- --- --- ------- ------- ------- |
import traceback
-- -- --- --- --- --- --- --- ------- ------- ------- |
from pathlib import Path
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily import logger, __version__
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.archivers import resolve_archiver
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.cache import exists, get_default_metrics
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.config import DEFAULT_CONFIG_PATH, DEFAULT_GRID_STYLE
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.config import load as load_config
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.decorators import add_version
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.helper.custom_enums import ReportFormat
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.operators import resolve_operators
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.group()
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.version_option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
__version__, "-V", "--version", message="\U0001F98A %(prog)s, version %(version)s"
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--debug/--no-debug",
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=False,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Print debug information, used for development",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--config",
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=DEFAULT_CONFIG_PATH,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Path to configuration file, defaults to wily.cfg",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-p",
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--path",
-- -- --- --- --- --- --- --- ------- ------- ------- |
type=click.Path(resolve_path=True),
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=".",
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Root path to the project folder to scan",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-c",
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--cache",
-- -- --- --- --- --- --- --- ------- ------- ------- |
type=click.Path(resolve_path=True),
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Override the default cache path (defaults to $HOME/.wily/HASH)",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- -- --- --- --- --- --- --- ------- ------- ------- |
@add_version
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def cli(ctx, debug, config, path, cache):
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
\U0001F98A Inspect and search through the complexity of your source code.
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
To get started, run setup:
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
$ wily setup
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
To reindex any changes in your source code:
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
$ wily build <src>
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
Then explore basic metrics with:
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
$ wily report <file>
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
You can also graph specific metrics in a browser with:
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
$ wily graph <file> <metric>
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
ctx.ensure_object(dict)
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
ctx.obj["DEBUG"] = debug
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
if debug:
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.setLevel("DEBUG")
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
else:
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.setLevel("INFO")
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
ctx.obj["CONFIG"] = load_config(config)
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
if path:
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.debug(f"Fixing path to {path}")
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
ctx.obj["CONFIG"].path = path
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
if cache:
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.debug(f"Fixing cache to {cache}")
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
ctx.obj["CONFIG"].cache_path = cache
-- 04 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.debug(f"Loaded configuration from {config}")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@cli.command()
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-n",
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--max-revisions",
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=None,
-- -- --- --- --- --- --- --- ------- ------- ------- |
type=click.INT,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="The maximum number of historical commits to archive",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.argument("targets", type=click.Path(resolve_path=True), nargs=-1, required=False)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-o",
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--operators",
-- -- --- --- --- --- --- --- ------- ------- ------- |
type=click.STRING,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="List of operators, separated by commas",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-a",
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--archiver",
-- -- --- --- --- --- --- --- ------- ------- ------- |
type=click.STRING,
-- -- --- --- --- --- --- --- ------- ------- ------- |
default="git",
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Archiver to use, defaults to git if git repo, else filesystem",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def build(ctx, max_revisions, targets, operators, archiver):
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""Build the wily cache."""
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
config = ctx.obj["CONFIG"]
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
from wily.commands.build import build
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
if max_revisions:
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.debug(f"Fixing revisions to {max_revisions}")
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
config.max_revisions = max_revisions
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
if operators:
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.debug(f"Fixing operators to {operators}")
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
config.operators = operators.strip().split(",")
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
if archiver:
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.debug(f"Fixing archiver to {archiver}")
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
config.archiver = archiver
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
if targets:
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.debug(f"Fixing targets to {targets}")
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
config.targets = targets
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
build(
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
config=config,
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
archiver=resolve_archiver(config.archiver),
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
operators=resolve_operators(config.operators),
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
)
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.info(
-- 05 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"Completed building wily history, run `wily report <file>` or `wily index` to see more."
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@cli.command()
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option("--message/--no-message", default=False, help="Include revision message")
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
def index(ctx, message):
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
"""Show the history archive in the .wily/ folder."""
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
config = ctx.obj["CONFIG"]
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
if not exists(config):
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
handle_no_cache(ctx)
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
from wily.commands.index import index
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
index(config=config, include_message=message)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@cli.command()
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.argument("file", type=click.Path(resolve_path=False))
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.argument("metrics", nargs=-1, required=False)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option("-n", "--number", help="Number of items to show", type=click.INT)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option("--message/--no-message", default=False, help="Include revision message")
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-f",
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--format",
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=ReportFormat.CONSOLE.name,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Specify report format (console or html)",
-- -- --- --- --- --- --- --- ------- ------- ------- |
type=click.Choice(ReportFormat.get_all()),
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--console-format",
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=DEFAULT_GRID_STYLE,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Style for the console grid, see Tabulate Documentation for a list of styles.",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-o", "--output", help="Output report to specified HTML path, e.g. reports/out.html"
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
def report(ctx, file, metrics, number, message, format, console_format, output):
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
"""Show metrics for a given file."""
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
config = ctx.obj["CONFIG"]
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
if not exists(config):
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
handle_no_cache(ctx)
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
if not metrics:
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
metrics = get_default_metrics(config)
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
logger.info(f"Using default metrics {metrics}")
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
new_output = Path().cwd()
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
if output:
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
new_output = new_output / Path(output)
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
else:
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
new_output = new_output / "wily_report" / "index.html"
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
from wily.commands.report import report
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
logger.debug(f"Running report on {file} for metric {metrics}")
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
logger.debug(f"Output format is {format}")
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
report(
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
config=config,
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
path=file,
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
metrics=metrics,
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
n=number,
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
output=new_output,
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
include_message=message,
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
format=ReportFormat[format],
-- 04 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
console_format=console_format,
-- -- 002 007 005 008 009 013 0041.21 0047.10 0001.14 |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@cli.command()
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.argument("files", type=click.Path(resolve_path=False), nargs=-1, required=True)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--metrics",
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=None,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="comma-seperated list of metrics, see list-metrics for choices",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--all/--changes-only",
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=False,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Show all files, instead of changes only",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"--detail/--no-detail",
-- -- --- --- --- --- --- --- ------- ------- ------- |
default=True,
-- -- --- --- --- --- --- --- ------- ------- ------- |
help="Show function/class level metrics where available",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
def diff(ctx, files, metrics, all, detail):
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
"""Show the differences in metrics for each file."""
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
config = ctx.obj["CONFIG"]
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
if not exists(config):
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
handle_no_cache(ctx)
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
if not metrics:
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
metrics = get_default_metrics(config)
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
logger.info(f"Using default metrics {metrics}")
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
else:
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
metrics = metrics.split(",")
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
logger.info(f"Using specified metrics {metrics}")
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
from wily.commands.diff import diff
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
logger.debug(f"Running diff on {files} for metric {metrics}")
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
diff(
-- 03 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
config=config, files=files, metrics=metrics, changes_only=not all, detail=detail
-- -- 001 003 003 003 004 006 0012.00 0006.00 0000.50 |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@cli.command()
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.argument("path", type=click.Path(resolve_path=False))
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.argument("metrics", nargs=-2, required=True)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-o", "--output", help="Output report to specified HTML path, e.g. reports/out.html"
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option("-x", "--x-axis", help="Metric to use on x-axis, defaults to history.")
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option(
-- -- --- --- --- --- --- --- ------- ------- ------- |
"-a/-c", "--changes/--all", default=True, help="All commits or changes only"
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
def graph(ctx, path, metrics, output, x_axis, changes):
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
"""
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
Graph a specific metric for a given file, if a path is given, all files within path will be graphed.
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
Some common examples:
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
Graph all .py files within src/ for the raw.loc metric
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
$ wily graph src/ raw.loc
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
Graph test.py against raw.loc and cyclomatic.complexity metrics
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
$ wily graph src/test.py raw.loc cyclomatic.complexity
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
Graph test.py against raw.loc and raw.sloc on the x-axis
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
$ wily graph src/test.py raw.loc --x-axis raw.sloc
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
"""
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
config = ctx.obj["CONFIG"]
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
if not exists(config):
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
handle_no_cache(ctx)
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
from wily.commands.graph import graph
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
logger.debug(f"Running report on {path} for metrics {metrics}")
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
graph(
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
config=config,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
path=path,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
metrics=metrics,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
output=output,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
x_axis=x_axis,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
changes=changes,
-- -- 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@cli.command()
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.option("-y/-p", "--yes/--prompt", default=False, help="Skip prompt")
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
def clean(ctx, yes):
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
"""Clear the .wily/ folder."""
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
config = ctx.obj["CONFIG"]
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
if not exists(config):
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
logger.info("Wily cache does not exist, nothing to remove.")
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
exit(0)
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
if not yes:
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
p = input("Are you sure you want to delete wily cache? [y/N]")
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
if p.lower() != "y":
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
exit(0)
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
from wily.cache import clean
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
-- 04 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
clean(config)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@cli.command("list-metrics")
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
def list_metrics(ctx):
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
"""List the available metrics."""
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
config = ctx.obj["CONFIG"]
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
if not exists(config):
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
handle_no_cache(ctx)
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
from wily.commands.list_metrics import list_metrics
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
list_metrics()
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@cli.command("setup")
-- -- --- --- --- --- --- --- ------- ------- ------- |
@click.pass_context
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def setup(ctx):
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""Run a guided setup to build the wily cache."""
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
handle_no_cache(ctx)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def handle_no_cache(context):
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Handle lack-of-cache error, prompt user for index process."""
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
logger.error(
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
f"Could not locate wily cache, the cache is required to provide insights."
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
)
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
p = input("Do you want to run setup and index your project now? [y/N]")
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
if p.lower() != "y":
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
exit(1)
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
else:
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
revisions = input("How many previous git revisions do you want to index? : ")
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
revisions = int(revisions)
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
path = input("Path to your source files; comma-separated for multiple: ")
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
paths = path.split(",")
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
context.invoke(build, max_revisions=revisions, targets=paths, operators=None)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
if __name__ == "__main__":
-- -- --- --- --- --- --- --- ------- ------- ------- |
try:
-- -- --- --- --- --- --- --- ------- ------- ------- |
cli() # pragma: no cover
-- -- --- --- --- --- --- --- ------- ------- ------- |
except Exception as runtime:
-- -- --- --- --- --- --- --- ------- ------- ------- |
logger.error("Wily crashed!")
-- -- --- --- --- --- --- --- ------- ------- ------- |
logger.debug(traceback.format_exc())