Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update requirements #222

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ services:
image: pc-apis-tiler-dev
# For Mac OS M1 user, you'll need to add `platform: linux/amd64`.
# see https://github.com/developmentseed/titiler/discussions/387#discussioncomment-1643110
# platform: linux/amd64
platform: linux/amd64
build:
context: .
dockerfile: pctiler/Dockerfile.dev
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
image: pc-apis-tiler
# For Mac OS M1 user, you'll need to add `platform: linux/amd64`.
# see https://github.com/developmentseed/titiler/discussions/387#discussioncomment-1643110
# platform: linux/amd64
platform: linux/amd64
build:
context: .
dockerfile: pctiler/Dockerfile
Expand Down
41 changes: 17 additions & 24 deletions pccommon/pccommon/config/collections.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from enum import Enum
from typing import Any, Dict, List, Optional, Tuple

import orjson
from humps import camelize
from pydantic import BaseModel, Field

from pccommon.tables import ModelTableService
from pccommon.utils import get_param_str, orjson_dumps
from pccommon.utils import get_param_str


class RenderOptionType(str, Enum):
Expand All @@ -19,11 +18,13 @@ def __str__(self) -> str:


class CamelModel(BaseModel):
class Config:
alias_generator = camelize
allow_population_by_field_name = True
json_loads = orjson.loads
json_dumps = orjson_dumps

