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

Expressive handler for fsspec block_size ValueError #142

Merged
merged 17 commits into from
Jun 10, 2021
Merged
Changes from 3 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
24 changes: 20 additions & 4 deletions pangeo_forge_recipes/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ def _copy_btw_filesystems(input_opener, output_opener, BLOCK_SIZE=10_000_000):
with input_opener as source:
with output_opener as target:
while True:
data = source.read(BLOCK_SIZE)
if not data:
break
target.write(data)
try:
data = source.read(BLOCK_SIZE)
if not data:
break
target.write(data)
except ValueError:
raise BlockSizeError()


class AbstractTarget(ABC):
Expand Down Expand Up @@ -209,3 +212,16 @@ 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 StorageError(Exception):
"""Base class for exceptions in this module."""

pass


class BlockSizeError(StorageError):
"""Error for source file servers that require {"block_size": 0}"""

def __str__(self):
return 'Try re-instantiating your recipe with fsspec_open_kwargs = {"block_size": 0}'