-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support applying Lightweight Python components in Pipeline SDK (#770)
- Loading branch information
1 parent
410c3f6
commit abcd36f
Showing
13 changed files
with
360 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from .lightweight_component import Image, PythonComponent, lightweight_component # noqa | ||
from .pipeline import ( # noqa | ||
VALID_ACCELERATOR_TYPES, | ||
VALID_VERTEX_ACCELERATOR_TYPES, | ||
ComponentOp, | ||
Dataset, | ||
Pipeline, | ||
Resources, | ||
VALID_ACCELERATOR_TYPES, | ||
VALID_VERTEX_ACCELERATOR_TYPES, | ||
) |
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,42 @@ | ||
import typing as t | ||
from dataclasses import dataclass | ||
from functools import wraps | ||
|
||
|
||
@dataclass | ||
class Image: | ||
base_image: str = "fondant:latest" | ||
extra_requires: t.Optional[t.List[str]] = None | ||
script: t.Optional[str] = None | ||
|
||
|
||
class PythonComponent: | ||
@classmethod | ||
def image(cls) -> Image: | ||
raise NotImplementedError | ||
|
||
|
||
def lightweight_component( | ||
extra_requires: t.Optional[t.List[str]] = None, | ||
base_image: t.Optional[str] = None, | ||
): | ||
"""Decorator to enable a python component.""" | ||
|
||
def wrapper(cls): | ||
kwargs = {} | ||
if base_image: | ||
kwargs["base_image"] = base_image | ||
if extra_requires: | ||
kwargs["extra_requires"] = extra_requires | ||
image = Image(**kwargs) | ||
|
||
# updated=() is needed to prevent an attempt to update the class's __dict__ | ||
@wraps(cls, updated=()) | ||
class AppliedPythonComponent(cls, PythonComponent): | ||
@classmethod | ||
def image(cls) -> Image: | ||
return image | ||
|
||
return AppliedPythonComponent | ||
|
||
return wrapper |
Oops, something went wrong.