Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS focussed CLI implementation for Shareable Viz #1661

Merged
merged 31 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
910709f
initial draft
ravi-kumar-pilla Nov 29, 2023
907125b
add unit tests
ravi-kumar-pilla Nov 30, 2023
4664dc0
adjust exception handlers
ravi-kumar-pilla Dec 1, 2023
f97fad1
Merge branch 'main' into feature/cli-share-viz
ravi-kumar-pilla Dec 4, 2023
95bacc0
test viz group initial draft
ravi-kumar-pilla Dec 5, 2023
94259cc
update viz group help text
ravi-kumar-pilla Dec 5, 2023
8e72d30
add pytest
ravi-kumar-pilla Dec 5, 2023
75b6e94
fix e2e tests
ravi-kumar-pilla Dec 5, 2023
0b8a984
Add new notes for upcoming release
MehdiNV Dec 6, 2023
754c6b7
Merge branch 'main' into chore/viz-group
MehdiNV Dec 6, 2023
aef34b2
merge 1616
ravi-kumar-pilla Dec 6, 2023
946188c
merge viz group and adjust deploy command
ravi-kumar-pilla Dec 6, 2023
901412f
Correct typo in RELEASE file
MehdiNV Dec 7, 2023
b4329d7
Remove redundant bullet point in RELEASE.md
MehdiNV Dec 7, 2023
a670026
Remove redundant command deploy from group
MehdiNV Dec 7, 2023
6356057
Adjust doc refs of 'kedro viz' to 'kedro viz run'
MehdiNV Dec 7, 2023
d754849
Update more doc references to 'kedro viz run'
MehdiNV Dec 7, 2023
1a5cf9e
remove custom command group class
ravi-kumar-pilla Dec 8, 2023
be329af
Merge branch 'chore/viz-group' of https://github.com/kedro-org/kedro-…
ravi-kumar-pilla Dec 9, 2023
6ff2e34
merge main
ravi-kumar-pilla Dec 11, 2023
08fd959
adjust test case
ravi-kumar-pilla Dec 11, 2023
86560b1
add release note
ravi-kumar-pilla Dec 11, 2023
d62cba4
update docs
ravi-kumar-pilla Dec 11, 2023
0b1be13
add timer message
ravi-kumar-pilla Dec 12, 2023
7a85113
add pytest for timer
ravi-kumar-pilla Dec 12, 2023
ae1b4e0
Merge branch 'main' into feature/cli-share-viz
ravi-kumar-pilla Dec 12, 2023
63d8c4a
Merge branch 'main' into feature/cli-share-viz
rashidakanchwala Dec 14, 2023
0a46ee7
Merge branch 'main' into feature/cli-share-viz
rashidakanchwala Dec 15, 2023
dbd7d16
Update docs/source/share_kedro_viz.md
rashidakanchwala Dec 15, 2023
d9a38c0
fix based on reviews
rashidakanchwala Dec 15, 2023
5f92476
typo in docs
rashidakanchwala Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ For **Python 3.6** users, the last supported version of Kedro-Viz is **3.16.0**
To launch Kedro-Viz from the command line as a Kedro plugin, use the following command from the root folder of your Kedro project:

```bash
kedro viz
kedro viz run
```

A browser tab opens automatically to serve the visualisation at `http://127.0.0.1:4141/`.

Kedro-Viz also supports the following additional arguments on the command line:

```bash
Usage: kedro viz [OPTIONS]
Usage: kedro viz run [OPTIONS]

Visualise a Kedro pipeline using Kedro-Viz.

Expand Down Expand Up @@ -183,7 +183,7 @@ const MyApp = () => <NoSSRKedro data={json} />;
The JSON can be obtained by running:

```bash
kedro viz --save-file=filename.json
kedro viz run --save-file=filename.json
```

We also recommend wrapping the `Kedro-Viz` component with a parent HTML/JSX element that has a specified height (as seen in the above example) in order for Kedro-Viz to be styled properly.
Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Please follow the established format:

- Fix for dataset existence check in factory pattern discovery (#1659)
- Remove support for Python 3.7 (#1660)
- Adjust CLI to use 'kedro viz run' instead of 'kedro viz' (#1671)

# Release 6.7.0

Expand Down
2 changes: 1 addition & 1 deletion demo-project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ This project is designed to be a realistic example of what Kedro looks like when
1. Run `pip install kedro~=0.18.0`
2. Run `pip install -r src/demo_project/requirements.in`
3. Run `kedro run`
4. Run `kedro viz`
4. Run `kedro viz run`
4 changes: 2 additions & 2 deletions docs/source/experiment_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Execute `kedro run` a few times in a row to generate a larger set of experiment
Here comes the fun part of accessing your run data on Kedro-Viz. Having generated some run data, execute the following command:

```bash
kedro viz
kedro viz run
```

When you open the Kedro-Viz web app, you see an experiment tracking icon on the left-hand side of the screen.
Expand Down Expand Up @@ -323,7 +323,7 @@ confusion_matrix:
versioned: true
```

