diff --git a/RELEASE.md b/RELEASE.md index b1c8e9d0c9..2b2cc4118e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -11,6 +11,7 @@ Please follow the established format: - Fix a bug on metadata panel when preview data is unavailable. (#1794) - Update Compatibility/Support Matrix in README. (#1774) +- Update CLI command to support both `kedro viz run` and `kedro viz`. (#1790) # Release 8.0.0 diff --git a/package/kedro_viz/launchers/cli.py b/package/kedro_viz/launchers/cli.py index 10f3d74569..6582d238f4 100644 --- a/package/kedro_viz/launchers/cli.py +++ b/package/kedro_viz/launchers/cli.py @@ -6,6 +6,7 @@ from typing import Dict import click +from click_default_group import DefaultGroup from kedro.framework.cli.project import PARAMS_ARG_HELP from kedro.framework.cli.utils import KedroCliError, _split_params from packaging.version import parse @@ -41,13 +42,10 @@ def viz_cli(): # pylint: disable=missing-function-docstring pass -@viz_cli.group(invoke_without_command=True) +@viz_cli.group(cls=DefaultGroup, default="run", default_if_no_args=True) @click.pass_context -def viz(ctx): +def viz(ctx): # pylint: disable=unused-argument """Visualise a Kedro pipeline using Kedro viz.""" - if ctx.invoked_subcommand is None: - display_cli_message("\nDid you mean this ? \n kedro viz run \n\n", "yellow") - display_cli_message(f"{ctx.get_help()}") @viz.command(context_settings={"help_option_names": ["-h", "--help"]}) diff --git a/package/requirements.txt b/package/requirements.txt index 9dff93133d..0e5ef2e700 100644 --- a/package/requirements.txt +++ b/package/requirements.txt @@ -1,15 +1,16 @@ -packaging~=23.0 -kedro>=0.18.0 -ipython>=7.0.0, <9.0 +aiofiles>=22.1.0 +click-default-group fastapi>=0.100.0,<0.200.0 fsspec>=2021.4 -aiofiles>=22.1.0 -uvicorn[standard]~=0.27.1 -watchgod~=0.8.2 -plotly>=4.0 -pandas>=1.3 -sqlalchemy>=1.4, <3 -strawberry-graphql>=0.192.0, <1.0 +ipython>=7.0.0, <9.0 +kedro>=0.18.0 networkx>=2.5 orjson~=3.9 +packaging~=23.0 +pandas>=1.3 +plotly>=4.0 secure>=0.3.0 +sqlalchemy>=1.4, <3 +strawberry-graphql>=0.192.0, <1.0 +uvicorn[standard]~=0.27.1 +watchgod~=0.8.2 diff --git a/package/tests/test_launchers/test_cli.py b/package/tests/test_launchers/test_cli.py index cc6e60f5c1..2d6282780d 100755 --- a/package/tests/test_launchers/test_cli.py +++ b/package/tests/test_launchers/test_cli.py @@ -76,6 +76,20 @@ def mock_project_path(mocker): @pytest.mark.parametrize( "command_options,run_server_args", [ + ( + ["viz"], + { + "host": "127.0.0.1", + "port": 4141, + "load_file": None, + "save_file": None, + "pipeline_name": None, + "env": None, + "autoreload": False, + "ignore_plugins": False, + "extra_params": {}, + }, + ), ( ["viz", "run"], { @@ -279,22 +293,21 @@ def test_viz_command_group(mocker, mock_click_echo): runner = CliRunner() with runner.isolated_filesystem(): - runner.invoke(cli.viz_cli, ["viz"]) - - mock_click_echo_calls = [ - call("\x1b[33m\nDid you mean this ? \n kedro viz run \n\n\x1b[0m"), - call( - "Usage: Kedro-Viz viz [OPTIONS] COMMAND [ARGS]...\n\n " - "Visualise a Kedro pipeline using Kedro viz.\n\n" - "Options:\n --help Show this message and exit.\n\n" - "Commands:\n build Create build directory of local Kedro Viz " - "instance with Kedro...\n " - "deploy Deploy and host Kedro Viz on provided platform\n " - "run Launch local Kedro Viz instance\x1b[0m" - ), - ] - - mock_click_echo.assert_has_calls(mock_click_echo_calls) + result = runner.invoke(cli.viz_cli, ["viz", "--help"]) + + assert result.output == ( + "Usage: Kedro-Viz viz [OPTIONS] COMMAND [ARGS]...\n" + "\n" + " Visualise a Kedro pipeline using Kedro viz.\n" + "\n" + "Options:\n" + " --help Show this message and exit.\n" + "\n" + "Commands:\n" + " run* Launch local Kedro Viz instance\n" + " build Create build directory of local Kedro Viz instance with Kedro...\n" + " deploy Deploy and host Kedro Viz on provided platform\n" + ) @pytest.mark.parametrize(