Skip to content

Commit

Permalink
resolve circular dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Sajid Alam <[email protected]>
  • Loading branch information
SajidAlamQB committed Oct 25, 2024
1 parent dea5dca commit 4d09417
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
30 changes: 30 additions & 0 deletions package/kedro_viz/models/flowchart/model_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""`kedro_viz.models.flowchart.model_utils` defines utils for Kedro entities in a viz graph."""

import logging
from enum import Enum
from types import FunctionType
from typing import Any, Dict, Optional

Expand Down Expand Up @@ -38,6 +39,11 @@ def get_dataset_type(dataset: AbstractDataset) -> str:
return f"{dataset.__class__.__module__}.{dataset.__class__.__qualname__}"


# =============================================================================
# Shared base classes and enumerations for model components
# =============================================================================


class NamedEntity(BaseModel):
"""Represent a named entity (Tag/Registered Pipeline) in a Kedro project
Args:
Expand All @@ -59,3 +65,27 @@ class NamedEntity(BaseModel):
def set_name(cls, _, info: ValidationInfo):
assert "id" in info.data
return info.data["id"]


class GraphNodeType(str, Enum):
"""Represent all possible node types in the graph representation of a Kedro pipeline.
The type needs to inherit from str as well so FastAPI can serialise it. See:
https://fastapi.tiangolo.com/tutorial/path-params/#working-with-python-enumerations
"""

TASK = "task"
DATA = "data"
PARAMETERS = "parameters"
MODULAR_PIPELINE = "modularPipeline" # CamelCase for frontend compatibility


class ModularPipelineChild(BaseModel, frozen=True):
"""Represent a child of a modular pipeline.
Args:
id (str): Id of the modular pipeline child
type (GraphNodeType): Type of modular pipeline child
"""

id: str
type: GraphNodeType
16 changes: 1 addition & 15 deletions package/kedro_viz/models/flowchart/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
from abc import ABC
from enum import Enum
from typing import Any, Dict, Optional, Set, Union, cast

from fastapi.encoders import jsonable_encoder
Expand Down Expand Up @@ -31,24 +30,11 @@

from kedro_viz.utils import TRANSCODING_SEPARATOR, _strip_transcoding

from .model_utils import get_dataset_type
from .pipelines import ModularPipelineChild
from .model_utils import GraphNodeType, ModularPipelineChild, get_dataset_type

logger = logging.getLogger(__name__)


class GraphNodeType(str, Enum):
"""Represent all possible node types in the graph representation of a Kedro pipeline.
The type needs to inherit from str as well so FastAPI can serialise it. See:
https://fastapi.tiangolo.com/tutorial/path-params/#working-with-python-enumerations
"""

TASK = "task"
DATA = "data"
PARAMETERS = "parameters"
MODULAR_PIPELINE = "modularPipeline" # CamelCase for frontend compatibility


class GraphNode(BaseModel, ABC):
"""Represent a node in the graph representation of a Kedro pipeline.
All node models except the metadata node models should inherit from this class
Expand Down
15 changes: 1 addition & 14 deletions package/kedro_viz/models/flowchart/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,13 @@

from pydantic import BaseModel, Field

from .model_utils import NamedEntity
from .nodes import GraphNodeType
from .model_utils import GraphNodeType, ModularPipelineChild, NamedEntity


class RegisteredPipeline(NamedEntity):
"""Represent a registered pipeline in a Kedro project."""


class ModularPipelineChild(BaseModel, frozen=True):
"""Represent a child of a modular pipeline.
Args:
id (str): Id of the modular pipeline child
type (GraphNodeType): Type of modular pipeline child
"""

id: str
type: GraphNodeType


class ModularPipelineNode(BaseModel):
"""Represent a modular pipeline node in the graph."""

Expand Down

0 comments on commit 4d09417

Please sign in to comment.