Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore optional cache target #118

Merged
merged 8 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading