morecantile 6.2.0__py3-none-any.whl → 7.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
morecantile/defaults.py CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  import os
4
4
  import pathlib
5
- from copy import copy
6
- from typing import Dict, List, Union
5
+ from copy import copy, deepcopy
7
6
 
8
7
  import attr
9
8
 
@@ -17,7 +16,7 @@ user_tms_dir = os.environ.get("TILEMATRIXSET_DIRECTORY", None)
17
16
  if user_tms_dir:
18
17
  tms_paths.extend(list(pathlib.Path(user_tms_dir).glob("*.json")))
19
18
 
20
- default_tms: Dict[str, Union[TileMatrixSet, pathlib.Path]] = {
19
+ default_tms: dict[str, TileMatrixSet | pathlib.Path] = {
21
20
  tms.stem: tms for tms in sorted(tms_paths)
22
21
  }
23
22
 
@@ -26,38 +25,38 @@ default_tms: Dict[str, Union[TileMatrixSet, pathlib.Path]] = {
26
25
  class TileMatrixSets:
27
26
  """Default TileMatrixSets holder."""
28
27
 
29
- tms: Dict = attr.ib()
28
+ tilematrixsets: dict = attr.ib()
30
29
 
31
30
  def get(self, identifier: str) -> TileMatrixSet:
32
31
  """Fetch a TMS."""
33
- if identifier not in self.tms:
32
+ if identifier not in self.tilematrixsets:
34
33
  raise InvalidIdentifier(f"Invalid identifier: {identifier}")
35
34
 
36
- tms = self.tms[identifier]
35
+ tilematrix = self.tilematrixsets[identifier]
37
36
 
38
37
  # We lazyload the TMS document only when called
39
- if isinstance(tms, pathlib.Path):
40
- with tms.open() as f:
41
- tms = TileMatrixSet.model_validate_json(f.read())
42
- self.tms[identifier] = tms
38
+ if isinstance(tilematrix, pathlib.Path):
39
+ with tilematrix.open() as f:
40
+ tilematrix = TileMatrixSet.model_validate_json(f.read())
41
+ self.tilematrixsets[identifier] = tilematrix
43
42
 
44
- return tms
43
+ return deepcopy(tilematrix)
45
44
 
46
- def list(self) -> List[str]:
45
+ def list(self) -> list[str]:
47
46
  """List registered TMS."""
48
- return list(self.tms.keys())
47
+ return list(self.tilematrixsets.keys())
49
48
 
50
49
  def register(
51
50
  self,
52
- custom_tms: Dict[str, TileMatrixSet],
51
+ custom_tms: dict[str, TileMatrixSet],
53
52
  overwrite: bool = False,
54
53
  ) -> "TileMatrixSets":
55
54
  """Register TileMatrixSet(s)."""
56
55
  for identifier in custom_tms.keys():
57
- if identifier in self.tms and not overwrite:
56
+ if identifier in self.tilematrixsets and not overwrite:
58
57
  raise InvalidIdentifier(f"{identifier} is already a registered TMS.")
59
58
 
60
- return TileMatrixSets({**self.tms, **custom_tms})
59
+ return TileMatrixSets({**self.tilematrixsets, **custom_tms})
61
60
 
62
61
 
63
62
  tms = TileMatrixSets(copy(default_tms)) # noqa