Skip to content

Commit 3cbd545

Browse files
Patch/update rio tiler req (#247)
* fix type hints and update rio-tiler requirements * update changelog
1 parent 0c0b0e5 commit 3cbd545

File tree

10 files changed

+739
-677
lines changed

10 files changed

+739
-677
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Unreleased
22

3+
## 9.1.0 (2026-02-02)
4+
5+
* update: rio-tiler requirements
6+
* update: type hints
7+
38
## 9.0.2 (2025-12-15)
49

510
* add support for python 3.14

cogeo_mosaic/backends/base.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import abc
44
import itertools
55
import warnings
6+
from collections.abc import Sequence
67
from threading import Lock
7-
from typing import Any, Dict, List, Optional, Sequence, Type, Union
8+
from typing import Any
89

910
import attr
1011
from cachetools import TTLCache, cached
@@ -25,7 +26,7 @@
2526
from cogeo_mosaic.utils import bbox_union
2627

2728

28-
def _convert_to_mosaicjson(value: Union[Dict, MosaicJSON]):
29+
def _convert_to_mosaicjson(value: dict | MosaicJSON):
2930
if value is not None:
3031
return MosaicJSON(**dict(value))
3132

@@ -55,18 +56,16 @@ class MosaicJSONBackend(BaseBackend):
5556
minzoom: int = attr.ib(default=None)
5657
maxzoom: int = attr.ib(default=None)
5758

58-
reader: Union[
59-
Type[BaseReader],
60-
Type[MultiBaseReader],
61-
Type[MultiBandReader],
62-
] = attr.ib(default=Reader)
63-
reader_options: Dict = attr.ib(factory=dict)
59+
reader: type[BaseReader] | type[MultiBaseReader] | type[MultiBandReader] = attr.ib(
60+
default=Reader
61+
)
62+
reader_options: dict = attr.ib(factory=dict)
6463

6564
bounds: BBox = attr.ib(init=False)
6665
crs: CRS = attr.ib(init=False)
6766

6867
_backend_name: str
69-
_file_byte_size: Optional[int] = 0
68+
_file_byte_size: int | None = 0
7069

7170
def __attrs_post_init__(self):
7271
"""Post Init: if not passed in init, try to read from self.input."""
@@ -103,7 +102,7 @@ def write(self, overwrite: bool = True):
103102

104103
def update(
105104
self,
106-
features: Sequence[Dict],
105+
features: Sequence[dict],
107106
add_first: bool = True,
108107
quiet: bool = False,
109108
**kwargs,
@@ -146,7 +145,7 @@ def update(
146145
self.bounds = bounds
147146
self.write(overwrite=True)
148147

149-
def assets_for_tile(self, x: int, y: int, z: int, **kwargs: Any) -> List[str]:
148+
def assets_for_tile(self, x: int, y: int, z: int, **kwargs: Any) -> list[str]:
150149
"""Retrieve assets for tile."""
151150
mosaic_tms = self.mosaic_def.tilematrixset or WEB_MERCATOR_TMS
152151
if self.tms == mosaic_tms:
@@ -168,9 +167,9 @@ def assets_for_point(
168167
self,
169168
lng: float,
170169
lat: float,
171-
coord_crs: Optional[CRS] = None,
170+
coord_crs: CRS | None = None,
172171
**kwargs: Any,
173-
) -> List[str]:
172+
) -> list[str]:
174173
"""Retrieve assets for point."""
175174
mosaic_tms = self.mosaic_def.tilematrixset or WEB_MERCATOR_TMS
176175

@@ -196,9 +195,9 @@ def assets_for_bbox(
196195
ymin: float,
197196
xmax: float,
198197
ymax: float,
199-
coord_crs: Optional[CRS] = None,
198+
coord_crs: CRS | None = None,
200199
**kwargs,
201-
) -> List[str]:
200+
) -> list[str]:
202201
"""Retrieve assets for bbox."""
203202
mosaic_tms = self.mosaic_def.tilematrixset or WEB_MERCATOR_TMS
204203

@@ -241,7 +240,7 @@ def assets_for_bbox(
241240
),
242241
lock=Lock(),
243242
)
244-
def get_assets(self, x: int, y: int, z: int, reverse: bool = False) -> List[str]:
243+
def get_assets(self, x: int, y: int, z: int, reverse: bool = False) -> list[str]:
245244
"""Find assets."""
246245
quadkeys = self.find_quadkeys(Tile(x=x, y=y, z=z), self.quadkey_zoom)
247246
assets = list(
@@ -259,7 +258,7 @@ def get_assets(self, x: int, y: int, z: int, reverse: bool = False) -> List[str]
259258

260259
return assets
261260

262-
def find_quadkeys(self, tile: Tile, quadkey_zoom: int) -> List[str]:
261+
def find_quadkeys(self, tile: Tile, quadkey_zoom: int) -> list[str]:
263262
"""
264263
Find quadkeys at desired zoom for tile
265264
@@ -273,7 +272,7 @@ def find_quadkeys(self, tile: Tile, quadkey_zoom: int) -> List[str]:
273272
Returns
274273
-------
275274
list
276-
List[str] of quadkeys
275+
list[str] of quadkeys
277276
278277
"""
279278
mosaic_tms = self.mosaic_def.tilematrixset or WEB_MERCATOR_TMS
@@ -318,7 +317,7 @@ def mosaicid(self) -> str:
318317
return get_hash(**self.mosaic_def.model_dump(exclude_none=True))
319318

320319
@property
321-
def _quadkeys(self) -> List[str]:
320+
def _quadkeys(self) -> list[str]:
322321
"""Return the list of quadkey tiles."""
323322
return list(self.mosaic_def.tiles)
324323

cogeo_mosaic/backends/dynamodb.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import os
66
import re
77
import warnings
8+
from collections.abc import Sequence
89
from decimal import Decimal
910
from threading import Lock
10-
from typing import Any, Dict, List, Sequence
11+
from typing import Any
1112
from urllib.parse import urlparse
1213

1314
import attr
@@ -136,7 +137,7 @@ def write(self, overwrite: bool = False, **kwargs: Any):
136137
)
137138
self.delete()
138139

