Skip to content

Commit

Permalink
simplify Factories (#943)
Browse files Browse the repository at this point in the history
* simplify Factories

* fix

* fix mosaic

* update changelog

* update version number

* update changelog

* update changelog
  • Loading branch information
vincentsarago committed Sep 24, 2024
1 parent c443d5f commit 1825dce
Show file tree
Hide file tree
Showing 21 changed files with 314 additions and 321 deletions.
45 changes: 43 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
# Release Notes

## Unreleased
## 0.19.0 (TBD)

### Misc

* Removed default `WebMercatorQuad` tile matrix set in `/tiles`, `/tilesjson.json`, `/map` and `/WMTSCapabilities.xml` endpoints **breaking change**

```
# Before
/tiles/{z}/{x}/{y}
/tilejson.json
/map
/WMTSCapabilities.xml
# Now
/tiles/WebMercatorQuad/{z}/{x}/{y}
/WebMercatorQuad/tilejson.json
/WebMercatorQuad/map
/WebMercatorQuad/WMTSCapabilities.xml
```

* Use `@attrs.define` instead of dataclass for factories **breaking change**
* Use `@attrs.define` instead of dataclass for factory extensions **breaking change**


### titiler.core

* Improve XSS security for HTML templates (author @jcary741, https://github.com/developmentseed/titiler/pull/953)

* Remove all default values to the dependencies
* Remove all default values to the dependencies **breaking change**

* `DatasetParams.unscale`: `False` -> `None` (default to `False` in rio-tiler)
* `DatasetParams.resampling_method`: `nearest` -> `None` (default to `nearest` in rio-tiler)
* `DatasetParams.reproject_method`: `nearest` -> `None` (default to `nearest` in rio-tiler)
Expand Down Expand Up @@ -40,12 +63,30 @@

* Use `.as_dict()` method when passing option to rio-tiler Reader's methods to avoid parameter conflicts when using custom Readers.

* Renamed `BaseTilerFactory` to `BaseFactory` **breaking change**

* Removed useless attribute in `BaseFactory` (and moved them to `TilerFactory`) **breaking change**

### titiler.mosaic

* Renamed `reader` attribute to `backend` in `MosaicTilerFactory` **breaking change**

### titiler.extensions

* Encode URL for cog_viewer and stac_viewer (author @guillemc23, https://github.com/developmentseed/titiler/pull/961)

* Add links for render parameters and `/map` link to **viewer** dashboard (author @hrodmn, https://github.com/developmentseed/titiler/pull/987)

## 0.18.9 (2024-09-23)

* fix release 0.18.8

## 0.18.8 (2024-09-23)

### titiler.extensions

* Add links for render parameters and /map link to viewer dashboard (author @hrodmn, https://github.com/developmentseed/titiler/pull/987)

## 0.18.7 (2024-09-19)

* fix Hillshade algorithm (bad `azimuth` angle) (https://github.com/developmentseed/titiler/pull/985) [Backported]
Expand Down
2 changes: 1 addition & 1 deletion deployment/aws/lambda/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /tmp
RUN yum install -y gcc-c++

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

# Reduce package size and remove useless files
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;
Expand Down
2 changes: 1 addition & 1 deletion deployment/k8s/charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v1
appVersion: 0.18.6
appVersion: 0.18.9
description: A dynamic Web Map tile server
name: titiler
version: 1.1.3
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: GIS",
]
version="0.18.6"
version="0.18.9"
dependencies = [
"titiler.core==0.18.6",
"titiler.extensions==0.18.6",
"titiler.mosaic==0.18.6",
"titiler.application==0.18.6",
"titiler.core==0.18.9",
"titiler.extensions==0.18.9",
"titiler.mosaic==0.18.9",
"titiler.application==0.18.9",
]

[project.urls]
Expand Down Expand Up @@ -126,7 +126,7 @@ filterwarnings = [
bypass-selection = true

[tool.bumpversion]
current_version = "0.18.6"
current_version = "0.18.9"
parse = """(?x)
(?P<major>\\d+)\\.
(?P<minor>\\d+)\\.
Expand Down
6 changes: 3 additions & 3 deletions src/titiler/application/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"titiler.core==0.18.6",
"titiler.extensions[cogeo,stac]==0.18.6",
"titiler.mosaic==0.18.6",
"titiler.core==0.18.9",
"titiler.extensions[cogeo,stac]==0.18.9",
"titiler.mosaic==0.18.9",
"starlette-cramjam>=0.3,<0.4",
"pydantic-settings~=2.0",
]
Expand Down
2 changes: 1 addition & 1 deletion src/titiler/application/titiler/application/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""titiler.application"""

__version__ = "0.18.6"
__version__ = "0.18.9"
3 changes: 2 additions & 1 deletion src/titiler/application/titiler/application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import jinja2
from fastapi import Depends, FastAPI, HTTPException, Security
from fastapi.security.api_key import APIKeyQuery
from rio_tiler.io import STACReader
from rio_tiler.io import Reader, STACReader
from starlette.middleware.cors import CORSMiddleware
from starlette.requests import Request
from starlette.responses import HTMLResponse
Expand Down Expand Up @@ -98,6 +98,7 @@ def validate_access_token(access_token: str = Security(api_key_query)):
# Simple Dataset endpoints (e.g Cloud Optimized GeoTIFF)
if not api_settings.disable_cog:
cog = TilerFactory(
reader=Reader,
router_prefix="/cog",
extensions=[
cogValidateExtension(),
Expand Down
35 changes: 17 additions & 18 deletions src/titiler/core/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
import pathlib
import warnings
import xml.etree.ElementTree as ET
from dataclasses import dataclass
from enum import Enum
from io import BytesIO
from typing import Dict, Optional, Type
from unittest.mock import patch
from urllib.parse import urlencode

import attr
import httpx
import morecantile
import numpy
import pytest
from attrs import define, field
from fastapi import Depends, FastAPI, HTTPException, Path, Query, security, status
from morecantile.defaults import TileMatrixSets
from rasterio.crs import CRS
Expand All @@ -31,7 +30,7 @@
from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers
from titiler.core.factory import (
AlgorithmFactory,
BaseTilerFactory,
BaseFactory,
ColorMapFactory,
MultiBandTilerFactory,
MultiBaseTilerFactory,
Expand All @@ -49,7 +48,7 @@
def test_TilerFactory():
"""Test TilerFactory class."""
cog = TilerFactory()
assert len(cog.router.routes) == 27
assert len(cog.router.routes) == 20
assert len(cog.supported_tms.list()) == NB_DEFAULT_TMS

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

cog = TilerFactory(add_preview=False, add_part=False, add_viewer=False)
assert len(cog.router.routes) == 18
assert len(cog.router.routes) == 12

app = FastAPI()
cog = TilerFactory()
Expand Down Expand Up @@ -723,7 +722,7 @@ def test_MultiBaseTilerFactory(rio):
rio.open = mock_rasterio_open

stac = MultiBaseTilerFactory(reader=STACReader)
assert len(stac.router.routes) == 29
assert len(stac.router.routes) == 22

app = FastAPI()
app.include_router(stac.router)
Expand Down Expand Up @@ -1045,20 +1044,20 @@ def test_MultiBaseTilerFactory(rio):
assert "(B09 - B01) / (B09 + B01)" in props


@attr.s
@define
class BandFileReader(MultiBandReader):
"""Test MultiBand"""

input: str = attr.ib()
tms: morecantile.TileMatrixSet = attr.ib(
input: str = field()
tms: morecantile.TileMatrixSet = field(
default=morecantile.tms.get("WebMercatorQuad")
)
reader_options: Dict = attr.ib(factory=dict)
reader_options: Dict = field(factory=dict)

reader: Type[BaseReader] = attr.ib(default=Reader)
reader: Type[BaseReader] = field(default=Reader)

minzoom: int = attr.ib()
maxzoom: int = attr.ib()
minzoom: int = field()
maxzoom: int = field()

@minzoom.default
def _minzoom(self):
Expand Down Expand Up @@ -1093,7 +1092,7 @@ def test_MultiBandTilerFactory():
bands = MultiBandTilerFactory(
reader=BandFileReader, path_dependency=CustomPathParams
)
assert len(bands.router.routes) == 28
assert len(bands.router.routes) == 21

app = FastAPI()
app.include_router(bands.router)
Expand Down Expand Up @@ -1465,7 +1464,7 @@ def must_be_bob(credentials: security.HTTPBasicCredentials = Depends(http_basic)
],
router_prefix="something",
)
assert len(cog.router.routes) == 27
assert len(cog.router.routes) == 20

app = FastAPI()
app.include_router(cog.router, prefix="/something")
Expand Down Expand Up @@ -1614,8 +1613,8 @@ def test_algorithm():
def test_path_param_in_prefix():
"""Test path params in prefix."""

@dataclass
class EndpointFactory(BaseTilerFactory):
@define
class EndpointFactory(BaseFactory):
def register_routes(self):
"""register endpoints."""

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

app = FastAPI()
endpoints = EndpointFactory(reader=Reader, router_prefix="/prefixed/{param1}")
endpoints = EndpointFactory(router_prefix="/prefixed/{param1}")
app.include_router(endpoints.router, prefix="/prefixed/{param1}")
client = TestClient(app)

Expand Down
7 changes: 5 additions & 2 deletions src/titiler/core/titiler/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""titiler.core"""

__version__ = "0.18.6"
__version__ = "0.18.9"

from . import dependencies, errors, factory, routing # noqa
from .factory import ( # noqa
BaseTilerFactory,
AlgorithmFactory,
BaseFactory,
ColorMapFactory,
MultiBandTilerFactory,
MultiBaseTilerFactory,
TilerFactory,
TMSFactory,
)
Loading

1 comment on commit 1825dce

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'TiTiler performance Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: 1825dce Previous: c443d5f Ratio
WGS1984Quad longest_transaction 0.08 s 0.06 s 1.33

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.