Skip to content

Commit

Permalink
Add UnavailableDataset as a default dataset for lite mode (#2083)
Browse files Browse the repository at this point in the history
* sync remote

* fallback dataset for lite

* update file permissions

* update release note

* fix tests
  • Loading branch information
ravi-kumar-pilla authored Sep 10, 2024
1 parent d3fc51f commit c90e723
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 32 deletions.
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:

- Fixes design issues in metadata panel. (#2009)
- Fix missing run command in metadata panel for task nodes. (#2055)
- Add `UnavailableDataset` as a default dataset for `--lite` mode. (#2083)

# Release 9.2.0

Expand Down
2 changes: 1 addition & 1 deletion package/kedro_viz/api/rest/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class DataNodeMetadataAPIResponse(BaseAPIResponse):


class TranscodedDataNodeMetadataAPIReponse(BaseAPIResponse):
filepath: str
filepath: Optional[str] = None
original_type: str
transcoded_types: List[str]
run_command: Optional[str] = None
Expand Down
6 changes: 2 additions & 4 deletions package/kedro_viz/data_access/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import networkx as nx
from kedro.io import DataCatalog
from kedro.io.core import DatasetError
from kedro.io.memory_dataset import MemoryDataset
from kedro.pipeline import Pipeline as KedroPipeline
from kedro.pipeline.node import Node as KedroNode
from sqlalchemy.orm import sessionmaker

from kedro_viz.constants import DEFAULT_REGISTERED_PIPELINE_ID, ROOT_MODULAR_PIPELINE_ID
from kedro_viz.integrations.utils import UnavailableDataset
from kedro_viz.models.flowchart import (
DataNode,
GraphEdge,
Expand Down Expand Up @@ -325,9 +325,7 @@ def add_dataset(
# Kedro Viz in lite mode. The `get_dataset` function
# of DataCatalog calls AbstractDataset.from_config
# which tries to create a Dataset instance from the pattern

# pylint: disable=abstract-class-instantiated
obj = MemoryDataset() # type: ignore[abstract]
obj = UnavailableDataset()

layer = self.catalog.get_layer_for_dataset(dataset_name)
graph_node: Union[DataNode, TranscodedDataNode, ParametersNode]
Expand Down
9 changes: 4 additions & 5 deletions package/kedro_viz/integrations/kedro/data_catalog_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from kedro.io.core import AbstractDataset, DatasetError, generate_timestamp
from kedro.io.data_catalog import DataCatalog, _resolve_credentials
from kedro.io.memory_dataset import MemoryDataset

from kedro_viz.integrations.utils import UnavailableDataset


class DataCatalogLite(DataCatalog):
Expand Down Expand Up @@ -54,11 +55,9 @@ def from_config(
ds_name, ds_config, load_versions.get(ds_name), save_version
)
except DatasetError:
# pylint: disable=abstract-class-instantiated
datasets[ds_name] = MemoryDataset() # type: ignore[abstract]
datasets[ds_name] = UnavailableDataset()
except KeyError:
# pylint: disable=abstract-class-instantiated
datasets[ds_name] = MemoryDataset() # type: ignore[abstract]
datasets[ds_name] = UnavailableDataset()

sorted_patterns = cls._sort_patterns(dataset_patterns)
if sorted_patterns:
Expand Down
21 changes: 1 addition & 20 deletions package/kedro_viz/integrations/kedro/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,11 @@
from kedro_viz.constants import VIZ_METADATA_ARGS
from kedro_viz.integrations.kedro.data_catalog_lite import DataCatalogLite
from kedro_viz.integrations.kedro.lite_parser import LiteParser
from kedro_viz.integrations.utils import _VizNullPluginManager

logger = logging.getLogger(__name__)


class _VizNullPluginManager:
"""This class creates an empty ``hook_manager`` that will ignore all calls to hooks
and registered plugins allowing the runner to function if no ``hook_manager``
has been instantiated.
NOTE: _VizNullPluginManager is a clone of _NullPluginManager class in Kedro.
This was introduced to support the earliest version of Kedro which does not
have _NullPluginManager defined
"""

def __init__(self, *args, **kwargs):
pass

def __getattr__(self, name):
return self

def __call__(self, *args, **kwargs):
pass


def _get_dataset_stats(project_path: Path) -> Dict:
"""Return the stats saved at stats.json as a dictionary if found.
If not, return an empty dictionary
Expand Down
54 changes: 54 additions & 0 deletions package/kedro_viz/integrations/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""`kedro_viz.integrations.utils` provides utility functions and classes
to integrate Kedro-Viz with external data sources.
"""

from typing import Any, Union

from kedro.io.core import AbstractDataset

_EMPTY = object()


class _VizNullPluginManager: # pragma: no cover
"""This class creates an empty ``hook_manager`` that will ignore all calls to hooks
and registered plugins allowing the runner to function if no ``hook_manager``
has been instantiated.
NOTE: _VizNullPluginManager is a clone of _NullPluginManager class in Kedro.
This was introduced to support the earliest version of Kedro which does not
have _NullPluginManager defined
"""

def __init__(self, *args, **kwargs):
pass

def __getattr__(self, name):
return self

def __call__(self, *args, **kwargs):
pass


class UnavailableDataset(AbstractDataset): # pragma: no cover
"""This class is a custom dataset implementation for `Kedro Viz Lite`
when kedro-datasets are unavailable"""

def __init__(
self,
data: Any = _EMPTY,
metadata: Union[dict[str, Any], None] = None,
):
self._data = data
self.metadata = metadata

def load(self, *args, **kwargs):
pass

def save(self, *args, **kwargs):
pass

def _exists(self):
pass

def _describe(self) -> dict[str, Any]:
return {"data": self._data}
3 changes: 2 additions & 1 deletion package/tests/test_data_access/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from kedro_viz.data_access.repositories.modular_pipelines import (
ModularPipelinesRepository,
)
from kedro_viz.integrations.utils import UnavailableDataset
from kedro_viz.models.flowchart import (
DataNode,
GraphEdge,
Expand Down Expand Up @@ -381,7 +382,7 @@ def test_add_dataset_with_unresolved_pattern(
"my_pipeline", dataset_name, example_modular_pipelines_repo_obj
)

assert isinstance(dataset_obj.kedro_obj, MemoryDataset)
assert isinstance(dataset_obj.kedro_obj, UnavailableDataset)

def test_add_all_parameters(
self,
Expand Down
1 change: 1 addition & 0 deletions src/components/metadata/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ const MetaData = ({
<MetaDataRow
label="File Path:"
kind="path"
empty="N/A"
value={removeInitialSlash(metadata.filepath)}
/>
{hasTrackingData && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/metadata/metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ describe('MetaData', () => {
mockMetadata: nodeParameters,
});
const row = rowByLabel(wrapper, 'File Path:');
expect(textOf(rowValue(row))).toEqual(['-']);
expect(textOf(rowValue(row))).toEqual(['N/A']);
});

it('shows the first line (number of parameters) displayed in json viewer for parameter object', () => {
Expand Down

0 comments on commit c90e723

Please sign in to comment.