139-
items: List[Dict[str, Any]] = []
140+
items: list[dict[str, Any]] = []
140141

141142
# Create Metadata item
142143
# Note: `parse_float=Decimal` is required because DynamoDB requires all numbers to be
@@ -158,7 +159,7 @@ def write(self, overwrite: bool = False, **kwargs: Any):
158159

159160
def update(
160161
self,
161-
features: Sequence[Dict],
162+
features: Sequence[dict],
162163
add_first: bool = True,
163164
quiet: bool = False,
164165
**kwargs,
@@ -193,7 +194,7 @@ def update(
193194
)
194195
self.bounds = bounds
195196

196-
items: List[Dict[str, Any]] = []
197+
items: list[dict[str, Any]] = []
197198

198199
# Create Metadata item
199200
# Note: `parse_float=Decimal` is required because DynamoDB requires all numbers to be
@@ -222,7 +223,7 @@ def update(
222223
key=lambda self, x, y, z: hashkey(self.input, x, y, z, self.mosaicid),
223224
lock=Lock(),
224225
)
225-
def get_assets(self, x: int, y: int, z: int) -> List[str]:
226+
def get_assets(self, x: int, y: int, z: int) -> list[str]:
226227
"""Find assets."""
227228
quadkeys = self.find_quadkeys(Tile(x=x, y=y, z=z), self.quadkey_zoom)
228229
assets = list(
@@ -238,7 +239,7 @@ def get_assets(self, x: int, y: int, z: int) -> List[str]:
238239
return assets
239240

240241
@property
241-
def _quadkeys(self) -> List[str]:
242+
def _quadkeys(self) -> list[str]:
242243
"""Return the list of quadkey tiles."""
243244
resp = self.table.query(
244245
KeyConditionExpression=Key("mosaicId").eq(self.mosaic_name),
@@ -288,7 +289,7 @@ def _create_table(self, billing_mode: str = "PAY_PER_REQUEST", **kwargs: Any):
288289
warnings.warn("Unable to create table.")
289290
return
290291

291-
def _write_items(self, items: List[Dict]):
292+
def _write_items(self, items: list[dict]):
292293
with self.table.batch_writer() as batch:
293294
with click.progressbar(
294295
items,
@@ -299,7 +300,7 @@ def _write_items(self, items: List[Dict]):
299300
for item in progitems:
300301
batch.put_item(item)
301302

302-
def _fetch_dynamodb(self, quadkey: str) -> Dict:
303+
def _fetch_dynamodb(self, quadkey: str) -> dict:
303304
try:
304305
return self.table.get_item(
305306
Key={"mosaicId": self.mosaic_name, "quadkey": quadkey}

cogeo_mosaic/backends/sqlite.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import re
66
import sqlite3
77
import warnings
8+
from collections.abc import Sequence
89
from pathlib import Path
910
from threading import Lock
10-
from typing import Dict, List, Sequence
1111
from urllib.parse import urlparse
1212

1313
import attr
@@ -215,7 +215,7 @@ def write(self, overwrite: bool = False):
215215

216216
def update(
217217
self,
218-
features: Sequence[Dict],
218+
features: Sequence[dict],
219219
add_first: bool = True,
220220
quiet: bool = False,
221221
**kwargs,
@@ -315,7 +315,7 @@ def update(
315315
key=lambda self, x, y, z: hashkey(self.input, x, y, z, self.mosaicid),
316316
lock=Lock(),
317317
)
318-
def get_assets(self, x: int, y: int, z: int) -> List[str]:
318+
def get_assets(self, x: int, y: int, z: int) -> list[str]:
319319
"""Find assets."""
320320
mercator_tile = morecantile.Tile(x=x, y=y, z=z)
321321
quadkeys = self.find_quadkeys(mercator_tile, self.quadkey_zoom)
@@ -330,23 +330,23 @@ def get_assets(self, x: int, y: int, z: int) -> List[str]:
330330
return assets
331331

332332
@property
333-
def _quadkeys(self) -> List[str]:
333+
def _quadkeys(self) -> list[str]:
334334
"""Return the list of quadkey tiles."""
335335
with self.db:
336336
rows = self.db.execute(
337337
f'SELECT quadkey FROM "{self.mosaic_name}";',
338338
).fetchall()
339339
return [r["quadkey"] for r in rows]
340340

341-
def _fetch_metadata(self) -> Dict:
341+
def _fetch_metadata(self) -> dict:
342342
with self.db:
343343
row = self.db.execute(
344344
f"SELECT * FROM {self._metadata_table} WHERE name=?;",
345345
(self.mosaic_name,),
346346
).fetchone()
347347
return dict(row) if row else {}
348348

349-
def _fetch(self, quadkey: str) -> List:
349+
def _fetch(self, quadkey: str) -> list:
350350
with self.db:
351351
row = self.db.execute(
352352
f'SELECT assets FROM "{self.mosaic_name}" WHERE quadkey=?;', (quadkey,)
@@ -377,7 +377,7 @@ def delete(self):
377377
def list_mosaics_in_db(
378378
cls,
379379
db_path: str,
380-
) -> List[str]:
380+
) -> list[str]:
381381
"""List Mosaic tables in SQLite database.
382382
383383
Args:

cogeo_mosaic/backends/stac.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import json
44
import os
5+
from collections.abc import Sequence
56
from threading import Lock
6-
from typing import Dict, List, Optional, Sequence, Type
77

88
import attr
99
import httpx
@@ -22,7 +22,7 @@
2222
from cogeo_mosaic.mosaic import MosaicJSON
2323

2424

25-
def default_stac_accessor(feature: Dict):
25+
def default_stac_accessor(feature: dict):
2626
"""Return feature identifier."""
2727
link = list(filter(lambda link: link["rel"] == "self", feature["links"]))
2828
if link:
@@ -58,26 +58,26 @@ class STACBackend(MosaicJSONBackend):
5858
"""
5959

6060
input: str = attr.ib()
61-
query: Dict = attr.ib()
61+
query: dict = attr.ib()
6262

6363
minzoom: int = attr.ib()
6464
maxzoom: int = attr.ib()
6565

6666
tms: TileMatrixSet = attr.ib(default=WEB_MERCATOR_TMS)
6767

68-
reader: Type[STACReader] = attr.ib(default=STACReader)
69-
reader_options: Dict = attr.ib(factory=dict)
68+
reader: type[STACReader] = attr.ib(default=STACReader)
69+
reader_options: dict = attr.ib(factory=dict)
7070

7171
bounds: BBox = attr.ib(init=False, default=(-180, -90, 180, 90))
7272
crs: CRS = attr.ib(init=False, default=WGS84_CRS)
7373

7474
# STAC API related options
7575
# max_items | next_link_key | limit
76-
stac_api_options: Dict = attr.ib(factory=dict)
76+
stac_api_options: dict = attr.ib(factory=dict)
7777

7878
# Mosaic Creation options
7979
# e.g `accessor`
80-
mosaic_options: Dict = attr.ib(factory=dict)
80+
mosaic_options: dict = attr.ib(factory=dict)
8181

8282
# Because the STACBackend is a Read-Only backend, there is no need for
8383
# mosaic_def to be in the init method.
@@ -126,7 +126,7 @@ def write(self, overwrite: bool = True):
126126

127127
def update(
128128
self,
129-
features: Sequence[Dict],
129+
features: Sequence[dict],
130130
add_first: bool = True,
131131
quiet: bool = False,
132132
**kwargs,
@@ -135,7 +135,7 @@ def update(
135135
raise NotImplementedError
136136

137137

138-
def query_from_link(link: Dict, query: Dict):
138+
def query_from_link(link: dict, query: dict):
139139
"""Handle Next Link."""
140140
q = query.copy()
141141
if link["method"] != "POST":
@@ -156,13 +156,13 @@ def query_from_link(link: Dict, query: Dict):
156156
)
157157
def _fetch( # noqa: C901
158158
stac_url: str,
159-
query: Dict,
160-
max_items: Optional[int] = None,
161-
next_link_key: Optional[str] = None,
159+
query: dict,
160+
max_items: int | None = None,
161+
next_link_key: str | None = None,
162162
limit: int = 500,
163-
) -> List[Dict]:
163+
) -> list[dict]:
164164
"""Call STAC API."""
165-
features: List[Dict] = []
165+
features: list[dict] = []
166166
stac_query = query.copy()
167167

168168
headers = {
@@ -174,7 +174,7 @@ def _fetch( # noqa: C901
174174
if "limit" not in stac_query:
175175
stac_query.update({"limit": limit})
176176

177-
def _stac_search(url: str, q: Dict):
177+
def _stac_search(url: str, q: dict):
178178
try:
179179
r = httpx.post(url, headers=headers, json=q)
180180
r.raise_for_status()

cogeo_mosaic/backends/web.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""
66

77
import json
8+
from collections.abc import Sequence
89
from threading import Lock
9-
from typing import Dict, Sequence
1010

1111
import attr
1212
import httpx
@@ -64,7 +64,7 @@ def write(self, overwrite: bool = True):
6464

6565
def update(
6666
self,
67-
features: Sequence[Dict],
67+
features: Sequence[dict],
6868
add_first: bool = True,
6969
quiet: bool = False,
7070
**kwargs,

0 commit comments

Comments
 (0)