Skip to content
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
8 changes: 4 additions & 4 deletions mapchete_eo/io/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from rasterio.vrt import WarpedVRT
from retry import retry

from mapchete_eo.io.path import COMMON_RASTER_EXTENSIONS, asset_mpath, cached_path
from mapchete_eo.io.path import COMMON_RASTER_EXTENSIONS, asset_mpath
from mapchete_eo.io.profiles import COGDeflateProfile

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -394,9 +394,9 @@ def should_be_converted(
return False


def _read_vector_mask(mask_path):
def _read_vector_mask(mask_path: MPath):
logger.debug("open %s with Fiona", mask_path)
with cached_path(mask_path) as cached:
with mask_path.local_copy() as cached:
try:
with fiona_open(cached) as src:
return list([dict(f) for f in src])
Expand Down Expand Up @@ -427,7 +427,7 @@ def read_mask_as_raster(
if dst_grid:
dst_grid = Grid.from_obj(dst_grid)
try:
with cached_path(path, active=cached_read) as path:
with path.local_copy(active=cached_read) as path:
if path.suffix in COMMON_RASTER_EXTENSIONS:
if dst_grid:
array = read_raster_window(
Expand Down
22 changes: 1 addition & 21 deletions mapchete_eo/io/path.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import hashlib
import logging
from contextlib import contextmanager
from enum import Enum
from tempfile import TemporaryDirectory
from typing import Generator, Tuple, Union
from typing import Tuple, Union
from xml.etree.ElementTree import Element, fromstring

import fsspec
import pystac
from mapchete.io import copy
from mapchete.path import MPath
from mapchete.settings import IORetrySettings
from retry import retry
Expand Down Expand Up @@ -107,23 +104,6 @@ def path_in_paths(path, existing_paths) -> bool:
return False


@contextmanager
@retry(logger=logger, **dict(IORetrySettings()))
def cached_path(path: MPath, active: bool = True) -> Generator[MPath, None, None]:
"""If path is remote, download to temporary directory and return path."""
if active and path.is_remote():
with TemporaryDirectory() as tempdir:
tempfile = MPath(tempdir) / path.name
logger.debug("%s is remote, download to %s", path, tempfile)
copy(
path,
tempfile,
)
yield tempfile
else:
yield path


def asset_mpath(
item: pystac.Item,
asset: Union[str, Tuple[str, ...]],
Expand Down
30 changes: 15 additions & 15 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading