diff --git a/pangeo_forge_runner/commands/bake.py b/pangeo_forge_runner/commands/bake.py index 47b3238..3405013 100644 --- a/pangeo_forge_runner/commands/bake.py +++ b/pangeo_forge_runner/commands/bake.py @@ -208,11 +208,11 @@ def start(self): ), } - cache_target = input_cache_storage.get_forge_target(job_name=self.job_name) - if cache_target: + if not input_cache_storage.is_default(): + cache_target = input_cache_storage.get_forge_target( + job_name=self.job_name + ) injection_values |= {"INPUT_CACHE_STORAGE": cache_target} - print(injection_values) - print(injection_specs) feedstock = Feedstock( Path(checkout_dir) / self.feedstock_subdir, @@ -300,9 +300,7 @@ def start(self): ("cache", "metadata"), (input_cache_storage, metadata_cache_storage), ): - # `.root_path` is an empty string by default, so if the user has not setup this - # optional storage type in config, this block is skipped. - if optional_storage.root_path: + if not optional_storage.is_default(): setattr( recipe.storage_config, attrname, diff --git a/pangeo_forge_runner/storage.py b/pangeo_forge_runner/storage.py index b988497..aa17576 100644 --- a/pangeo_forge_runner/storage.py +++ b/pangeo_forge_runner/storage.py @@ -44,6 +44,15 @@ class StorageTargetConfig(LoggingConfigurable): """, ) + def is_default(self): + """ + Return if `root_path` is an empty string + + `.root_path` is an empty string by default. For optional storage targets, + this is used to mean it's unconfigured. + """ + return self.fsspec_class == AbstractFileSystem and not self.root_path + def get_forge_target(self, job_name: str): """ Return correct pangeo-forge-recipes Target diff --git a/tests/unit/test_bake.py b/tests/unit/test_bake.py index 464c652..5281b90 100644 --- a/tests/unit/test_bake.py +++ b/tests/unit/test_bake.py @@ -117,20 +117,27 @@ def recipes_version_ref(request): @pytest.mark.parametrize( - ("recipe_id", "expected_error", "custom_job_name"), + ("recipe_id", "expected_error", "custom_job_name", "no_input_cache"), ( - [None, None, None], - ["gpcp-from-gcs", None, None], + [None, None, None, False], + ["gpcp-from-gcs", None, None, False], [ "invalid_recipe_id", "ValueError: self.recipe_id='invalid_recipe_id' not in ['gpcp-from-gcs']", None, + False, ], - [None, None, "special-name-for-job"], + [None, None, "special-name-for-job", False], + [None, None, None, True], ), ) def test_gpcp_bake( - minio, recipe_id, expected_error, custom_job_name, recipes_version_ref + minio, + recipe_id, + expected_error, + custom_job_name, + no_input_cache, + recipes_version_ref, ): if recipes_version_ref == "0.9.x-dictobj" or ( recipes_version_ref == "0.10.x-dictobj" and recipe_id @@ -168,6 +175,12 @@ def test_gpcp_bake( }, } + if no_input_cache: + config["InputCacheStorage"] = { + "fsspec_class": "fsspec.AbstractFileSystem", + "fsspec_args": {}, + "root_path": "", + } if recipe_id: config["Bake"].update({"recipe_id": recipe_id}) if custom_job_name: @@ -195,7 +208,9 @@ def test_gpcp_bake( if expected_error: assert proc.returncode == 1 stdout[-1] == expected_error - + elif no_input_cache and recipes_version_ref == "0.9.x": + # no_input_cache is only supported in 0.10.x and above + assert proc.returncode == 1 else: assert proc.returncode == 0