From 917c2bf9376b720d0e4602b7d81561b3755bf910 Mon Sep 17 00:00:00 2001 From: Colton Loftus <70598503+C-Loftus@users.noreply.github.com> Date: Wed, 11 Jun 2025 15:23:24 -0400 Subject: [PATCH 1/6] typeBaseProvider --- pygeoapi/provider/base.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pygeoapi/provider/base.py b/pygeoapi/provider/base.py index 538c076a9..7166072f6 100644 --- a/pygeoapi/provider/base.py +++ b/pygeoapi/provider/base.py @@ -31,6 +31,7 @@ import logging from enum import Enum from http import HTTPStatus +from typing import Literal, Optional, TypedDict from pygeoapi.error import GenericError @@ -43,11 +44,16 @@ class SchemaType(Enum): update = 'update' replace = 'replace' +# Dict type representing a mapping of the field +# to its associated data type +FieldMapping = dict[ + str, dict[Literal["type"], Literal["number", "string", "integer"]] +] class BaseProvider: """generic Provider ABC""" - def __init__(self, provider_def): + def __init__(self, provider_def: dict): """ Initialize object @@ -73,7 +79,7 @@ def __init__(self, provider_def): self.title_field = provider_def.get('title_field') self.properties = provider_def.get('properties', []) self.file_types = provider_def.get('file_types', []) - self._fields = {} + self._fields: FieldMapping = {} self.filename = None # for coverage providers @@ -81,7 +87,7 @@ def __init__(self, provider_def): self.crs = None self.num_bands = None - def get_fields(self): + def get_fields(self) -> FieldMapping: """ Get provider field information (names, types) @@ -94,7 +100,7 @@ def get_fields(self): raise NotImplementedError() @property - def fields(self) -> dict: + def fields(self) -> FieldMapping: """ Store provider field information (names, types) @@ -110,7 +116,7 @@ def fields(self) -> dict: else: return self.get_fields() - def get_schema(self, schema_type: SchemaType = SchemaType.item): + def get_schema(self, schema_type: SchemaType = SchemaType.item) -> tuple: """ Get provider schema model @@ -122,7 +128,7 @@ def get_schema(self, schema_type: SchemaType = SchemaType.item): raise NotImplementedError() - def get_data_path(self, baseurl, urlpath, dirpath): + def get_data_path(self, baseurl: str , urlpath: str, dirpath: str) -> dict: """ Gets directory listing or file description or raw file dump @@ -145,7 +151,7 @@ def get_metadata(self): raise NotImplementedError() - def get_domains(self, properties=[], current=False): + def get_domains(self, properties: list[str] = [], current=False): """ Get domains from dataset @@ -168,7 +174,7 @@ def query(self): raise NotImplementedError() - def get(self, identifier, **kwargs): + def get(self, identifier: str, **kwargs): """ query the provider by id @@ -179,7 +185,7 @@ def get(self, identifier, **kwargs): raise NotImplementedError() - def create(self, item): + def create(self, item: dict) -> str: """ Create a new item @@ -190,7 +196,7 @@ def create(self, item): raise NotImplementedError() - def update(self, identifier, item): + def update(self, identifier: str, item: dict) -> bool: """ Updates an existing item @@ -202,7 +208,7 @@ def update(self, identifier, item): raise NotImplementedError() - def delete(self, identifier): + def delete(self, identifier: str) -> bool: """ Deletes an existing item @@ -213,7 +219,7 @@ def delete(self, identifier): raise NotImplementedError() - def _load_and_prepare_item(self, item, identifier=None, + def _load_and_prepare_item(self, item: str, identifier: Optional[str]=None, accept_missing_identifier=False, raise_if_exists=True): """ From 8efd88007e9dce4ba27d840fa25bb5ca8e1003f4 Mon Sep 17 00:00:00 2001 From: Colton Loftus <70598503+C-Loftus@users.noreply.github.com> Date: Wed, 11 Jun 2025 15:24:25 -0400 Subject: [PATCH 2/6] typeBaseProvider --- pygeoapi/provider/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygeoapi/provider/base.py b/pygeoapi/provider/base.py index 7166072f6..4a02f1a1f 100644 --- a/pygeoapi/provider/base.py +++ b/pygeoapi/provider/base.py @@ -44,7 +44,7 @@ class SchemaType(Enum): update = 'update' replace = 'replace' -# Dict type representing a mapping of the field +# Dict type representing a mapping of the field # to its associated data type FieldMapping = dict[ str, dict[Literal["type"], Literal["number", "string", "integer"]] From d9d6b72da79b072438121e313884c21e678e4a49 Mon Sep 17 00:00:00 2001 From: Colton Loftus <70598503+C-Loftus@users.noreply.github.com> Date: Wed, 11 Jun 2025 15:50:10 -0400 Subject: [PATCH 3/6] add all oaf properties --- pygeoapi/provider/base.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pygeoapi/provider/base.py b/pygeoapi/provider/base.py index 4a02f1a1f..7f662a1c9 100644 --- a/pygeoapi/provider/base.py +++ b/pygeoapi/provider/base.py @@ -31,7 +31,7 @@ import logging from enum import Enum from http import HTTPStatus -from typing import Literal, Optional, TypedDict +from typing import Literal, NotRequired, Optional, TypedDict from pygeoapi.error import GenericError @@ -46,9 +46,18 @@ class SchemaType(Enum): # Dict type representing a mapping of the field # to its associated data type -FieldMapping = dict[ - str, dict[Literal["type"], Literal["number", "string", "integer"]] -] +FieldMapping = TypedDict( + "FieldMapping", + { + "type": Literal["string", "number", "integer", "boolean", "object", "array"], + "title": str, + "description": str, + "format": NotRequired[str], + "x-ogc-unit": NotRequired[str], + "x-ogc-role": NotRequired[str], + "enum": NotRequired[list[str]], + }, +) class BaseProvider: """generic Provider ABC""" From 54d46a9417f307025b08372deee65f23dd35e80d Mon Sep 17 00:00:00 2001 From: Colton Loftus <70598503+C-Loftus@users.noreply.github.com> Date: Wed, 11 Jun 2025 15:50:36 -0400 Subject: [PATCH 4/6] add all oaf properties --- pygeoapi/provider/base.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pygeoapi/provider/base.py b/pygeoapi/provider/base.py index 7f662a1c9..12666f1b2 100644 --- a/pygeoapi/provider/base.py +++ b/pygeoapi/provider/base.py @@ -44,10 +44,10 @@ class SchemaType(Enum): update = 'update' replace = 'replace' -# Dict type representing a mapping of the field -# to its associated data type -FieldMapping = TypedDict( - "FieldMapping", +# All the potential properties on a field +# as defined by the OGC API features spec +FieldProperties = TypedDict( + "FieldProperties", { "type": Literal["string", "number", "integer", "boolean", "object", "array"], "title": str, @@ -59,6 +59,10 @@ class SchemaType(Enum): }, ) +# Dict type representing a mapping of the field +# to its associated data type +FieldMapping = dict[str, FieldProperties] + class BaseProvider: """generic Provider ABC""" From 9270daa2d2fd4d6710ca6b8391f8a11dc2640c16 Mon Sep 17 00:00:00 2001 From: Colton Loftus <70598503+C-Loftus@users.noreply.github.com> Date: Wed, 11 Jun 2025 16:27:36 -0400 Subject: [PATCH 5/6] fix not required import on old python version --- pygeoapi/provider/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pygeoapi/provider/base.py b/pygeoapi/provider/base.py index 12666f1b2..27c1854a3 100644 --- a/pygeoapi/provider/base.py +++ b/pygeoapi/provider/base.py @@ -31,7 +31,14 @@ import logging from enum import Enum from http import HTTPStatus -from typing import Literal, NotRequired, Optional, TypedDict +from typing import Literal, Optional, TypedDict +import sys + +if sys.version_info >= (3, 11): + from typing import NotRequired +else: + from typing_extensions import NotRequired + from pygeoapi.error import GenericError From f360b659fee4eee65ff220ddb08ff6e0475fab0f Mon Sep 17 00:00:00 2001 From: Colton Loftus <70598503+C-Loftus@users.noreply.github.com> Date: Wed, 11 Jun 2025 16:34:55 -0400 Subject: [PATCH 6/6] fix flake8 --- pygeoapi/provider/base.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pygeoapi/provider/base.py b/pygeoapi/provider/base.py index 27c1854a3..0374adfc9 100644 --- a/pygeoapi/provider/base.py +++ b/pygeoapi/provider/base.py @@ -51,12 +51,14 @@ class SchemaType(Enum): update = 'update' replace = 'replace' + # All the potential properties on a field # as defined by the OGC API features spec FieldProperties = TypedDict( "FieldProperties", { - "type": Literal["string", "number", "integer", "boolean", "object", "array"], + "type": Literal["string", "number", "integer", + "boolean", "object", "array"], "title": str, "description": str, "format": NotRequired[str], @@ -66,10 +68,12 @@ class SchemaType(Enum): }, ) + # Dict type representing a mapping of the field # to its associated data type FieldMapping = dict[str, FieldProperties] + class BaseProvider: """generic Provider ABC""" @@ -148,7 +152,7 @@ def get_schema(self, schema_type: SchemaType = SchemaType.item) -> tuple: raise NotImplementedError() - def get_data_path(self, baseurl: str , urlpath: str, dirpath: str) -> dict: + def get_data_path(self, baseurl: str, urlpath: str, dirpath: str) -> dict: """ Gets directory listing or file description or raw file dump @@ -239,7 +243,8 @@ def delete(self, identifier: str) -> bool: raise NotImplementedError() - def _load_and_prepare_item(self, item: str, identifier: Optional[str]=None, + def _load_and_prepare_item(self, item: str, + identifier: Optional[str] = None, accept_missing_identifier=False, raise_if_exists=True): """