Skip to content

Commit

Permalink
feat(sdk): Add load_component_from_spec. Fixes #5708 #3748 (#6690)
Browse files Browse the repository at this point in the history
* add load_component_from_spec

* update release.md

* update RELEASE.md

* update RELEASE.md
  • Loading branch information
omarzouk authored Oct 28, 2021
1 parent 41275b4 commit 3e6c776
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions sdk/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
* Add v2 placeholder variables [\#6693](https://github.com/kubeflow/pipelines/pull/6693)
* Add a new command in KFP's CLI, `components`, that enables users to manage and build
v2 components in a container with Docker [\#6417](https://github.com/kubeflow/pipelines/pull/6417)
* Add `load_component_from_spec` for SDK v1 which brings back the ability to build components directly in python, using `ComponentSpec` [\#6690](https://github.com/kubeflow/pipelines/pull/6690)

## Breaking Changes

Expand Down
21 changes: 20 additions & 1 deletion sdk/python/kfp/components/_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
_default_component_name = 'Component'


def load_component(filename=None, url=None, text=None):
def load_component(filename=None, url=None, text=None, component_spec=None):
"""Loads component from text, file or URL and creates a task factory
function.
Expand All @@ -43,6 +43,7 @@ def load_component(filename=None, url=None, text=None):
filename: Path of local file containing the component definition.
url: The URL of the component file data.
text: A string containing the component file data.
component_spec: A ComponentSpec containing the component definition.
Returns:
A factory function with a strongly-typed signature.
Expand All @@ -61,6 +62,8 @@ def load_component(filename=None, url=None, text=None):
return load_component_from_url(url)
elif text:
return load_component_from_text(text)
elif component_spec:
return load_component_from_spec(component_spec)
else:
raise ValueError('Need to specify a source')

Expand Down Expand Up @@ -120,6 +123,22 @@ def load_component_from_text(text):
component_spec=component_spec)


def load_component_from_spec(component_spec):
"""Loads component from a ComponentSpec and creates a task factory function.
Args:
component_spec: A ComponentSpec containing the component definition.
Returns:
A factory function with a strongly-typed signature.
Once called with the required arguments, the factory constructs a pipeline task instance (ContainerOp).
"""
if component_spec is None:
raise TypeError
return _create_task_factory_from_component_spec(
component_spec=component_spec)


def _fix_component_uri(uri: str) -> str:
#Handling Google Cloud Storage URIs
if uri.startswith('gs://'):
Expand Down

0 comments on commit 3e6c776

Please sign in to comment.