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

Fix CI due to lazy-loading #1481

Merged
merged 10 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Please follow the established format:
- Fix incorrect rendering of datasets in modular pipelines. (#1439)
- Fix broken SVG/PNG exports in light theme. (#1463)
- Fix dataset and global toolbar error with standalone React component (#1351)
- Fix `ImportError` as kedro-datasets is now lazily loaded (#1481).

# Release 6.3.4

Expand Down
32 changes: 23 additions & 9 deletions package/kedro_viz/integrations/kedro/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
plotly,
tracking,
)
except ImportError:
except ImportError: # kedro_datasets is not installed.
from kedro.extras.datasets import ( # Safe since ImportErrors are suppressed within kedro.
json as json_dataset,
matplotlib,
Expand Down Expand Up @@ -158,12 +158,12 @@ def load_data(
return context.catalog, context.pipelines, session_store, stats_dict


# The dataset type is available as an attribute if and only if the import from kedro
# did not suppress an ImportError. i.e. hasattr(matplotlib, "MatplotlibWriter") is True
# when matplotlib dependencies are installed.
# Try to access the attribute to trigger the import of dependencies, only modify the _load
# if dependencies are installed.
# These datasets do not have _load methods defined (tracking and matplotlib) or do not
# load to json (plotly), hence the need to define _load here.
if hasattr(matplotlib, "MatplotlibWriter"):
try:
getattr(matplotlib, "MatplotlibWriter") # Trigger the lazy import

def matplotlib_writer_load(dataset: matplotlib.MatplotlibWriter) -> str:
load_path = get_filepath_str(dataset._get_load_path(), dataset._protocol)
Expand All @@ -172,15 +172,29 @@ def matplotlib_writer_load(dataset: matplotlib.MatplotlibWriter) -> str:
return base64_bytes.decode("utf-8")

matplotlib.MatplotlibWriter._load = matplotlib_writer_load
except (ImportError, AttributeError):
pass

if hasattr(plotly, "JSONDataSet"):
try:
getattr(plotly, "JSONDataSet") # Trigger import
plotly.JSONDataSet._load = json_dataset.JSONDataSet._load
except (ImportError, AttributeError):
pass

if hasattr(plotly, "PlotlyDataSet"):
try:
getattr(plotly, "PlotlyDataSet") # Trigger import
plotly.PlotlyDataSet._load = json_dataset.JSONDataSet._load
except (ImportError, AttributeError):
pass

if hasattr(tracking, "JSONDataSet"):
try:
getattr(tracking, "JSONDataSet") # Trigger import
tracking.JSONDataSet._load = json_dataset.JSONDataSet._load
except (ImportError, AttributeError):
pass

if hasattr(tracking, "MetricsDataSet"):
try:
getattr(tracking, "MetricsDataSet") # Trigger import
tracking.MetricsDataSet._load = json_dataset.JSONDataSet._load
except (ImportError, AttributeError):
pass
4 changes: 3 additions & 1 deletion package/kedro_viz/models/flowchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,9 @@ def __post_init__(self, data_node: DataNode, dataset_stats: Dict):
self.tracking_data = dataset.load()
elif data_node.is_preview_node():
try:
self.preview = dataset._preview(**data_node.get_preview_args())
if hasattr(dataset, "_preview"):
self.preview = dataset._preview(**data_node.get_preview_args())

except Exception as exc: # pylint: disable=broad-except # pragma: no cover
logger.warning(
"'%s' could not be previewed. Full exception: %s: %s",
Expand Down
Loading