Skip to content

Commit e5003a2

Browse files
committed
remove deprecated and fix typing hints
1 parent 0334d58 commit e5003a2

File tree

11 files changed

+25
-237
lines changed

11 files changed

+25
-237
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
- `titiler.core.dependencies.BandsExprParams`
3535
- `titiler.core.dependencies.parse_asset_indexes()`
3636
- `titiler.core.dependencies.parse_asset_expression()`
37+
- `titiler.core.routing.apiroute_factory()`
3738

3839
### titiler.extensions
3940

docs/mkdocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ nav:
5252
- Performance Tuning: "advanced/performance_tuning.md"
5353
- Extensions: "advanced/Extensions.md"
5454
- Observability with OpenTelemetry: "advanced/telemetry.md"
55-
# - APIRoute and environment variables: "advanced/APIRoute_and_environment_variables.md"
5655

5756
- Packages:
5857
- titiler.core: "packages/core.md"

docs/src/advanced/APIRoute_and_environment_variables.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/titiler/core/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ dependencies = [
3636
"numpy",
3737
"pydantic~=2.0",
3838
"rasterio",
39-
"rio-tiler>=9.0.0a1,<10.0",
39+
"rio-tiler>=9.0.0a4,<10.0",
4040
"morecantile",
4141
"simplejson",
42-
"typing_extensions>=4.6.1",
4342
]
4443

4544
[project.optional-dependencies]

src/titiler/core/tests/test_factories.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dataclasses import dataclass
99
from enum import Enum
1010
from io import BytesIO
11-
from typing import Dict, Optional, Sequence, Type
11+
from typing import Annotated, Dict, Optional, Sequence, Type
1212
from unittest.mock import patch
1313
from urllib.parse import quote, urlencode
1414

@@ -27,7 +27,6 @@
2727
from rio_tiler.io import BaseReader, MultiBandReader, Reader, STACReader
2828
from starlette.requests import Request
2929
from starlette.testclient import TestClient
30-
from typing_extensions import Annotated
3130

3231
from titiler.core import dependencies
3332
from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers

src/titiler/core/tests/test_routing.py

Lines changed: 3 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,10 @@
1-
"""Test Custom APIRoute factory."""
2-
3-
from concurrent import futures
1+
"""Test route dependencies."""
42

53
import httpx
6-
import pytest
7-
import rasterio
8-
from fastapi import APIRouter, Depends, FastAPI, HTTPException, security, status
9-
from rasterio._env import get_gdal_config
4+
from fastapi import Depends, FastAPI, HTTPException, security, status
105
from starlette.testclient import TestClient
116

12-
from titiler.core.routing import add_route_dependencies, apiroute_factory
13-
14-
15-
@pytest.mark.xfail
16-
def test_withoutCustomRoute(monkeypatch):
17-
"""Create App."""
18-
monkeypatch.setenv("GDAL_DISABLE_READDIR_ON_OPEN", "something")
19-
20-
app = FastAPI()
21-
router = APIRouter()
22-
23-
def f(r):
24-
return get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
25-
26-
@router.get("/simple")
27-
def home():
28-
"""Works and should return FALSE."""
29-
with rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN="FALSE"):
30-
res = get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
31-
return {"env": res}
32-
33-
@router.get("/asimple")
34-
async def home1():
35-
"""Works and should return FALSE."""
36-
with rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN="FALSE"):
37-
res = get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
38-
return {"env": res}
39-
40-
@router.get("/future")
41-
def home2():
42-
"""Doesn't work and should return the value from env."""
43-
with rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN="FALSE"):
44-
with futures.ThreadPoolExecutor() as executor:
45-
res = list(executor.map(f, range(1)))[0]
46-
return {"env": res}
47-
48-
@router.get("/afuture")
49-
async def home3():
50-
"""Works and should return FALSE."""
51-
with rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN="FALSE"):
52-
with futures.ThreadPoolExecutor() as executor:
53-
res = list(executor.map(f, range(1)))[0]
54-
return {"env": res}
55-
56-
app.include_router(router)
57-
client = TestClient(app)
58-
59-
response = client.get("/simple")
60-
assert response.json()["env"] == "FALSE"
61-
62-
response = client.get("/asimple")
63-
assert response.json()["env"] == "FALSE"
64-
65-
# confirm the multi threads case doesn't work
66-
response = client.get("/future")
67-
assert not response.json()["env"] == "FALSE"
68-
69-
response = client.get("/afuture")
70-
assert response.json()["env"] == "FALSE"
71-
72-
73-
@pytest.mark.xfail
74-
def test_withCustomRoute(monkeypatch):
75-
"""Create App."""
76-
monkeypatch.setenv("GDAL_DISABLE_READDIR_ON_OPEN", "something")
77-
78-
app = FastAPI()
79-
80-
env = {"GDAL_DISABLE_READDIR_ON_OPEN": "FALSE"}
81-
with pytest.warns(DeprecationWarning):
82-
route_class = apiroute_factory(env)
83-
router = APIRouter(route_class=route_class)
84-
85-
def f(r):
86-
return get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
87-
88-
@router.get("/simple")
89-
def home():
90-
"""Works and should return FALSE."""
91-
res = get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
92-
return {"env": res}
93-
94-
@router.get("/asimple")
95-
async def home1():
96-
"""Works and should return FALSE."""
97-
res = get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
98-
return {"env": res}
99-
100-
@router.get("/future")
101-
def home2():
102-
"""Doesn't work and should return the value from env."""
103-
with futures.ThreadPoolExecutor() as executor:
104-
res = list(executor.map(f, range(1)))[0]
105-
return {"env": res}
106-
107-
@router.get("/afuture")
108-
async def home3():
109-
"""Works and should return FALSE."""
110-
with futures.ThreadPoolExecutor() as executor:
111-
res = list(executor.map(f, range(1)))[0]
112-
return {"env": res}
113-
114-
app.include_router(router)
115-
client = TestClient(app)
116-
117-
response = client.get("/simple")
118-
assert response.json()["env"] == "FALSE"
119-
120-
response = client.get("/asimple")
121-
assert response.json()["env"] == "FALSE"
122-
123-
# confirm the Custom APIRoute class fix
124-
response = client.get("/future")
125-
assert response.json()["env"] == "FALSE"
126-
127-
response = client.get("/afuture")
128-
assert response.json()["env"] == "FALSE"
7+
from titiler.core.routing import add_route_dependencies
1298

