Skip to content

Commit

Permalink
enable component compilation via decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-mccarthy committed May 10, 2022
1 parent 4d81308 commit 1be8ea8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sdk/python/kfp/components/component_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# limitations under the License.

import functools
from typing import Callable, Optional, List
import warnings
from typing import Callable, List, Optional

from kfp.components import component_factory

Expand Down Expand Up @@ -97,8 +98,10 @@ def pipeline():
A component task factory that can be used in pipeline definitions.
"""
if output_component_file is not None:
raise Exception("output_component_file is not supported yet in v2 early"
"releases and will be added back for v2.0.0 ")
warnings.warn(
'output_component_file parameter is deprecated and will eventually be removed. Please use `Compiler().compile()` to compile a component instead.',
DeprecationWarning,
stacklevel=2)

if func is None:
return functools.partial(
Expand Down
21 changes: 21 additions & 0 deletions sdk/python/kfp/components/component_decorator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import tempfile
import unittest

from kfp.components import python_component
from kfp.components import structures
from kfp.components.component_decorator import component


Expand Down Expand Up @@ -75,3 +78,21 @@ def test_packages_to_install_with_custom_index_url(self):
self.assertTrue('numpy' in concat_command and
'tensorflow' in concat_command)
self.assertTrue('https://pypi.org/simple' in concat_command)

def test_output_component_file_parameter(self):
with tempfile.TemporaryDirectory() as tmpdir:
filepath = os.path.join(tmpdir, 'my_component.yaml')
with self.assertWarnsRegex(
DeprecationWarning,
r'output_component_file parameter is deprecated and will eventually be removed\.'
):
comp = component(func, output_component_file=filepath)

self.assertIsInstance(comp, python_component.PythonComponent)
self.assertTrue(os.path.exists(filepath))
with open(filepath, 'r') as f:
yaml_text = f.read()

component_spec = structures.ComponentSpec.load_from_component_yaml(
yaml_text)
self.assertEqual(component_spec, comp.component_spec)

0 comments on commit 1be8ea8

Please sign in to comment.