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

feat: implement rdfproxy.ConfigDict for model config #160

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ The result set can be mapped to a nested Pydantic model like so:
from typing import Annotated

from fastapi import FastAPI, Query
from pydantic import BaseModel, ConfigDict
from rdfproxy import Page, QueryParameters, SPARQLBinding, SPARQLModelAdapter
from pydantic import BaseModel
from rdfproxy import ConfigDict, Page, QueryParameters, SPARQLBinding, SPARQLModelAdapter

class Work(BaseModel):
model_config = ConfigDict(group_by="name")
Expand Down
10 changes: 8 additions & 2 deletions examples/full_static_fastapi_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
from typing import Annotated

from fastapi import FastAPI, Query
from pydantic import BaseModel, ConfigDict
from rdfproxy import Page, QueryParameters, SPARQLBinding, SPARQLModelAdapter
from pydantic import BaseModel
from rdfproxy import (
ConfigDict,
Page,
QueryParameters,
SPARQLBinding,
SPARQLModelAdapter,
)


query = """
Expand Down
10 changes: 8 additions & 2 deletions examples/wikidata_grouped_person_fastapi_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
from typing import Annotated

from fastapi import FastAPI, Query
from pydantic import BaseModel, ConfigDict
from rdfproxy import Page, QueryParameters, SPARQLBinding, SPARQLModelAdapter
from pydantic import BaseModel
from rdfproxy import (
ConfigDict,
Page,
QueryParameters,
SPARQLBinding,
SPARQLModelAdapter,
)


query = """
Expand Down
2 changes: 1 addition & 1 deletion rdfproxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rdfproxy.adapter import SPARQLModelAdapter # noqa: F401
from rdfproxy.mapper import ModelBindingsMapper # noqa: F401
from rdfproxy.utils._types import SPARQLBinding # noqa: F401
from rdfproxy.utils._types import ConfigDict, SPARQLBinding # noqa: F401
from rdfproxy.utils.models import Page, QueryParameters # noqa: F401
9 changes: 8 additions & 1 deletion rdfproxy/utils/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections.abc import Iterable
from typing import Protocol, TypeAlias, TypeVar, runtime_checkable

from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict as PydanticConfigDict


_TModelInstance = TypeVar("_TModelInstance", bound=BaseModel)
Expand Down Expand Up @@ -42,3 +42,10 @@ def __call__(self, model: BaseModel) -> bool: ...


_TModelBoolValue: TypeAlias = ModelBoolPredicate | str | Iterable[str]


class ConfigDict(PydanticConfigDict, total=False):
"""pydantic.ConfigDict extension for RDFProxy model_config options."""

group_by: str
model_bool: _TModelBoolValue
3 changes: 2 additions & 1 deletion tests/data/models/author_array_collection_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Annotated

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel
from rdfproxy import ConfigDict
from rdfproxy.utils._types import SPARQLBinding


Expand Down
3 changes: 2 additions & 1 deletion tests/data/models/author_work_title_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from typing import Annotated

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel
from rdfproxy import ConfigDict
from rdfproxy.utils._types import SPARQLBinding


Expand Down
3 changes: 2 additions & 1 deletion tests/data/models/dummy_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Simple dummy models e.g. for count query constructor testing."""

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel
from rdfproxy import ConfigDict


class Dummy(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion tests/data/models/grouping_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Grouping model for RDFProxy testing."""

from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, Field
from rdfproxy import ConfigDict


class GroupingSimpleModel(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion tests/data/models/nested_grouping_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Nested grouping model for RDFProxy testing."""

from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, Field
from rdfproxy import ConfigDict


class NestedGroupingSimpleModel(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
The test cover all cases discussed in https://github.com/acdh-oeaw/rdfproxy/issues/110.
"""

from pydantic import BaseModel, ConfigDict, Field, create_model
from pydantic import BaseModel, Field, create_model
from rdfproxy import ConfigDict
from tests.utils._types import ModelBindingsMapperParameter


Expand Down
10 changes: 8 additions & 2 deletions tests/tests_adapter/test_adapter_grouped_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

import pytest

from pydantic import BaseModel, ConfigDict
from rdfproxy import Page, QueryParameters, SPARQLBinding, SPARQLModelAdapter
from pydantic import BaseModel
from rdfproxy import (
ConfigDict,
Page,
QueryParameters,
SPARQLBinding,
SPARQLModelAdapter,
)


binding_query = """
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_mapper/test_sad_path_mapper_grouped_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel
import pytest
from rdfproxy import ModelBindingsMapper
from rdfproxy import ConfigDict, ModelBindingsMapper
from rdfproxy.utils._exceptions import (
InvalidGroupingKeyException,
MissingModelConfigException,
Expand Down
Loading