remove unused Unitialized targets and errors
MODIFY
pangeo_forge_recipes/recipes/xarray_zarr.py
pangeo_forge_recipes/recipes/xarray_zarr.py
@@ -202,7 +202,7 @@ class XarrayZarrRecipe(BaseRecipe):
@closure
def prepare_target(self) -> None:
if self.target is None:
- raise ValueError("target has not been set.")
+ raise ValueError("target is not set.")
try:
ds = self.open_target()
logger.info("Found an existing dataset in target")
@@ -264,7 +264,7 @@ class XarrayZarrRecipe(BaseRecipe):
if self._cache_metadata:
if self.metadata_cache is None:
- raise ValueError("metadata_cache has not been set")
+ raise ValueError("metadata_cache is not set")
# if nitems_per_input is not constant, we need to cache this info
recipe_meta = {"input_sequence_lens": input_sequence_lens}
self.metadata_cache[_GLOBAL_METADATA_KEY] = recipe_meta
@@ -275,7 +275,7 @@ class XarrayZarrRecipe(BaseRecipe):
def cache_input(self, input_key: InputKey) -> None: # type: ignore
if self.cache_inputs:
if self.input_cache is None:
- raise ValueError("input_cache has not been set.")
+ raise ValueError("input_cache is not set.")
logger.info(f"Caching input '{input_key}'")
fname = self.file_pattern[input_key]
self.input_cache.cache_file(fname, **self.fsspec_open_kwargs)

MODIFY
pangeo_forge_recipes/storage.py
pangeo_forge_recipes/storage.py
@@ -209,32 +209,3 @@ def _slugify(value: str) -> str:
value = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
value = re.sub(r"[^.\w\s-]+", "_", value.lower())
return re.sub(r"[-\s]+", "-", value).strip("-_")
-
-
-class UninitializedTarget(AbstractTarget):
- def get_mapper(self):
- raise UninitializedTargetError
-
- def exists(self, path: str) -> bool:
- return False
-
- def rm(self, path: str) -> None:
- raise UninitializedTargetError
-
- def open(self, path: str, **kwargs): # don't know how to type hint this
- raise UninitializedTargetError
-
- def size(self, path: str, **kwargs):
- raise UninitializedTargetError
-
-
-class TargetError(Exception):
- """Base class for exceptions in this module."""
-
- pass
-
-
-class UninitializedTargetError(TargetError):
- """Operation on an uninitialized Target."""
-
- pass

MODIFY
tests/conftest.py
tests/conftest.py
@@ -23,12 +23,7 @@ from pangeo_forge_recipes.patterns import (
MergeDim,
pattern_from_file_sequence,
)
-from pangeo_forge_recipes.storage import (
- CacheFSSpecTarget,
- FSSpecTarget,
- MetadataTarget,
- UninitializedTarget,
-)
+from pangeo_forge_recipes.storage import CacheFSSpecTarget, FSSpecTarget, MetadataTarget
def pytest_addoption(parser):
@@ -185,11 +180,6 @@ def tmp_metadata_target(tmpdir_factory):
return cache
-@pytest.fixture()
-def uninitialized_target():
- return UninitializedTarget()
-
-
@pytest.fixture
def netCDFtoZarr_sequential_recipe(
daily_xarray_dataset, netcdf_local_paths, tmp_target, tmp_cache, tmp_metadata_target

MODIFY
tests/test_storage.py
tests/test_storage.py
import pytest
from pytest_lazyfixture import lazy_fixture
-from pangeo_forge_recipes.storage import UninitializedTargetError, file_opener
+from pangeo_forge_recipes.storage import file_opener
def test_target(tmp_target):
@@ -17,18 +17,6 @@ def test_target(tmp_target):
pass
-def test_uninitialized_target(uninitialized_target):
- target = uninitialized_target
- assert not target.exists("foo")
- with pytest.raises(UninitializedTargetError):
- target.get_mapper()
- with pytest.raises(UninitializedTargetError):
- target.rm("foo")
- with pytest.raises(UninitializedTargetError):
- with target.open("foo"):
- pass
-
-
def test_cache(tmp_cache):
assert not tmp_cache.exists("foo")
with tmp_cache.open("foo", mode="w") as f:

remove unused Unitialized targets and errors