diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 436afb85..c44809f1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,14 @@ New Features ~~~~~~~~~~~~ - Added simulation config validation - Added a new commandline subcommand: ``validate-simulation`` +- Added an alias ``validate-circuit`` for the old ``validate`` subcommand + + - deprecated ``validate`` + + +Breaking Changes +~~~~~~~~~~~~~~~~ +- Deprecated the commandline subcommand ``validate`` in favor of new ``validate-circuit`` command Version v2.0.2 diff --git a/README.rst b/README.rst index a26c6233..2fedc88e 100644 --- a/README.rst +++ b/README.rst @@ -62,7 +62,7 @@ This functionality is provided by either the cli function: .. code-block:: shell - bluepysnap validate my/circuit/path/circuit_config.json + bluepysnap validate-circuit my/circuit/path/circuit_config.json Or a python free function: diff --git a/bluepysnap/cli.py b/bluepysnap/cli.py index c952071f..e77da4ad 100644 --- a/bluepysnap/cli.py +++ b/bluepysnap/cli.py @@ -1,9 +1,12 @@ """The project's command line launcher.""" +import functools import logging +import warnings import click from bluepysnap import circuit_validation, simulation_validation +from bluepysnap.utils import Deprecate CLICK_EXISTING_FILE = click.Path(exists=True, file_okay=True, dir_okay=False) @@ -20,18 +23,50 @@ def cli(verbose): ) +def circuit_validation_params(func): + """Small helper to have shared params.""" + + @click.argument("config_file", type=CLICK_EXISTING_FILE) + @click.option( + "--skip-slow/--no-skip-slow", + default=True, + help=( + "Skip slow checks; checking all edges refer to existing node ids, " + "edge indices are correct, etc" + ), + ) + @click.option("--only-errors", is_flag=True, help="Only print fatal errors (ignore warnings)") + @functools.wraps(func) + def wrapper(*args, **kwargs): + return func(*args, **kwargs) + + return wrapper + + @cli.command() -@click.argument("config_file", type=CLICK_EXISTING_FILE) -@click.option( - "--skip-slow/--no-skip-slow", - default=True, - help=( - "Skip slow checks; checking all edges refer to existing node ids, " - "edge indices are correct, etc" - ), -) -@click.option("--only-errors", is_flag=True, help="Only print fatal errors (ignore warnings)") +@circuit_validation_params def validate(config_file, skip_slow, only_errors): + """[DEPRECATED] Validate Sonata circuit based on config file. + + Args: + config_file (str): path to Sonata circuit config file + skip_slow (bool): skip slow tests + only_errors (bool): only print fatal errors + """ + with warnings.catch_warnings(): + # Making sure the warning is shown + warnings.simplefilter("always", DeprecationWarning) + Deprecate.warn( + "Calling circuit validation with 'validate' is deprecated. " + "Please use 'validate-circuit' instead." + ) + + circuit_validation.validate(config_file, skip_slow, only_errors) + + +@cli.command() +@circuit_validation_params +def validate_circuit(config_file, skip_slow, only_errors): """Validate Sonata circuit based on config file. Args: diff --git a/tests/test_cli.py b/tests/test_cli.py index c36d92d1..dc939351 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,9 +1,12 @@ +import warnings from unittest.mock import Mock, patch import click +import pytest from click.testing import CliRunner from bluepysnap.cli import cli +from bluepysnap.exceptions import BluepySnapDeprecationWarning from utils import TEST_DATA_DIR @@ -13,7 +16,13 @@ @patch("bluepysnap.schemas.validate_circuit_schema", Mock(return_value=[])) def test_cli_correct(): runner = CliRunner() - result = runner.invoke(cli, ["validate", str(TEST_DATA_DIR / "circuit_config.json")]) + + with pytest.warns( + BluepySnapDeprecationWarning, + match="Calling circuit validation with 'validate' is deprecated", + ): + result = runner.invoke(cli, ["validate", str(TEST_DATA_DIR / "circuit_config.json")]) + assert result.exit_code == 0 assert click.style("No Error: Success.", fg="green") in result.stdout @@ -25,9 +34,20 @@ def test_cli_no_config(): assert "Missing argument 'CONFIG_FILE'" in result.stdout +@patch("bluepysnap.schemas.validate_nodes_schema", Mock(return_value=[])) +@patch("bluepysnap.schemas.validate_edges_schema", Mock(return_value=[])) +@patch("bluepysnap.schemas.validate_circuit_schema", Mock(return_value=[])) +def test_cli_validate_circuit_correct(): + runner = CliRunner() + result = runner.invoke(cli, ["validate-circuit", str(TEST_DATA_DIR / "circuit_config.json")]) + assert result.exit_code == 0 + assert click.style("No Error: Success.", fg="green") in result.stdout + + def test_cli_validate_simulation_correct(): runner = CliRunner() result = runner.invoke( cli, ["validate-simulation", str(TEST_DATA_DIR / "simulation_config.json")] ) assert result.exit_code == 0 + assert click.style("No Error: Success.", fg="green") in result.stdout