Skip to content

Commit

Permalink
fix template loading for starlette >= 0.28 (#744)
Browse files Browse the repository at this point in the history
* fix template loading for starlette >= 0.28

* update from main and set fastapi version to >=0.107.0

---------

Co-authored-by: vincentsarago <[email protected]>
  • Loading branch information
jasongi and vincentsarago authored Jan 8, 2024
1 parent 33914c7 commit 27f8f6e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Release Notes

## Unreleased

### titiler.core

* fix template loading for starlette >= 0.28 by using `jinja2.Environment` argument

### titiler.extensions

* fix template loading for starlette >= 0.28 by using `jinja2.Environment` argument

### titiler.application

* fix template loading for starlette >= 0.28 by using `jinja2.Environment` argument

## 0.15.7 (2024-01-08)

### titiler.core
Expand Down
11 changes: 6 additions & 5 deletions src/titiler/application/titiler/application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
logging.getLogger("botocore.utils").disabled = True
logging.getLogger("rio-tiler").setLevel(logging.ERROR)

templates = Jinja2Templates(
directory="",
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")]),
) # type:ignore
jinja2_env = jinja2.Environment(
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")])
)
templates = Jinja2Templates(env=jinja2_env)


api_settings = ApiSettings()
Expand All @@ -56,7 +56,8 @@
def validate_access_token(access_token: str = Security(api_key_query)):
"""Validates API key access token, set as the `api_settings.global_access_token` value.
Returns True if no access token is required, or if the access token is valid.
Raises an HTTPException (401) if the access token is required but invalid/missing."""
Raises an HTTPException (401) if the access token is required but invalid/missing.
"""
if api_settings.global_access_token is None:
return True

Expand Down
2 changes: 1 addition & 1 deletion src/titiler/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"fastapi>=0.100.0,<0.107.0",
"fastapi>=0.107.0",
"geojson-pydantic>=1.0,<2.0",
"jinja2>=2.11.2,<4.0.0",
"numpy",
Expand Down
9 changes: 4 additions & 5 deletions src/titiler/core/titiler/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@
from titiler.core.routing import EndpointScope
from titiler.core.utils import render_image

DEFAULT_TEMPLATES = Jinja2Templates(
directory="",
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")]),
) # type:ignore

jinja2_env = jinja2.Environment(
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")])
)
DEFAULT_TEMPLATES = Jinja2Templates(env=jinja2_env)

img_endpoint_params: Dict[str, Any] = {
"responses": {
Expand Down
8 changes: 4 additions & 4 deletions src/titiler/extensions/titiler/extensions/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

from titiler.core.factory import BaseTilerFactory, FactoryExtension

DEFAULT_TEMPLATES = Jinja2Templates(
directory="",
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")]),
) # type:ignore
jinja2_env = jinja2.Environment(
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")])
)
DEFAULT_TEMPLATES = Jinja2Templates(env=jinja2_env)


@dataclass
Expand Down
9 changes: 4 additions & 5 deletions src/titiler/extensions/titiler/extensions/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from titiler.core.resources.enums import ImageType, MediaType
from titiler.core.utils import render_image

DEFAULT_TEMPLATES = Jinja2Templates(
directory="",
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")]),
) # type:ignore
jinja2_env = jinja2.Environment(
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")])
)
DEFAULT_TEMPLATES = Jinja2Templates(env=jinja2_env)


class WMSMediaType(str, Enum):
Expand Down Expand Up @@ -522,7 +522,6 @@ def _reader(src_path: str):
return image, format, transparent

if request_type.lower() == "getmap":

# List of required parameters (styles and crs are excluded)
req_keys = {
"version",
Expand Down

0 comments on commit 27f8f6e

Please sign in to comment.