Skip to content

Commit

Permalink
Clarify names
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Dec 18, 2024
1 parent 9361726 commit 0c055af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
7 changes: 5 additions & 2 deletions tilecloud_chain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,16 +1367,19 @@ def imap(self, func: Any, time_message: str | None = None) -> None:
class Func:
"""Function with an additional field used to names it in timing messages."""

def __init__(self, func: Callable[[Tile], Tile], time_message: str | None) -> None:
def __init__(self, func: Callable[[Tile], Tile | None], time_message: str | None) -> None:
self.func = func
self.time_message = time_message

def __call__(self, tile: Tile) -> Tile:
def __call__(self, tile: Tile) -> Tile | None:
return self.func(tile)

def __str__(self) -> str:
return f"Func: {self.func}"

def __repr__(self):
return f"Func: {self.func!r}"

self.functions.append(Func(func, time_message))

def consume(self, test: int | None = None) -> None:
Expand Down
38 changes: 18 additions & 20 deletions tilecloud_chain/multitilestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,30 @@ class MultiTileStore(TileStore):
def __init__(self, get_store: Callable[[str, str], TileStore | None]) -> None:
"""Initialize."""
TileStore.__init__(self)
self.get_store = get_store
self._get_store = get_store
self.stores: dict[tuple[str, str], TileStore | None] = {}

def _get_store(self, config_file: str, layer: str) -> TileStore | None:
def _get_store_cache(self, config_file: str, layer: str) -> TileStore | None:
store = self.stores.get((config_file, layer))
if store is None:
store = self.get_store(config_file, layer)
store = self._get_store(config_file, layer)
self.stores[(config_file, layer)] = store
return store

def _get_store_tile(self, tile: Tile) -> TileStore | None:
"""Return the store corresponding to the tile."""
layer = tile.metadata["layer"]
config_file = tile.metadata["config_file"]
return self._get_store_cache(config_file, layer)

def __contains__(self, tile: Tile) -> bool:
"""
Return true if this store contains ``tile``.
Arguments:
tile: Tile
"""
layer = tile.metadata["layer"]
config_file = tile.metadata["config_file"]
store = self._get_store(config_file, layer)
store = self._get_store_tile(tile)
assert store is not None
return tile in store

Expand All @@ -45,9 +49,7 @@ def delete_one(self, tile: Tile) -> Tile:
Arguments:
tile: Tile
"""
layer = tile.metadata["layer"]
config_file = tile.metadata["config_file"]
store = self._get_store(config_file, layer)
store = self._get_store_tile(tile)
assert store is not None
return store.delete_one(tile)

Expand All @@ -64,9 +66,7 @@ def put_one(self, tile: Tile) -> Tile:
Arguments:
tile: Tile
"""
layer = tile.metadata["layer"]
config_file = tile.metadata["config_file"]
store = self._get_store(config_file, layer)
store = self._get_store_tile(tile)
assert store is not None
return store.put_one(tile)

Expand All @@ -77,17 +77,15 @@ def get_one(self, tile: Tile) -> Tile | None:
Arguments:
tile: Tile
"""
layer = tile.metadata["layer"]
config_file = tile.metadata["config_file"]
store = self._get_store(config_file, layer)
store = self._get_store_tile(tile)
assert store is not None
return store.get_one(tile)

def get(self, tiles: Iterable[Tile | None]) -> Iterator[Tile | None]:
"""See in superclass."""

def apply(key: tuple[str, str], tiles: Iterator[Tile]) -> Iterable[Tile | None]:
store = self._get_store(*key)
store = self._get_store_cache(*key)
if store is None:
return tiles
return store.get(tiles)
Expand All @@ -98,7 +96,7 @@ def put(self, tiles: Iterable[Tile]) -> Iterator[Tile]:
"""See in superclass."""

def apply(key: tuple[str, str], tiles: Iterator[Tile]) -> Iterator[Tile]:
store = self._get_store(*key)
store = self._get_store_cache(*key)
assert store is not None
return store.put(tiles)

Expand All @@ -108,7 +106,7 @@ def delete(self, tiles: Iterable[Tile]) -> Iterator[Tile]:
"""See in superclass."""

def apply(key: tuple[str, str], tiles: Iterator[Tile]) -> Iterator[Tile]:
store = self._get_store(*key)
store = self._get_store_cache(*key)
assert store is not None
return store.delete(tiles)

Expand All @@ -117,13 +115,13 @@ def apply(key: tuple[str, str], tiles: Iterator[Tile]) -> Iterator[Tile]:
def __str__(self) -> str:
"""Return a string representation of the object."""
stores = {str(store) for store in self.stores.values()}
keys = {f"{config_file}/{layer}" for config_file, layer in self.stores}
keys = {f"{config_file}:{layer}" for config_file, layer in self.stores}
return f"{self.__class__.__name__}({', '.join(stores)} - {', '.join(keys)})"

def __repr__(self) -> str:
"""Return a string representation of the object."""
stores = {repr(store) for store in self.stores.values()}
keys = {f"{config_file}/{layer}" for config_file, layer in self.stores}
keys = {f"{config_file}:{layer}" for config_file, layer in self.stores}
return f"{self.__class__.__name__}({', '.join(stores)} - {', '.join(keys)})"

@staticmethod
Expand Down

0 comments on commit 0c055af

Please sign in to comment.