diff --git a/RELEASE.md b/RELEASE.md index 273e8db60d..408e98bd68 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -12,6 +12,7 @@ Please follow the established format: - Allow users to hide modular pipelines on the flowchart. (#1046) - Create URL parameters for each element/section in the flowchart. (#1138) +- Improve CLI loading time. (#1196) ## Bug fixes and other changes diff --git a/package/kedro_viz/constants.py b/package/kedro_viz/constants.py index 40832da3b8..b225702968 100644 --- a/package/kedro_viz/constants.py +++ b/package/kedro_viz/constants.py @@ -5,3 +5,6 @@ DEFAULT_REGISTERED_PIPELINE_ID = "__default__" KEDRO_VERSION = VersionInfo.parse(kedro.__version__) ROOT_MODULAR_PIPELINE_ID = "__root__" + +DEFAULT_HOST = "127.0.0.1" +DEFAULT_PORT = 4141 diff --git a/package/kedro_viz/launchers/cli.py b/package/kedro_viz/launchers/cli.py index de7594c0f9..d4aac428b3 100644 --- a/package/kedro_viz/launchers/cli.py +++ b/package/kedro_viz/launchers/cli.py @@ -11,8 +11,8 @@ from watchgod import RegExpWatcher, run_process from kedro_viz import __version__ +from kedro_viz.constants import DEFAULT_HOST, DEFAULT_PORT from kedro_viz.integrations.pypi import get_latest_version, is_running_outdated_version -from kedro_viz.server import DEFAULT_HOST, DEFAULT_PORT, is_localhost, run_server @click.group(name="Kedro-Viz") @@ -80,8 +80,11 @@ def commands(): # pylint: disable=missing-function-docstring help=PARAMS_ARG_HELP, callback=_split_params, ) +# pylint: disable=import-outside-toplevel, too-many-locals def viz(host, port, browser, load_file, save_file, pipeline, env, autoreload, params): """Visualise a Kedro pipeline using Kedro viz.""" + from kedro_viz.server import is_localhost, run_server + installed_version = VersionInfo.parse(__version__) latest_version = get_latest_version() diff --git a/package/kedro_viz/server.py b/package/kedro_viz/server.py index 4db1651f54..453027d3d6 100644 --- a/package/kedro_viz/server.py +++ b/package/kedro_viz/server.py @@ -11,13 +11,12 @@ from kedro_viz.api import apps from kedro_viz.api.rest.responses import EnhancedORJSONResponse, get_default_response +from kedro_viz.constants import DEFAULT_HOST, DEFAULT_PORT from kedro_viz.data_access import DataAccessManager, data_access_manager from kedro_viz.database import create_db_engine from kedro_viz.integrations.kedro import data_loader as kedro_data_loader from kedro_viz.models.experiment_tracking import Base -DEFAULT_HOST = "127.0.0.1" -DEFAULT_PORT = 4141 DEV_PORT = 4142 diff --git a/package/tests/test_launchers/test_cli.py b/package/tests/test_launchers/test_cli.py index 462898ad6a..acc3dd7adf 100644 --- a/package/tests/test_launchers/test_cli.py +++ b/package/tests/test_launchers/test_cli.py @@ -6,6 +6,7 @@ from kedro_viz import __version__ from kedro_viz.launchers import cli +from kedro_viz.server import run_server @pytest.mark.parametrize( @@ -57,7 +58,7 @@ ], ) def test_kedro_viz_command_run_server(command_options, run_server_args, mocker): - run_server = mocker.patch("kedro_viz.launchers.cli.run_server") + run_server = mocker.patch("kedro_viz.server.run_server") runner = CliRunner() with runner.isolated_filesystem(): runner.invoke(cli.commands, command_options) @@ -74,7 +75,7 @@ def test_kedro_viz_command_should_log_outdated_version(mocker, mock_http_respons ) mock_click_echo = mocker.patch("click.echo") - mocker.patch("kedro_viz.launchers.cli.run_server") + mocker.patch("kedro_viz.server.run_server") runner = CliRunner() with runner.isolated_filesystem(): runner.invoke(cli.commands, ["viz"]) @@ -96,7 +97,7 @@ def test_kedro_viz_command_should_not_log_latest_version(mocker, mock_http_respo ) mock_click_echo = mocker.patch("click.echo") - mocker.patch("kedro_viz.launchers.cli.run_server") + mocker.patch("kedro_viz.server.run_server") runner = CliRunner() with runner.isolated_filesystem(): runner.invoke(cli.commands, ["viz"]) @@ -109,7 +110,7 @@ def test_kedro_viz_command_should_not_log_if_pypi_is_down(mocker, mock_http_resp requests_get.side_effect = requests.exceptions.RequestException("PyPI is down") mock_click_echo = mocker.patch("click.echo") - mocker.patch("kedro_viz.launchers.cli.run_server") + mocker.patch("kedro_viz.server.run_server") runner = CliRunner() with runner.isolated_filesystem(): runner.invoke(cli.commands, ["viz"]) @@ -128,7 +129,7 @@ def test_kedro_viz_command_with_autoreload(mocker): run_process.assert_called_once_with( path=mock_project_path, - target=cli.run_server, + target=run_server, kwargs={ "host": "127.0.0.1", "port": 4141,