From dbe62de981abbab891abd79caf09faf71feef7ee Mon Sep 17 00:00:00 2001 From: Yee Hing Tong Date: Thu, 28 Apr 2022 13:45:38 -0700 Subject: [PATCH 1/3] fixes Signed-off-by: Yee Hing Tong --- flytekit/configuration/__init__.py | 3 +++ tests/flytekit/unit/configuration/test_image_config.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/flytekit/configuration/__init__.py b/flytekit/configuration/__init__.py index ac3bd1de84..83386fed48 100644 --- a/flytekit/configuration/__init__.py +++ b/flytekit/configuration/__init__.py @@ -219,6 +219,8 @@ def validate_image(_: typing.Any, param: str, values: tuple) -> ImageConfig: @classmethod def create_from(cls, default_image: Image, other_images: typing.Optional[typing.List[Image]] = None) -> ImageConfig: + if not isinstance(default_image, Image): + raise ValueError(f"Default image should be of type Image not {type(default_image)}") all_images = [default_image] if default_image else [] if other_images: all_images.extend(other_images) @@ -263,6 +265,7 @@ def from_images(cls, default_image: str, m: typing.Optional[typing.Dict[str, str :return: """ + m = m or {} def_img = Image.look_up_image_info("default", default_image) if default_image else None other_images = [Image.look_up_image_info(k, tag=v, optional_tag=True) for k, v in m.items()] return cls.create_from(def_img, other_images) diff --git a/tests/flytekit/unit/configuration/test_image_config.py b/tests/flytekit/unit/configuration/test_image_config.py index cac8e55615..6371bae4f6 100644 --- a/tests/flytekit/unit/configuration/test_image_config.py +++ b/tests/flytekit/unit/configuration/test_image_config.py @@ -44,3 +44,11 @@ def test_not_version(mock_sys): # Python version 2 not in enum with pytest.raises(ValueError): DefaultImages.default_image() + + +def test_image_create(): + with pytest.raises(ValueError): + ImageConfig.create_from("ghcr.io/im/g:latest") + + ic = ImageConfig.from_images("ghcr.io/im/g:latest") + assert ic.default_image.fqn == "ghcr.io/im/g" From c34459c109102b6e0f1cbc9c8ea118009ebc227d Mon Sep 17 00:00:00 2001 From: Yee Hing Tong Date: Thu, 28 Apr 2022 13:55:46 -0700 Subject: [PATCH 2/3] add None type as acceptable input Signed-off-by: Yee Hing Tong --- flytekit/configuration/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/flytekit/configuration/__init__.py b/flytekit/configuration/__init__.py index 83386fed48..c72852fcd7 100644 --- a/flytekit/configuration/__init__.py +++ b/flytekit/configuration/__init__.py @@ -218,9 +218,11 @@ def validate_image(_: typing.Any, param: str, values: tuple) -> ImageConfig: return ImageConfig.create_from(default_image=default_image, other_images=images) @classmethod - def create_from(cls, default_image: Image, other_images: typing.Optional[typing.List[Image]] = None) -> ImageConfig: - if not isinstance(default_image, Image): - raise ValueError(f"Default image should be of type Image not {type(default_image)}") + def create_from( + cls, default_image: Optional[Image], other_images: typing.Optional[typing.List[Image]] = None + ) -> ImageConfig: + if default_image and not isinstance(default_image, Image): + raise ValueError(f"Default image should be of type Image or None not {type(default_image)}") all_images = [default_image] if default_image else [] if other_images: all_images.extend(other_images) From c1861960368756ee84c8d49f8893f1d2cd705988 Mon Sep 17 00:00:00 2001 From: Yee Hing Tong Date: Thu, 28 Apr 2022 14:07:45 -0700 Subject: [PATCH 3/3] nit Signed-off-by: Yee Hing Tong --- .github/workflows/upgrade_automation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upgrade_automation.yml b/.github/workflows/upgrade_automation.yml index 94fceadd27..e5f483eaef 100644 --- a/.github/workflows/upgrade_automation.yml +++ b/.github/workflows/upgrade_automation.yml @@ -9,4 +9,4 @@ jobs: with: component: boilerplate secrets: - FLYTE_BOT_PAT: ${{ secrets.FLYTE_BOT_PAT }} \ No newline at end of file + FLYTE_BOT_PAT: ${{ secrets.FLYTE_BOT_PAT }}