def test_create_and_delete(tmpdir): """ Test that create() will create a folder with the correct path and then delete it. """ config = DEFAULT_CONFIG cache_path = pathlib.Path(tmpdir) / ".wily" config.cache_path = str(cache_path) assert not cache.exists(config) cache.create(config) assert cache.exists(config) cache.clean(config) assert not cache.exists(config)
def rank(ctx, path, metric, revision, limit, desc): """ Rank files, methods and functions in order of any metrics, e.g. complexity. Some common examples: Rank all .py files within src/ for the maintainability.mi metric $ wily rank src/ maintainability.mi Rank all .py files in the index for the default metrics across all archivers $ wily rank """ config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) from wily.commands.rank import rank logger.debug( f"Running rank on {path} for metric {metric} and revision {revision}") rank( config=config, path=path, metric=metric, revision_index=revision, limit=limit, descending=desc, )
def report(ctx, file, metrics, number, message, format, console_format, output): """Show metrics for a given file.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) if not metrics: metrics = get_default_metrics(config) logger.info(f"Using default metrics {metrics}") new_output = Path().cwd() if output: new_output = new_output / Path(output) else: new_output = new_output / "wily_report" / "index.html" from wily.commands.report import report logger.debug(f"Running report on {file} for metric {metrics}") logger.debug(f"Output format is {format}") report( config=config, path=file, metrics=metrics, n=number, output=new_output, include_message=message, format=ReportFormat[format], console_format=console_format, )
def diff(ctx, files, metrics, all, detail, revision): """Show the differences in metrics for each file.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) if not metrics: metrics = get_default_metrics(config) logger.info(f"Using default metrics {metrics}") else: metrics = metrics.split(",") logger.info(f"Using specified metrics {metrics}") from wily.commands.diff import diff logger.debug(f"Running diff on {files} for metric {metrics}") diff( config=config, files=files, metrics=metrics, changes_only=not all, detail=detail, revision=revision, )
def test_not_exists(): """ Test that exists() returns false if path does not exist """ config = DEFAULT_CONFIG config.cache_path = "/v/v/w" assert not cache.exists(config)
def graph(ctx, path, metrics, output, x_axis, changes): """ Graph a specific metric for a given file, if a path is given, all files within path will be graphed. Some common examples: Graph all .py files within src/ for the raw.loc metric $ wily graph src/ raw.loc Graph test.py against raw.loc and cyclomatic.complexity metrics $ wily graph src/test.py raw.loc cyclomatic.complexity Graph test.py against raw.loc and raw.sloc on the x-axis $ wily graph src/test.py raw.loc --x-axis raw.sloc """ config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) from wily.commands.graph import graph logger.debug(f"Running report on {path} for metrics {metrics}") graph( config=config, path=path, metrics=metrics, output=output, x_axis=x_axis, changes=changes, )
def test_exists(tmpdir): """ Test that exists() returns true if path does exist """ config = DEFAULT_CONFIG config.cache_path = tmpdir assert cache.exists(config)
def diff(ctx, files, metrics, all, detail, revision, format, output): """Show the differences in metrics for each file.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) if not metrics: metrics = get_default_metrics(config) logger.info(f"Using default metrics {metrics}") else: metrics = metrics.split(",") logger.info(f"Using specified metrics {metrics}") new_output = output if output is None else Path().cwd() / Path(output) from wily.commands.diff import diff logger.debug(f"Running diff on {files} for metric {metrics}") logger.debug(f"Output format is {format}") diff( config=config, files=files, metrics=metrics, changes_only=not all, detail=detail, output=new_output, revision=revision, format=ReportFormat[format], )
def ensure_exists(self): """Ensure that cache directory exists.""" if not cache.exists(self.config): logger.debug("Wily cache not found, creating.") cache.create(self.config) logger.debug("Created wily cache") else: logger.debug(f"Cache {self.config.cache_path} exists")
def test_clean_when_not_exists(tmpdir): """ Test that clean() will continue if the folder does not exist """ config = DEFAULT_CONFIG cache_path = pathlib.Path(tmpdir) / ".wily" config.cache_path = str(cache_path) assert not cache.exists(config) assert cache.clean(config) is None
def test_create_when_exists(tmpdir): """ Test that create() will continue if the folder already exists """ config = DEFAULT_CONFIG cache_path = pathlib.Path(tmpdir) / ".wily" pathlib.Path(cache_path).mkdir() config.cache_path = str(cache_path) assert cache.exists(config) assert str(cache.create(config)) == str(cache_path)
def index(ctx, message): """Show the history archive in the .wily/ folder.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) from wily.commands.index import index index(config=config, include_message=message)
def list_metrics(ctx): """List the available metrics.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) from wily.commands.list_metrics import list_metrics list_metrics()
def test_exists_older(tmpdir): """ Test that exists() returns true if path does exist and has a file with the version older than the current """ config = DEFAULT_CONFIG tmp_path = pathlib.Path(tmpdir) config.cache_path = tmp_path / ".wily" (tmp_path / ".wily").mkdir() with open((tmp_path / ".wily" / "index.json"), "w+") as index: index.write('{"version": "0.1.0"}') assert cache.exists(config)
def clean(ctx, yes): """Clear the .wily/ folder.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) if not yes: p = input("Are you sure you want to delete wily cache? [y/N]") if p.lower() != "y": exit(0) from wily.cache import clean clean(config)
def clean(ctx, yes): """Clear the .wily/ folder.""" config = ctx.obj["CONFIG"] if not exists(config): logger.info("Wily cache does not exist, nothing to remove.") exit(0) if not yes: p = input("Are you sure you want to delete wily cache? [y/N]") if p.lower() != "y": exit(0) from wily.cache import clean clean(config)
def graph(ctx, path, metrics, output, x_axis, changes): """Output report to specified HTML path, e.g. reports/out.html.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) from wily.commands.graph import graph logger.debug(f"Running report on {path} for metrics {metrics}") graph( config=config, path=path, metrics=metrics, output=output, x_axis=x_axis, changes=changes, )
def rank(ctx, path, metric, revision, limit, desc, threshold): """Rank files, methods and functions in order of any metrics, e.g. complexity.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) from wily.commands.rank import rank logger.debug(f"Running rank on {path} for metric {metric} and revision {revision}") rank( config=config, path=path, metric=metric, revision_index=revision, limit=limit, threshold=threshold, descending=desc, )
def report(ctx, file, metrics, number, message): """Show metrics for a given file.""" config = ctx.obj["CONFIG"] if not exists(config): handle_no_cache(ctx) if not metrics: metrics = get_default_metrics(config) logger.info(f"Using default metrics {metrics}") from wily.commands.report import report logger.debug(f"Running report on {file} for metric {metrics}") report(config=config, path=file, metrics=metrics, n=number, include_message=message)