From e6b63369c608e4b6f87d0d2a53b314839cfad647 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Wed, 19 Jul 2023 11:47:39 +0200 Subject: [PATCH] remove stac-pydantic --- CHANGES.md | 4 ++- pyproject.toml | 3 +- titiler/pgstac/model.py | 69 +++++++---------------------------------- 3 files changed, 16 insertions(+), 60 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4f98698..aa4f889 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,9 @@ * replace variable `TileMatrixSetId` by `tileMatrixSetId` * add `pixel_selection_dependency` attribute to the `MosaicTilerFactory` * re-order endpoints in `MosaicTilerFactory` to avoid conflicts between `tiles` and `assets` endpoints -* remove deprecater `/{searchid}/{z}/{x}/{y}/assets` endpoints +* remove deprecated `/{searchid}/{z}/{x}/{y}/assets` endpoints +* remove `stac-pydantic` dependency +* replace Enum's with `Literal` types ## 0.4.1 (2023-06-21) diff --git a/pyproject.toml b/pyproject.toml index 9b9ef10..3ab714f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,8 +29,7 @@ classifiers = [ dependencies = [ "titiler.core>=0.12.0,<0.13", "titiler.mosaic>=0.12.0,<0.13", - "geojson-pydantic", - "stac-pydantic==2.0.*", + "geojson-pydantic~=0.6", "pydantic~=1.0", ] dynamic = ["version"] diff --git a/titiler/pgstac/model.py b/titiler/pgstac/model.py index 293cfb7..54764b2 100644 --- a/titiler/pgstac/model.py +++ b/titiler/pgstac/model.py @@ -4,70 +4,28 @@ Note: This is mostly a copy of https://github.com/stac-utils/stac-fastapi/blob/master/stac_fastapi/pgstac/stac_fastapi/pgstac/types/search.py """ -import operator from datetime import datetime -from enum import Enum, auto -from types import DynamicClassAttribute -from typing import Any, Callable, Dict, List, Optional, Union - -from geojson_pydantic.geometries import ( - LineString, - MultiLineString, - MultiPoint, - MultiPolygon, - Point, - Polygon, -) +from typing import Any, Dict, List, Literal, Optional + +from geojson_pydantic.geometries import Geometry +from geojson_pydantic.types import BBox from pydantic import BaseModel, Field, root_validator, validator -from stac_pydantic.shared import BBox -from stac_pydantic.utils import AutoValueEnum from titiler.core.resources.enums import MediaType +# TODO: add "startsWith", "endsWith", "contains", "in" +Operator = Literal["eq", "ne", "lt", "lte", "gt", "gte"] -class FilterLang(str, Enum): - """filter language. - - ref: https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#get-query-parameters-and-post-json-fields - """ - - cql_json = "cql-json" - cql_text = "cql-text" - cql2_json = "cql2-json" - - -class Operator(str, AutoValueEnum): - """Defines the set of operators supported by the API.""" +# ref: https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#get-query-parameters-and-post-json-fields +FilterLang = Literal["cql-json", "cql-text", "cql2-json"] - eq = auto() - ne = auto() - lt = auto() - lte = auto() - gt = auto() - gte = auto() - # TODO: These are defined in the spec but aren't currently implemented by the api - # startsWith = auto() - # endsWith = auto() - # contains = auto() - # in = auto() - - @DynamicClassAttribute - def operator(self) -> Callable[[Any, Any], bool]: - """Return python operator.""" - return getattr(operator, self._value_) - - -class SearchType(str, Enum): - """Search type.""" - - mosaic = "mosaic" - search = "search" +SearchType = Literal["mosaic", "search"] class Metadata(BaseModel): """Metadata Model.""" - type: SearchType = SearchType.mosaic + type: SearchType = "mosaic" # WGS84 bounds bounds: Optional[BBox] @@ -100,7 +58,6 @@ class Metadata(BaseModel): class Config: """Config for model.""" - use_enum_values = True extra = "allow" @@ -115,9 +72,7 @@ class PgSTACSearch(BaseModel): collections: Optional[List[str]] = None ids: Optional[List[str]] = None bbox: Optional[BBox] - intersects: Optional[ - Union[Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon] - ] + intersects: Optional[Geometry] query: Optional[Dict[str, Dict[Operator, Any]]] filter: Optional[Dict] datetime: Optional[str] = None @@ -202,7 +157,7 @@ class Search(BaseModel): def validate_metadata(cls, v): """Set SearchType.search when not present in metadata.""" if "type" not in v: - v["type"] = SearchType.search.name + v["type"] = "search" return v