1309

13110
def test_register_deps():

src/titiler/core/titiler/core/routing.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,10 @@
11
"""Custom routing classes."""
22

3-
import warnings
4-
from collections.abc import Callable
3+
from typing import TypedDict
54

6-
import rasterio
75
from fastapi import params
86
from fastapi.dependencies.utils import get_parameterless_sub_dependant
9-
from fastapi.routing import APIRoute
10-
from starlette.requests import Request
11-
from starlette.responses import Response
127
from starlette.routing import BaseRoute, Match
13-
from typing_extensions import TypedDict
14-
15-
16-
def apiroute_factory(env: dict | None = None) -> type[APIRoute]:
17-
"""
18-
Create Custom API Route class with custom Env.
19-
20-
Because we cannot create middleware for specific router we need to create
21-
a custom APIRoute which add the `rasterio.Env(` block before the endpoint is
22-
actually called. This way we set the env outside the threads and we make sure
23-
that event multithreaded Reader will get the environment set.
24-
25-
Note: This has been tested in python 3.6 and 3.7 only.
26-
27-
"""
28-
warnings.warn(
29-
"'apiroute_factory' has been deprecated and will be removed"
30-
"in titiler 0.1.0. Please see `environment_dependency` option in endpoint factories.",
31-
DeprecationWarning,
32-
stacklevel=1,
33-
)
34-
35-
class EnvAPIRoute(APIRoute):
36-
"""Custom API route with env."""
37-
38-
config = env or {}
39-
40-
def get_route_handler(self) -> Callable:
41-
original_route_handler = super().get_route_handler()
42-
43-
async def custom_route_handler(request: Request) -> Response:
44-
with rasterio.Env(**self.config):
45-
response: Response = await original_route_handler(request)
46-
return response
47-
48-
return custom_route_handler
49-
50-
return EnvAPIRoute
518

529

5310
class EndpointScope(TypedDict, total=False):

src/titiler/extensions/titiler/extensions/stac.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""rio-stac Extension."""
22

3-
from typing import Annotated, Any, Literal
3+
from typing import Annotated, Any, Literal, TypedDict
44

55
from attrs import define
66
from fastapi import Depends, Query
7-
from typing_extensions import TypedDict
87

98
from titiler.core.factory import FactoryExtension, TilerFactory
109

src/titiler/xarray/titiler/xarray/extensions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import warnings
44
from collections.abc import Callable
5-
from typing import Annotated
5+
from typing import Annotated, TypedDict
66

77
import xarray
88
from attrs import define
99
from fastapi import Depends, Query
1010
from rio_tiler.constants import WGS84_CRS
1111
from starlette.responses import HTMLResponse
12-
from typing_extensions import TypedDict
1312

1413
from titiler.core.dependencies import DefaultDependency
1514
from titiler.core.factory import FactoryExtension

src/titiler/xarray/titiler/xarray/io.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections.abc import Callable
88
from functools import cache
99
from pathlib import Path
10-
from typing import Any, Literal
10+
from typing import Any, Literal, TypedDict
1111
from urllib.parse import urlparse
1212

1313
import attr
@@ -18,7 +18,6 @@
1818
from morecantile import TileMatrixSet
1919
from rio_tiler.constants import WEB_MERCATOR_TMS
2020
from rio_tiler.io.xarray import XarrayReader
21-
from typing_extensions import TypedDict
2221
from zarr.storage import ObjectStore
2322

2423
X_DIM_NAMES = ["lon", "longitude", "LON", "LONGITUDE", "Lon", "Longitude"]

0 commit comments

Comments
 (0)