After running the pipeline with `kedro run`, the plot is saved and you can see it in the experiment tracking panel when you execute `kedro viz`. Clicking on a plot expands it. When in comparison view, expanding a plot shows all the plots in that view for side-by-side comparison.
After running the pipeline with `kedro run`, the plot is saved and you can see it in the experiment tracking panel when you execute `kedro viz run`. Clicking on a plot expands it. When in comparison view, expanding a plot shows all the plots in that view for side-by-side comparison.

![](./images/experiment-tracking-plots-comparison.png)

Expand Down
12 changes: 6 additions & 6 deletions docs/source/kedro-viz_visualisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ kedro run
To start Kedro-Viz, type the following into your terminal from the project directory:

```bash
kedro viz
kedro viz run
```

```{important}
The `kedro viz` command will be deprecated with the release of Kedro-Viz 7.0.0.
`kedro viz run` will be the new way to run the tool.
The former `kedro viz` command used here is now deprecated with the release of Kedro-Viz 7.0.0.
`kedro viz run` is now the new way to run the tool.
```

The command opens a browser tab to serve the visualisation at `http://127.0.0.1:4141/`.
Expand All @@ -59,7 +59,7 @@ To exit the visualisation, close the browser tab. To regain control of the termi
You can use the `--autoreload` flag to autoreload Kedro-Viz when a `Python` or `YAML` file changes in the project. Add the flag to the command you use to start Kedro-Viz:

```bash
kedro viz --autoreload
kedro viz run --autoreload
```

![](./images/kedro_viz_autoreload.gif)
Expand Down Expand Up @@ -162,15 +162,15 @@ The visualisation now includes the layers:
You can share a pipeline structure within a Kedro-Viz visualisation as a JSON file from the terminal:

```bash
kedro viz --save-file=my_shareable_pipeline.json
kedro viz run --save-file=my_shareable_pipeline.json
```

This command will save a visualisation of the `__default__` pipeline as a JSON file called `my_shareable_pipeline.json`. It doesn't share data, such as that in the code panel, nor can you share images or charts.

To visualise the shared file, type the following to load it from the terminal:

```bash
kedro viz --load-file=my_shareable_pipeline.json
kedro viz run --load-file=my_shareable_pipeline.json
```

You can also share a complete project visualisation, described in more detail on [the following page](./share_kedro_viz).
2 changes: 1 addition & 1 deletion docs/source/preview_datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ shuttles:
After you've configured the Data Catalog, you can preview the datasets on Kedro-Viz. Start Kedro-Viz by running the following command in your terminal:

```bash
kedro viz
kedro viz run
```

