Skip to content

Commit

Permalink
fix: pipelines objects can be named as {pipeline_name} instead of `…
Browse files Browse the repository at this point in the history
…pipeline` (#69)
  • Loading branch information
julesbertrand authored Oct 6, 2023
1 parent d8dab84 commit f79d081
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,23 @@ vertex
#### Pipelines

You file `{pipeline_name}.py` must contain a function called `pipeline` decorated using `kfp.dsl.pipeline`.

You file `{pipeline_name}.py` must contain a function called `{pipeline_name}` decorated using `kfp.dsl.pipeline`.
In previous versions, the functions / object used to be called `pipeline` but it was changed to `{pipeline_name}` to avoid confusion with the `kfp.dsl.pipeline` decorator.

```python
# vertex/pipelines/dummy_pipeline.py
import kfp.dsl

# New name to avoid confusion with the kfp.dsl.pipeline decorator
@kfp.dsl.pipeline()
def dummy_pipeline():
...

# Old name
@kfp.dsl.pipeline()
def pipeline():
...
```

#### Configs

Expand Down
2 changes: 1 addition & 1 deletion deployer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def check(
Checking that a pipeline is valid includes:
* Checking that the pipeline can be imported. It must be a valid python module with a
`pipeline` function decorated with `@kfp.dsl.pipeline`.
`{pipeline_name}` function decorated with `@kfp.dsl.pipeline`.
* Checking that the pipeline can be compiled using `kfp.compiler.Compiler`.
Expand Down
8 changes: 6 additions & 2 deletions deployer/pipeline_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ def populate_config_names(cls, data: Any) -> Any:
@computed_field
def pipeline(self) -> Any:
"""Import pipeline"""
with disable_logger("deployer.utils.utils"):
return import_pipeline_from_dir(PIPELINE_ROOT_PATH, self.pipeline_name.value)
if getattr(self, "_pipeline", None) is None:
with disable_logger("deployer.utils.utils"):
self._pipeline = import_pipeline_from_dir(
PIPELINE_ROOT_PATH, self.pipeline_name.value
)
return self._pipeline

@model_validator(mode="after")
def import_pipeline(self):
Expand Down
16 changes: 14 additions & 2 deletions deployer/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
import warnings
from enum import Enum
from pathlib import Path
from typing import Dict, Optional
Expand Down Expand Up @@ -40,11 +41,22 @@ def import_pipeline_from_dir(dirpath: Path, pipeline_name: str) -> graph_compone
) from e

try:
pipeline: Optional[graph_component.GraphComponent] = pipeline_module.pipeline
pipeline: Optional[graph_component.GraphComponent]
pipeline = getattr(pipeline_module, pipeline_name, None)
if pipeline is None:
pipeline = pipeline_module.pipeline
warnings.warn(
f"Pipeline in `{module_path}` is named `pipeline` instead of `{pipeline_name}`. "
"This is deprecated and will be removed in a future version. "
f"Please rename your pipeline to `{pipeline_name}`.",
FutureWarning,
stacklevel=1,
)
except AttributeError as e:
raise ImportError(
f"Pipeline {module_path}:pipeline not found. "
f"Pipeline object not found in `{module_path}`. "
"Please check that the pipeline is correctly defined and named."
f"It should be named `{pipeline_name}` or `pipeline` (deprecated)."
) from e

logger.debug(f"Pipeline {module_path} imported successfully.")
Expand Down
2 changes: 1 addition & 1 deletion example/vertex/pipelines/broken_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@


@kfp.dsl.pipeline(name="broken-pipeline")
def pipeline(name: str):
def broken_pipeline(name: str):
"""This pipeline is broken!"""
broken_component(name=name)
2 changes: 1 addition & 1 deletion example/vertex/pipelines/dummy_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@


@kfp.dsl.pipeline(name="dummy-pipeline")
def pipeline(name: str):
def dummy_pipeline(name: str):
"""This pipeline prints hello {name}"""
dummy_component(name=name)

0 comments on commit f79d081

Please sign in to comment.