Skip to content

Commit

Permalink
Merge pull request #118 from sbquinlan/fix/optionalStorage
Browse files Browse the repository at this point in the history
Restore optional cache target
  • Loading branch information
cisaacstern authored Nov 22, 2023
2 parents 809295a + 79fb5df commit 95ce6f4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
12 changes: 5 additions & 7 deletions pangeo_forge_runner/commands/bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions pangeo_forge_runner/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions tests/unit/test_bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 95ce6f4

Please sign in to comment.