Skip to content

Commit

Permalink
Kedro CLI startup time made shorter (#1196)
Browse files Browse the repository at this point in the history
- server.py: Moved `DEFAULT_HOST` and `DEFAULT_PORT` to `constants.py`
- launchers/cli.py: Moved `from kedro_viz.server ...` statement to
  viz function
- modified tests so they follow new code structure

Signed-off-by: Konrad Sikorski <znfgnu@gmail.com>

Signed-off-by: Konrad Sikorski <znfgnu@gmail.com>
  • Loading branch information
znfgnu authored Dec 16, 2022
1 parent e1c3a99 commit 29adc5e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions package/kedro_viz/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion package/kedro_viz/launchers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions package/kedro_viz/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 6 additions & 5 deletions package/tests/test_launchers/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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"])
Expand All @@ -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"])
Expand All @@ -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"])
Expand All @@ -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,
Expand Down

0 comments on commit 29adc5e

Please sign in to comment.