From 07c890e254e8cbcae0b251ba020e8496510d2525 Mon Sep 17 00:00:00 2001 From: Vincent Sarago Date: Thu, 6 Jun 2024 13:10:32 +0200 Subject: [PATCH] move filter client from types to extensions (#704) * move filter client from types to extensions * update changelog --- CHANGES.md | 4 + .../extensions/core/filter/client.py | 58 +++++++++++++++ .../extensions/core/filter/filter.py | 2 +- stac_fastapi/types/stac_fastapi/types/core.py | 74 ++++++------------- 4 files changed, 87 insertions(+), 51 deletions(-) create mode 100644 stac_fastapi/extensions/stac_fastapi/extensions/core/filter/client.py diff --git a/CHANGES.md b/CHANGES.md index b804733f..a75f1da8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,10 @@ ## [Unreleased] - TBD +### Changed + +* moved `AsyncBaseFiltersClient` and `BaseFiltersClient` classes in `stac_fastapi.extensions.core.filter.client` submodule ([#704](https://github.com/stac-utils/stac-fastapi/pull/704)) + ## [3.0.0a2] - 2024-05-31 ### Fixed diff --git a/stac_fastapi/extensions/stac_fastapi/extensions/core/filter/client.py b/stac_fastapi/extensions/stac_fastapi/extensions/core/filter/client.py new file mode 100644 index 00000000..03ef9661 --- /dev/null +++ b/stac_fastapi/extensions/stac_fastapi/extensions/core/filter/client.py @@ -0,0 +1,58 @@ +"""Filter extensions clients.""" + +import abc +from typing import Any, Dict, Optional + +import attr + + +@attr.s +class AsyncBaseFiltersClient(abc.ABC): + """Defines a pattern for implementing the STAC filter extension.""" + + async def get_queryables( + self, collection_id: Optional[str] = None, **kwargs + ) -> Dict[str, Any]: + """Get the queryables available for the given collection_id. + + If collection_id is None, returns the intersection of all queryables over all + collections. + + This base implementation returns a blank queryable schema. This is not allowed + under OGC CQL but it is allowed by the STAC API Filter Extension + https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#queryables + """ + return { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.org/queryables", + "type": "object", + "title": "Queryables for Example STAC API", + "description": "Queryable names for the example STAC API Item Search filter.", + "properties": {}, + } + + +@attr.s +class BaseFiltersClient(abc.ABC): + """Defines a pattern for implementing the STAC filter extension.""" + + def get_queryables( + self, collection_id: Optional[str] = None, **kwargs + ) -> Dict[str, Any]: + """Get the queryables available for the given collection_id. + + If collection_id is None, returns the intersection of all queryables over all + collections. + + This base implementation returns a blank queryable schema. This is not allowed + under OGC CQL but it is allowed by the STAC API Filter Extension + https://github.com/stac-api-extensions/filter#queryables + """ + return { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.org/queryables", + "type": "object", + "title": "Queryables for Example STAC API", + "description": "Queryable names for the example STAC API Item Search filter.", + "properties": {}, + } diff --git a/stac_fastapi/extensions/stac_fastapi/extensions/core/filter/filter.py b/stac_fastapi/extensions/stac_fastapi/extensions/core/filter/filter.py index 0ebc3f9c..cd9463ec 100644 --- a/stac_fastapi/extensions/stac_fastapi/extensions/core/filter/filter.py +++ b/stac_fastapi/extensions/stac_fastapi/extensions/core/filter/filter.py @@ -9,9 +9,9 @@ from stac_fastapi.api.models import CollectionUri, EmptyRequest, JSONSchemaResponse from stac_fastapi.api.routes import create_async_endpoint -from stac_fastapi.types.core import AsyncBaseFiltersClient, BaseFiltersClient from stac_fastapi.types.extension import ApiExtension +from .client import AsyncBaseFiltersClient, BaseFiltersClient from .request import FilterExtensionGetRequest, FilterExtensionPostRequest diff --git a/stac_fastapi/types/stac_fastapi/types/core.py b/stac_fastapi/types/stac_fastapi/types/core.py index b665d3dc..4cdda49e 100644 --- a/stac_fastapi/types/stac_fastapi/types/core.py +++ b/stac_fastapi/types/stac_fastapi/types/core.py @@ -1,7 +1,8 @@ """Base clients.""" - import abc +import importlib +import warnings from typing import Any, Dict, List, Optional, Union from urllib.parse import urljoin @@ -22,6 +23,16 @@ from stac_fastapi.types.rfc3339 import DateTimeType from stac_fastapi.types.search import BaseSearchPostRequest +__all__ = [ + "NumType", + "StacType", + "BaseTransactionsClient", + "AsyncBaseTransactionsClient", + "LandingPageMixin", + "BaseCoreClient", + "AsyncBaseCoreClient", +] + NumType = Union[float, int] StacType = Dict[str, Any] @@ -737,53 +748,16 @@ async def item_collection( ... -@attr.s -class AsyncBaseFiltersClient(abc.ABC): - """Defines a pattern for implementing the STAC filter extension.""" - - async def get_queryables( - self, collection_id: Optional[str] = None, **kwargs - ) -> Dict[str, Any]: - """Get the queryables available for the given collection_id. - - If collection_id is None, returns the intersection of all queryables over all - collections. - - This base implementation returns a blank queryable schema. This is not allowed - under OGC CQL but it is allowed by the STAC API Filter Extension - https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#queryables - """ - return { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.org/queryables", - "type": "object", - "title": "Queryables for Example STAC API", - "description": "Queryable names for the example STAC API Item Search filter.", - "properties": {}, - } - - -@attr.s -class BaseFiltersClient(abc.ABC): - """Defines a pattern for implementing the STAC filter extension.""" - - def get_queryables( - self, collection_id: Optional[str] = None, **kwargs - ) -> Dict[str, Any]: - """Get the queryables available for the given collection_id. - - If collection_id is None, returns the intersection of all queryables over all - collections. +# TODO: remove for 3.0.0 final release +def __getattr__(name: str) -> Any: + if name in ["AsyncBaseFiltersClient", "BaseFiltersClient"]: + warnings.warn( + f"""importing {name} from `stac_fastapi.types.core` is deprecated, + please import it from `stac_fastapi.extensions.core.filter.client`.""", + DeprecationWarning, + stacklevel=2, + ) + clients = importlib.import_module("stac_fastapi.extensions.core.filter.client") + return getattr(clients, name) - This base implementation returns a blank queryable schema. This is not allowed - under OGC CQL but it is allowed by the STAC API Filter Extension - https://github.com/stac-api-extensions/filter#queryables - """ - return { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.org/queryables", - "type": "object", - "title": "Queryables for Example STAC API", - "description": "Queryable names for the example STAC API Item Search filter.", - "properties": {}, - } + raise AttributeError(f"module {__name__} has no attribute {name}")