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 bd30a66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
9 changes: 6 additions & 3 deletions tilecloud_chain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def __init__(
self.error_files_: dict[str, TextIO] = {}
self.functions_tiles: list[Callable[[Tile], Tile]] = []
self.functions_metatiles: list[Callable[[Tile], Tile]] = []
self.functions = self.functions_metatiles
self.functions: list[Callable[[Tile], Tile | None]] = self.functions_metatiles
self.metatilesplitter_thread_pool: ThreadPoolExecutor | None = None
self.multi_thread = multi_thread
self.maxconsecutive_errors = maxconsecutive_errors
Expand Down 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) -> str:
return f"Func: {self.func!r}"

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

def consume(self, test: int | None = None) -> None:
Expand Down
26 changes: 12 additions & 14 deletions tilecloud_chain/multitilestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ def _get_store(self, config_file: str, layer: str) -> TileStore | None:
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(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,9 +77,7 @@ 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)

Expand Down Expand Up @@ -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 bd30a66

Please sign in to comment.