model_config = {
# TODO, see if we can use pydantic native function
# https://docs.pydantic.dev/latest/api/config/#pydantic.alias_generators.to_camel
"alias_generator": camelize,
"populate_by_name": True,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO



class VectorTileset(CamelModel):
Expand Down Expand Up @@ -137,10 +138,6 @@ def should_add_collection_links(self) -> bool:
def should_add_item_links(self) -> bool:
return self.create_links and (not self.hidden)

class Config:
json_loads = orjson.loads
json_dumps = orjson_dumps


class Mosaics(CamelModel):
"""
Expand Down Expand Up @@ -187,11 +184,11 @@ class LegendConfig(CamelModel):
showing legend labels as scaled values.
"""

type: Optional[str]
labels: Optional[List[str]]
trim_start: Optional[int]
trim_end: Optional[int]
scale_factor: Optional[float]
type: Optional[str] = None
labels: Optional[List[str]] = None
trim_start: Optional[int] = None
trim_end: Optional[int] = None
scale_factor: Optional[float] = None


class VectorTileOptions(CamelModel):
Expand All @@ -216,10 +213,10 @@ class VectorTileOptions(CamelModel):

tilejson_key: str
source_layer: str
fill_color: Optional[str]
stroke_color: Optional[str]
stroke_width: Optional[int]
filter: Optional[List[Any]]
fill_color: Optional[str] = None
stroke_color: Optional[str] = None
stroke_width: Optional[int] = None
filter: Optional[List[Any]] = None


class RenderOptionCondition(CamelModel):
Expand Down Expand Up @@ -329,10 +326,6 @@ class CollectionConfig(BaseModel):
render_config: DefaultRenderConfig
mosaic_info: MosaicInfo

class Config:
json_loads = orjson.loads
json_dumps = orjson_dumps


class CollectionConfigTable(ModelTableService[CollectionConfig]):
_model = CollectionConfig
Expand Down
12 changes: 7 additions & 5 deletions pccommon/pccommon/config/containers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from typing import Optional

import orjson
from pydantic import BaseModel

from pccommon.tables import ModelTableService
from pccommon.utils import orjson_dumps


class ContainerConfig(BaseModel):
has_cdn: bool = False

class Config:
json_loads = orjson.loads
json_dumps = orjson_dumps
# json_loads/json_dumps config have been removed
# the authors seems to indicate that parsing/serialization
# in Rust (pydantic-core) is fast (but maybe not as fast as orjson)
# https://github.com/pydantic/pydantic/discussions/6388
# class Config:
# json_loads = orjson.loads
# json_dumps = orjson_dumps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't customize this with pydantic 2 but it seems that pydantic 2 is faster anyway



class ContainerConfigTable(ModelTableService[ContainerConfig]):
Expand Down
18 changes: 11 additions & 7 deletions pccommon/pccommon/config/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from cachetools import Cache, LRUCache, cachedmethod
from cachetools.func import lru_cache
from cachetools.keys import hashkey
from pydantic import BaseModel, BaseSettings, Field, PrivateAttr

from pydantic import BaseModel, Field, PrivateAttr
from pydantic_settings import BaseSettings
from pccommon.config.collections import CollectionConfigTable
from pccommon.config.containers import ContainerConfigTable
from pccommon.constants import DEFAULT_TTL
Expand Down Expand Up @@ -46,6 +46,15 @@ class PCAPIsConfig(BaseSettings):

debug: bool = False

model_config = {
"env_prefix": ENV_VAR_PCAPIS_PREFIX,
"env_nested_delimiter": "__",
# Mypi is complaining about this with
# error: Incompatible types (expression has type "str",
# TypedDict item "extra" has type "Extra")
"extra": "ignore", # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: remove type: ignore and see if this pass in the CI

}

@cachedmethod(cache=lambda self: self._cache, key=lambda _: hashkey("collection"))
def get_collection_config_table(self) -> CollectionConfigTable:
return CollectionConfigTable.from_account_key(
Expand Down Expand Up @@ -80,8 +89,3 @@ def get_ip_exception_list_table(self) -> IPExceptionListTable:
@lru_cache(maxsize=1)
def from_environment(cls) -> "PCAPIsConfig":
return PCAPIsConfig() # type: ignore

class Config:
env_prefix = ENV_VAR_PCAPIS_PREFIX
extra = "ignore"
env_nested_delimiter = "__"
4 changes: 3 additions & 1 deletion pccommon/pccommon/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class TableError(Exception):
pass


# TODO: mypy is complaining locally about
# "BaseModel" has no attribute "model_dump_json"
def encode_model(m: BaseModel) -> str:
return m.json()
return m.model_dump_json() # type: ignore


def decode_dict(s: str) -> Dict[str, Any]:
Expand Down
3 changes: 1 addition & 2 deletions pccommon/pccommon/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
from typing import List, Optional, Tuple, Union, cast

import fastapi
from fastapi import Request
from opencensus.ext.azure.trace_exporter import AzureExporter
from opencensus.trace import execution_context
Expand Down Expand Up @@ -211,7 +210,7 @@ def _iter_cql(cql: dict, property_name: str) -> Optional[Union[str, List[str]]]:
return None


def add_stac_attributes_from_search(search_json: str, request: fastapi.Request) -> None:
def add_stac_attributes_from_search(search_json: str, request: Request) -> None:
"""
Try to add the Collection ID and Item ID from a search to the current span.
"""
Expand Down
61 changes: 38 additions & 23 deletions pccommon/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#
# pip-compile --extra=server --output-file=pccommon/requirements.txt ./pccommon/setup.py
#
anyio==4.3.0
annotated-types==0.7.0
# via pydantic
anyio==4.4.0
# via starlette
async-timeout==4.0.3
# via redis
azure-core==1.30.1
azure-core==1.30.2
# via
# azure-data-tables
# azure-identity
Expand All @@ -28,27 +30,27 @@ cachetools==5.3.3
# via
# google-auth
# pccommon (pccommon/setup.py)
certifi==2024.2.2
certifi==2024.6.2
# via requests
cffi==1.16.0
# via cryptography
charset-normalizer==3.3.2
# via requests
cryptography==42.0.5
cryptography==42.0.8
# via
# azure-identity
# azure-storage-blob
# msal
# pyjwt
exceptiongroup==1.2.0
exceptiongroup==1.2.1
# via anyio
fastapi==0.90.1
fastapi-slim==0.111.0
# via pccommon (pccommon/setup.py)
google-api-core==2.18.0
google-api-core==2.19.0
# via opencensus
google-auth==2.29.0
google-auth==2.30.0
# via google-api-core
googleapis-common-protos==1.63.0
googleapis-common-protos==1.63.1
# via google-api-core
html-sanitizer==2.4.4
# via pccommon (pccommon/setup.py)
Expand All @@ -62,19 +64,19 @@ isodate==0.6.1
# via
# azure-data-tables
# azure-storage-blob
lxml==5.2.1
lxml==5.2.2
# via
# html-sanitizer
# lxml-html-clean
lxml-html-clean==0.1.0
# via
# html-sanitizer
# pccommon (pccommon/setup.py)
msal==1.28.0
msal==1.28.1
# via
# azure-identity
# msal-extensions
msal-extensions==0.3.1
msal-extensions==1.1.0
# via azure-identity
multidict==6.0.5
# via yarl
Expand All @@ -88,8 +90,10 @@ opencensus-ext-azure==1.1.13
# via pccommon (pccommon/setup.py)
opencensus-ext-logging==0.1.1
# via pccommon (pccommon/setup.py)
orjson==3.10.4
orjson==3.10.5
# via pccommon (pccommon/setup.py)
packaging==24.1
# via msal-extensions
portalocker==2.8.2
# via msal-extensions
proto-plus==1.23.0
Expand All @@ -101,22 +105,31 @@ protobuf==4.25.3
# proto-plus
psutil==5.9.8
# via opencensus-ext-azure
pyasn1==0.5.1
pyasn1==0.6.0
# via
# pyasn1-modules
# rsa
pyasn1-modules==0.3.0
pyasn1-modules==0.4.0
# via google-auth
pycparser==2.21
pycparser==2.22
# via cffi
pydantic==1.10.14
pydantic==2.7.4
# via
# fastapi
# fastapi-slim
# pccommon (pccommon/setup.py)
# pydantic-settings
pydantic-core==2.18.4
# via pydantic
pydantic-settings==2.3.3
# via pccommon (pccommon/setup.py)
pyhumps==3.5.3
# via pccommon (pccommon/setup.py)
pyjwt[crypto]==2.8.0
# via msal
# via
# msal
# pyjwt
python-dotenv==1.0.1
# via pydantic-settings
redis==4.6.0
# via pccommon (pccommon/setup.py)
requests==2.32.3
Expand All @@ -137,21 +150,23 @@ sniffio==1.3.1
# via anyio
soupsieve==2.5
# via beautifulsoup4
starlette==0.22.0
starlette==0.37.2
# via
# fastapi
# fastapi-slim
# pccommon (pccommon/setup.py)
types-cachetools==4.2.9
# via pccommon (pccommon/setup.py)
typing-extensions==4.10.0
typing-extensions==4.12.2
# via
# anyio
# azure-core
# azure-data-tables
# azure-storage-blob
# fastapi-slim
# pydantic
# pydantic-core
# starlette
urllib3==2.2.1
urllib3==2.2.2
# via
# pccommon (pccommon/setup.py)
# requests
Expand Down
7 changes: 4 additions & 3 deletions pccommon/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

# Runtime requirements.
inst_reqs = [
"fastapi==0.90.1",
"starlette>=0.22.0,<0.23.0",
"fastapi-slim==0.111.0",
"starlette>=0.37.2,<0.38.0",
"opencensus-ext-azure==1.1.13",
"opencensus-ext-logging==0.1.1",
"orjson>=3.10.4",
"azure-identity==1.16.1",
"azure-data-tables==12.5.0",
"azure-storage-blob>=12.20.0",
"pydantic>=1.10, <2.0.0",
"pydantic>=2.7,<2.8.0",
"pydantic-settings>=2.3,<2.4",
"cachetools~=5.3",
"types-cachetools==4.2.9",
"pyhumps==3.5.3",
Expand Down
12 changes: 0 additions & 12 deletions pcstac/pcstac/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ class PCClient(CoreCrudClient):

extra_conformance_classes: List[str] = attr.ib(factory=list)

def conformance_classes(self) -> List[str]:
"""Generate conformance classes list."""
base_conformance_classes = self.base_conformance_classes.copy()

for extension in self.extensions:
extension_classes = getattr(extension, "conformance_classes", [])
base_conformance_classes.extend(extension_classes)

base_conformance_classes.extend(self.extra_conformance_classes)

return sorted(list(set(base_conformance_classes)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def inject_collection_extras(
self,
collection: Collection,
Expand Down
Loading
Loading