Skip to content

Commit 1825dce

Browse files
simplify Factories (#943)
* simplify Factories * fix * fix mosaic * update changelog * update version number * update changelog * update changelog
1 parent c443d5f commit 1825dce

File tree

21 files changed

+314
-321
lines changed

21 files changed

+314
-321
lines changed

CHANGES.md

+43-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
# Release Notes
22

3-
## Unreleased
3+
## 0.19.0 (TBD)
4+
5+
### Misc
6+
7+
* Removed default `WebMercatorQuad` tile matrix set in `/tiles`, `/tilesjson.json`, `/map` and `/WMTSCapabilities.xml` endpoints **breaking change**
8+
9+
```
10+
# Before
11+
/tiles/{z}/{x}/{y}
12+
/tilejson.json
13+
/map
14+
/WMTSCapabilities.xml
15+
16+
# Now
17+
/tiles/WebMercatorQuad/{z}/{x}/{y}
18+
/WebMercatorQuad/tilejson.json
19+
/WebMercatorQuad/map
20+
/WebMercatorQuad/WMTSCapabilities.xml
21+
```
22+
23+
* Use `@attrs.define` instead of dataclass for factories **breaking change**
24+
* Use `@attrs.define` instead of dataclass for factory extensions **breaking change**
25+
426
527
### titiler.core
628
729
* Improve XSS security for HTML templates (author @jcary741, https://github.com/developmentseed/titiler/pull/953)
830
9-
* Remove all default values to the dependencies
31+
* Remove all default values to the dependencies **breaking change**
32+
1033
* `DatasetParams.unscale`: `False` -> `None` (default to `False` in rio-tiler)
1134
* `DatasetParams.resampling_method`: `nearest` -> `None` (default to `nearest` in rio-tiler)
1235
* `DatasetParams.reproject_method`: `nearest` -> `None` (default to `nearest` in rio-tiler)
@@ -40,12 +63,30 @@
4063
4164
* Use `.as_dict()` method when passing option to rio-tiler Reader's methods to avoid parameter conflicts when using custom Readers.
4265
66+
* Renamed `BaseTilerFactory` to `BaseFactory` **breaking change**
67+
68+
* Removed useless attribute in `BaseFactory` (and moved them to `TilerFactory`) **breaking change**
69+
70+
### titiler.mosaic
71+
72+
* Renamed `reader` attribute to `backend` in `MosaicTilerFactory` **breaking change**
73+
4374
### titiler.extensions
4475
4576
* Encode URL for cog_viewer and stac_viewer (author @guillemc23, https://github.com/developmentseed/titiler/pull/961)
4677
4778
* Add links for render parameters and `/map` link to **viewer** dashboard (author @hrodmn, https://github.com/developmentseed/titiler/pull/987)
4879
80+
## 0.18.9 (2024-09-23)
81+
82+
* fix release 0.18.8
83+
84+
## 0.18.8 (2024-09-23)
85+
86+
### titiler.extensions
87+
88+
* Add links for render parameters and /map link to viewer dashboard (author @hrodmn, https://github.com/developmentseed/titiler/pull/987)
89+
4990
## 0.18.7 (2024-09-19)
5091
5192
* fix Hillshade algorithm (bad `azimuth` angle) (https://github.com/developmentseed/titiler/pull/985) [Backported]

deployment/aws/lambda/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ WORKDIR /tmp
88
RUN yum install -y gcc-c++
99

1010
RUN python -m pip install pip -U
11-
RUN python -m pip install "titiler.application==0.18.6" "mangum>=0.10.0" -t /asset --no-binary pydantic
11+
RUN python -m pip install "titiler.application==0.18.9" "mangum>=0.10.0" -t /asset --no-binary pydantic
1212

1313
# Reduce package size and remove useless files
1414
RUN cd /asset && find . -type f -name '*.pyc' | while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[0-9]*//'); cp $f $n; done;

deployment/k8s/charts/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: v1
2-
appVersion: 0.18.6
2+
appVersion: 0.18.9
33
description: A dynamic Web Map tile server
44
name: titiler
55
version: 1.1.3

pyproject.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ classifiers = [
2929
"Programming Language :: Python :: 3.12",
3030
"Topic :: Scientific/Engineering :: GIS",
3131
]
32-
version="0.18.6"
32+
version="0.18.9"
3333
dependencies = [
34-
"titiler.core==0.18.6",
35-
"titiler.extensions==0.18.6",
36-
"titiler.mosaic==0.18.6",
37-
"titiler.application==0.18.6",
34+
"titiler.core==0.18.9",
35+
"titiler.extensions==0.18.9",
36+
"titiler.mosaic==0.18.9",
37+
"titiler.application==0.18.9",
3838
]
3939

4040
[project.urls]
@@ -126,7 +126,7 @@ filterwarnings = [
126126
bypass-selection = true
127127

128128
[tool.bumpversion]
129-
current_version = "0.18.6"
129+
current_version = "0.18.9"
130130
parse = """(?x)
131131
(?P<major>\\d+)\\.
132132
(?P<minor>\\d+)\\.

src/titiler/application/pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ classifiers = [
3131
]
3232
dynamic = ["version"]
3333
dependencies = [
34-
"titiler.core==0.18.6",
35-
"titiler.extensions[cogeo,stac]==0.18.6",
36-
"titiler.mosaic==0.18.6",
34+
"titiler.core==0.18.9",
35+
"titiler.extensions[cogeo,stac]==0.18.9",
36+
"titiler.mosaic==0.18.9",
3737
"starlette-cramjam>=0.3,<0.4",
3838
"pydantic-settings~=2.0",
3939
]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""titiler.application"""
22

3-
__version__ = "0.18.6"
3+
__version__ = "0.18.9"

src/titiler/application/titiler/application/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import jinja2
77
from fastapi import Depends, FastAPI, HTTPException, Security
88
from fastapi.security.api_key import APIKeyQuery
9-
from rio_tiler.io import STACReader
9+
from rio_tiler.io import Reader, STACReader
1010
from starlette.middleware.cors import CORSMiddleware
1111
from starlette.requests import Request
1212
from starlette.responses import HTMLResponse
@@ -98,6 +98,7 @@ def validate_access_token(access_token: str = Security(api_key_query)):
9898
# Simple Dataset endpoints (e.g Cloud Optimized GeoTIFF)
9999
if not api_settings.disable_cog:
100100
cog = TilerFactory(
101+
reader=Reader,
101102
router_prefix="/cog",
102103
extensions=[
103104
cogValidateExtension(),

src/titiler/core/tests/test_factories.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
import pathlib
66
import warnings
77
import xml.etree.ElementTree as ET
8-
from dataclasses import dataclass
98
from enum import Enum
109
from io import BytesIO
1110
from typing import Dict, Optional, Type
1211
from unittest.mock import patch
1312
from urllib.parse import urlencode
1413

15-
import attr
1614
import httpx
1715
import morecantile
1816
import numpy
1917
import pytest
18+
from attrs import define, field
2019
from fastapi import Depends, FastAPI, HTTPException, Path, Query, security, status
2120
from morecantile.defaults import TileMatrixSets
2221
from rasterio.crs import CRS
@@ -31,7 +30,7 @@
3130
from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers
3231
from titiler.core.factory import (
3332
AlgorithmFactory,
34-
BaseTilerFactory,
33+
BaseFactory,
3534
ColorMapFactory,
3635
MultiBandTilerFactory,
3736
MultiBaseTilerFactory,
@@ -49,7 +48,7 @@
4948
def test_TilerFactory():
5049
"""Test TilerFactory class."""
5150
cog = TilerFactory()
52-
assert len(cog.router.routes) == 27
51+
assert len(cog.router.routes) == 20
5352
assert len(cog.supported_tms.list()) == NB_DEFAULT_TMS
5453

5554
cog = TilerFactory(router_prefix="something", supported_tms=WEB_TMS)
@@ -76,7 +75,7 @@ def test_TilerFactory():
7675
assert response.status_code == 422
7776

7877
cog = TilerFactory(add_preview=False, add_part=False, add_viewer=False)
79-
assert len(cog.router.routes) == 18
78+
assert len(cog.router.routes) == 12
8079

8180
app = FastAPI()
8281
cog = TilerFactory()
@@ -723,7 +722,7 @@ def test_MultiBaseTilerFactory(rio):
723722
rio.open = mock_rasterio_open
724723

725724
stac = MultiBaseTilerFactory(reader=STACReader)
726-
assert len(stac.router.routes) == 29
725+
assert len(stac.router.routes) == 22
727726

728727
app = FastAPI()
729728
app.include_router(stac.router)
@@ -1045,20 +1044,20 @@ def test_MultiBaseTilerFactory(rio):
10451044
assert "(B09 - B01) / (B09 + B01)" in props
10461045

10471046

1048-
@attr.s
1047+
@define
10491048
class BandFileReader(MultiBandReader):
10501049
"""Test MultiBand"""
10511050

1052-
input: str = attr.ib()
1053-
tms: morecantile.TileMatrixSet = attr.ib(
1051+
input: str = field()
1052+
tms: morecantile.TileMatrixSet = field(
10541053
default=morecantile.tms.get("WebMercatorQuad")
10551054
)
1056-
reader_options: Dict = attr.ib(factory=dict)
1055+
reader_options: Dict = field(factory=dict)
10571056

1058-
reader: Type[BaseReader] = attr.ib(default=Reader)
1057+
reader: Type[BaseReader] = field(default=Reader)
10591058

1060-
minzoom: int = attr.ib()
1061-
maxzoom: int = attr.ib()
1059+
minzoom: int = field()
1060+
maxzoom: int = field()
10621061

10631062
@minzoom.default
10641063
def _minzoom(self):
@@ -1093,7 +1092,7 @@ def test_MultiBandTilerFactory():
10931092
bands = MultiBandTilerFactory(
10941093
reader=BandFileReader, path_dependency=CustomPathParams
10951094
)
1096-
assert len(bands.router.routes) == 28
1095+
assert len(bands.router.routes) == 21
10971096

10981097
app = FastAPI()
10991098
app.include_router(bands.router)
@@ -1465,7 +1464,7 @@ def must_be_bob(credentials: security.HTTPBasicCredentials = Depends(http_basic)
14651464
],
14661465
router_prefix="something",
14671466
)
1468-
assert len(cog.router.routes) == 27
1467+
assert len(cog.router.routes) == 20
14691468

14701469
app = FastAPI()
14711470
app.include_router(cog.router, prefix="/something")
@@ -1614,8 +1613,8 @@ def test_algorithm():
16141613
def test_path_param_in_prefix():
16151614
"""Test path params in prefix."""
16161615

1617-
@dataclass
1618-
class EndpointFactory(BaseTilerFactory):
1616+
@define
1617+
class EndpointFactory(BaseFactory):
16191618
def register_routes(self):
16201619
"""register endpoints."""
16211620

@@ -1632,7 +1631,7 @@ def route1(param1: int = Path(...), param2: str = Path(...)):
16321631
return {"value": param2}
16331632

16341633
app = FastAPI()
1635-
endpoints = EndpointFactory(reader=Reader, router_prefix="/prefixed/{param1}")
1634+
endpoints = EndpointFactory(router_prefix="/prefixed/{param1}")
16361635
app.include_router(endpoints.router, prefix="/prefixed/{param1}")
16371636
client = TestClient(app)
16381637

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""titiler.core"""
22

3-
__version__ = "0.18.6"
3+
__version__ = "0.18.9"
44

55
from . import dependencies, errors, factory, routing # noqa
66
from .factory import ( # noqa
7-
BaseTilerFactory,
7+
AlgorithmFactory,
8+
BaseFactory,
9+
ColorMapFactory,
810
MultiBandTilerFactory,
911
MultiBaseTilerFactory,
1012
TilerFactory,
13+
TMSFactory,
1114
)

0 commit comments

Comments
 (0)