-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breakdown flowchart models into separate files (#2144)
* imitial Signed-off-by: Sajid Alam <[email protected]> * update Signed-off-by: Sajid Alam <[email protected]> * split into modular pipelines Signed-off-by: Sajid Alam <[email protected]> * remove comment Signed-off-by: Sajid Alam <[email protected]> * move GraphNodeType to nodes Signed-off-by: Sajid Alam <[email protected]> * refactor Signed-off-by: Sajid Alam <[email protected]> * fix refactors Signed-off-by: Sajid Alam <[email protected]> * fix imports Signed-off-by: Sajid Alam <[email protected]> * resolve circular dependency Signed-off-by: Sajid Alam <[email protected]> * fix tests Signed-off-by: Sajid Alam <[email protected]> * lint Signed-off-by: Sajid Alam <[email protected]> * changes based on review Signed-off-by: Sajid Alam <[email protected]> * split flowchart test file Signed-off-by: Sajid Alam <[email protected]> * Update node_metadata.py Signed-off-by: Sajid Alam <[email protected]> * Update ruff.toml Signed-off-by: Sajid Alam <[email protected]> * lint Signed-off-by: Sajid Alam <[email protected]> * move test files Signed-off-by: Sajid Alam <[email protected]> * moved to named_entities.py Signed-off-by: Sajid Alam <[email protected]> --------- Signed-off-by: Sajid Alam <[email protected]>
- Loading branch information
1 parent
02ce770
commit 4db2bf9
Showing
24 changed files
with
855 additions
and
792 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""`kedro_viz.models.flowchart.edge` defines data models to represent Kedro edges in a viz graph.""" | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class GraphEdge(BaseModel, frozen=True): | ||
"""Represent an edge in the graph | ||
Args: | ||
source (str): The id of the source node. | ||
target (str): The id of the target node. | ||
""" | ||
|
||
source: str | ||
target: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""`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 | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def _parse_filepath(dataset_description: Dict[str, Any]) -> Optional[str]: | ||
""" | ||
Extract the file path from a dataset description dictionary. | ||
""" | ||
filepath = dataset_description.get("filepath") or dataset_description.get("path") | ||
return str(filepath) if filepath else None | ||
|
||
|
||
def _extract_wrapped_func(func: FunctionType) -> FunctionType: | ||
"""Extract a wrapped decorated function to inspect the source code if available. | ||
Adapted from https://stackoverflow.com/a/43506509/1684058 | ||
""" | ||
if func.__closure__ is None: | ||
return func | ||
closure = (c.cell_contents for c in func.__closure__) | ||
wrapped_func = next((c for c in closure if isinstance(c, FunctionType)), None) | ||
# return the original function if it's not a decorated function | ||
return func if wrapped_func is None else wrapped_func | ||
|
||
|
||
# ============================================================================= | ||
# Shared base classes and enumerations for model components | ||
# ============================================================================= | ||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""kedro_viz.models.flowchart.named_entities` defines data models for representing named entities | ||
such as tags and registered pipelines within a Kedro visualization graph.""" | ||
|
||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field, ValidationInfo, field_validator | ||
|
||
|
||
class NamedEntity(BaseModel): | ||
"""Represent a named entity (Tag/Registered Pipeline) in a Kedro project | ||
Args: | ||
id (str): Id of the registered pipeline | ||
Raises: | ||
AssertionError: If id is not supplied during instantiation | ||
""" | ||
|
||
id: str | ||
name: Optional[str] = Field( | ||
default=None, | ||
validate_default=True, | ||
description="The name of the entity", | ||
) | ||
|
||
@field_validator("name") | ||
@classmethod | ||
def set_name(cls, _, info: ValidationInfo): | ||
"""Ensures that the 'name' field is set to the value of 'id' if 'name' is not provided.""" | ||
assert "id" in info.data | ||
return info.data["id"] | ||
|
||
|
||
class RegisteredPipeline(NamedEntity): | ||
"""Represent a registered pipeline in a Kedro project.""" | ||
|
||
|
||
class Tag(NamedEntity): | ||
"""Represent a tag in a Kedro project.""" | ||
|
||
def __hash__(self) -> int: | ||
return hash(self.id) |
Oops, something went wrong.