The previews are shown as follows:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/share_kedro_viz.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ For more information, see the official AWS documentation about [how to work with
You're now ready to publish and share your Kedro-Viz project. Start Kedro-Viz by running the following command in your terminal:

```bash
kedro viz
kedro viz run
```

Click the **Publish and share** icon in the lower-left of the application. You will see a modal dialog to select your relevant AWS Bucket Region and enter your Bucket Name.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/visualise_charts_with_matplotlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def create_pipeline(**kwargs) -> Pipeline:

## Run the pipeline

Run the pipelines with `kedro run` and then visualise the result with `kedro viz`.
Run the pipelines with `kedro run` and then visualise the result with `kedro viz run`.

Click to see a small preview of the Matplotlib image in the metadata panel.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/visualise_charts_with_plotly.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Now run the pipelines:
kedro run
```

Then visualise with `kedro viz`
Then visualise with `kedro viz run`

The generated charts are shown as follows:

Expand Down
2 changes: 1 addition & 1 deletion package/features/steps/cli_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def install_kedro(context, version):
def exec_viz_command(context):
"""Execute Kedro-Viz command."""
context.result = ChildTerminatingPopen(
[context.kedro, "viz", "--no-browser"],
[context.kedro, "viz", "run", "--no-browser"],
env=context.env,
cwd=str(context.root_project_dir),
)
Expand Down
34 changes: 34 additions & 0 deletions package/kedro_viz/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,37 @@

DEFAULT_HOST = "127.0.0.1"
DEFAULT_PORT = 4141


AWS_REGIONS = [
"us-east-2",
"us-east-1",
"us-west-1",
"us-west-2",
"af-south-1",
"ap-east-1",
"ap-south-2",
"ap-southeast-3",
"ap-southeast-4",
"ap-south-1",
"ap-northeast-3",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ca-central-1",
"cn-north-1",
"cn-northwest-1",
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-south-1",
"eu-west-3",
"eu-north-1",
"eu-south-2",
"eu-central-2",
"sa-east-1",
"me-south-1",
"me-central-1",
"il-central-1",
]
99 changes: 86 additions & 13 deletions package/kedro_viz/launchers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,35 @@
from watchgod import RegExpWatcher, run_process

from kedro_viz import __version__
from kedro_viz.constants import DEFAULT_HOST, DEFAULT_PORT
from kedro_viz.constants import AWS_REGIONS, DEFAULT_HOST, DEFAULT_PORT
from kedro_viz.integrations.deployment.s3_deployer import S3Deployer
from kedro_viz.integrations.pypi import get_latest_version, is_running_outdated_version
from kedro_viz.launchers.utils import _check_viz_up, _start_browser, _wait_for
from kedro_viz.server import load_and_populate_data

_VIZ_PROCESSES: Dict[str, int] = {}


@click.group(name="Kedro-Viz")
def commands(): # pylint: disable=missing-function-docstring
def viz_cli(): # pylint: disable=missing-function-docstring
pass


@commands.command(context_settings={"help_option_names": ["-h", "--help"]})
@viz_cli.group(invoke_without_command=True)
@click.pass_context
def viz(ctx):
"""Visualise a Kedro pipeline using Kedro viz."""
if ctx.invoked_subcommand is None:
click.echo(
click.style(
"\nDid you mean this ? \n kedro viz run \n\n",
fg="yellow",
)
)
click.echo(click.style(f"{ctx.get_help()}"))


@viz.command(context_settings={"help_option_names": ["-h", "--help"]})
@click.option(
"--host",
default=DEFAULT_HOST,
Expand Down Expand Up @@ -89,7 +105,7 @@ def commands(): # pylint: disable=missing-function-docstring
callback=_split_params,
)
# pylint: disable=import-outside-toplevel, too-many-locals
def viz(
def run(
host,
port,
browser,
Expand All @@ -101,7 +117,7 @@ def viz(
ignore_plugins,
params,
):
"""Visualise a Kedro pipeline using Kedro viz."""
"""Launch local Kedro Viz instance"""
from kedro_viz.server import run_server

installed_version = parse(__version__)
Expand All @@ -119,14 +135,6 @@ def viz(
),
)

click.echo(
click.style(
"WARNING: The `kedro viz` command will be deprecated with the release of "
"Kedro-Viz 7.0.0. `kedro viz run` will be the new way to run the tool.",
fg="yellow",
),
)

try:
if port in _VIZ_PROCESSES and _VIZ_PROCESSES[port].is_alive():
_VIZ_PROCESSES[port].terminate()
Expand Down Expand Up @@ -187,3 +195,68 @@ def viz(
except Exception as ex: # pragma: no cover
traceback.print_exc()
raise KedroCliError(str(ex)) from ex


@viz.command(context_settings={"help_option_names": ["-h", "--help"]})
@click.option(
"--region",
type=str,
required=True,
help="AWS region where your S3 bucket is located",
)
@click.option(
"--bucket-name",
type=str,
required=True,
help="AWS S3 bucket name where Kedro Viz will be hosted",
)
def deploy(region, bucket_name):
"""Deploy and host Kedro Viz on AWS S3"""
if region not in AWS_REGIONS:
click.echo(
click.style(
"ERROR: Invalid AWS region. Please enter a valid AWS Region (eg., us-east-2).\n"
"Please find the complete list of available regions at :\n"
"https://docs.aws.amazon.com/AmazonRDS/latest"
"/UserGuide/Concepts.RegionsAndAvailabilityZones.html"
"#Concepts.RegionsAndAvailabilityZones.Regions",
fg="red",
),
)
return

try:
# Loads and populates data from underlying Kedro Project
load_and_populate_data(Path.cwd(), ignore_plugins=True)
ravi-kumar-pilla marked this conversation as resolved.
Show resolved Hide resolved

# Start the deployment
deployer = S3Deployer(region, bucket_name)
url = deployer.deploy_and_get_url()

click.echo(
click.style(
"\u2728 Success! Kedro Viz has been deployed on AWS S3. It can be accessed at :\n"
f"{url}",
fg="green",
),
)
except PermissionError: # pragma: no cover
click.echo(
click.style(
"PERMISSION ERROR: Deploying and hosting Kedro-Viz requires "
"AWS access keys, a valid AWS region and bucket name.\n"
"Please supply your AWS access keys as environment variables "
"and make sure the AWS region and bucket name are valid.\n"
"More information can be found at : "
"https://docs.kedro.org/en/stable/visualisation/share_kedro_viz.html",
fg="red",
)
)
# pylint: disable=broad-exception-caught
except Exception as exc: # pragma: no cover
click.echo(
click.style(
f"ERROR: Failed to deploy and host Kedro-Viz on AWS S3 : {exc} ",
fg="red",
)
)
40 changes: 26 additions & 14 deletions package/kedro_viz/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ def populate_data(
data_access_manager.add_pipelines(pipelines)


def load_and_populate_data(
path: Path,
env: Optional[str] = None,
ignore_plugins: bool = False,
extra_params: Optional[Dict[str, Any]] = None,
pipeline_name: Optional[str] = None,
):
"""Loads underlying Kedro project data and populates Kedro Viz Repositories"""

# Loads data from underlying Kedro Project
catalog, pipelines, session_store, stats_dict = kedro_data_loader.load_data(
path, env, ignore_plugins, extra_params
)

pipelines = (
pipelines
if pipeline_name is None
else {pipeline_name: pipelines[pipeline_name]}
)

# Creates data repositories which are used by Kedro Viz Backend APIs
populate_data(data_access_manager, catalog, pipelines, session_store, stats_dict)


def run_server(
host: str = DEFAULT_HOST,
port: int = DEFAULT_PORT,
Expand All @@ -58,7 +82,7 @@ def run_server(
autoreload: bool = False,
ignore_plugins: bool = False,
extra_params: Optional[Dict[str, Any]] = None,
): # pylint: disable=redefined-outer-name, too-many-locals
): # pylint: disable=redefined-outer-name
"""Run a uvicorn server with a FastAPI app that either launches API response data from a file
or from reading data from a real Kedro project.

Expand All @@ -83,19 +107,7 @@ def run_server(
path = Path(project_path) if project_path else Path.cwd()

if load_file is None:
# Loads data from underlying Kedro Project
catalog, pipelines, session_store, stats_dict = kedro_data_loader.load_data(
path, env, ignore_plugins, extra_params
)
pipelines = (
pipelines
if pipeline_name is None
else {pipeline_name: pipelines[pipeline_name]}
)
# Creates data repositories which are used by Kedro Viz Backend APIs
populate_data(
data_access_manager, catalog, pipelines, session_store, stats_dict
)
load_and_populate_data(path, env, ignore_plugins, extra_params, pipeline_name)

if save_file:
save_api_responses_to_fs(save_file)
Expand Down
2 changes: 1 addition & 1 deletion package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
package_data={"kedro_viz": list(files)},
zip_safe=False,
entry_points={
"kedro.global_commands": ["kedro-viz = kedro_viz.launchers.cli:commands"],
"kedro.global_commands": ["kedro-viz = kedro_viz.launchers.cli:viz_cli"],
"kedro.line_magic": ["line_magic = kedro_viz.launchers.jupyter:run_viz"],
"kedro.hooks": [
"kedro-dataset-stats = kedro_viz.integrations.kedro.hooks:dataset_stats_hook"
Expand Down
Loading