Skip to content

Commit

Permalink
fix: relax constraint on pydantic
Browse files Browse the repository at this point in the history
This change allows DSI to be installed in environments alongside either
pydantic v1 or v2
  • Loading branch information
bernardcooke53 committed Dec 13, 2023
1 parent 5f84503 commit 04a5d4f
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Dependencies-20231213-113016.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Dependencies
body: Relax Pydantic dependency to allow DSI to be installed in environments alongside
Pydantic v1 or v2
time: 2023-12-13T11:30:16.376387Z
custom:
Author: bernardcooke53
PR: "227"
12 changes: 10 additions & 2 deletions dbt_semantic_interfaces/dataclass_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@
get_type_hints,
)

import pydantic
from pydantic import BaseModel
try:
import pydantic.v1 as pydantic
except (ImportError, ModuleNotFoundError):
import pydantic

try:
from pydantic.v1 import BaseModel # pydantic v2
except ModuleNotFoundError:
from pydantic import BaseModel # pydantic v1

from typing_extensions import TypeAlias

from dbt_semantic_interfaces.pretty_print import pformat_big_objects
Expand Down
5 changes: 4 additions & 1 deletion dbt_semantic_interfaces/implementations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from abc import ABC, abstractmethod
from typing import Any, Callable, ClassVar, Generator, Generic, Type, TypeVar

from pydantic import BaseModel, root_validator
try:
from pydantic.v1 import BaseModel, root_validator # pydantic v2
except ModuleNotFoundError:
from pydantic import BaseModel, root_validator # pydantic v1

from dbt_semantic_interfaces.errors import ParsingException
from dbt_semantic_interfaces.parsing.yaml_loader import (
Expand Down
6 changes: 5 additions & 1 deletion dbt_semantic_interfaces/implementations/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from typing import Optional

from pydantic import Field
try:
from pydantic.v1 import Field # pydantic v2
except ModuleNotFoundError:
from pydantic import Field # pydantic v1

from typing_extensions import override

from dbt_semantic_interfaces.implementations.base import HashableBaseModel
Expand Down
5 changes: 4 additions & 1 deletion dbt_semantic_interfaces/implementations/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from typing import List, Optional, Sequence

from pydantic import Field
try:
from pydantic.v1 import Field # pydantic v2
except ModuleNotFoundError:
from pydantic import Field # pydantic v1

from dbt_semantic_interfaces.enum_extension import assert_values_exhausted
from dbt_semantic_interfaces.errors import ParsingException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from typing import List, Optional

from importlib_metadata import version
from pydantic import validator

try:
from pydantic.v1 import validator # pydantic v2
except ModuleNotFoundError:
from pydantic import validator # pydantic v1

from typing_extensions import override

from dbt_semantic_interfaces.implementations.base import (
Expand Down
6 changes: 5 additions & 1 deletion dbt_semantic_interfaces/implementations/semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from typing import Any, List, Optional, Sequence

from pydantic import validator
try:
from pydantic.v1 import validator # pydantic v2
except ModuleNotFoundError:
from pydantic import validator # pydantic v1

from typing_extensions import override

from dbt_semantic_interfaces.implementations.base import (
Expand Down
6 changes: 5 additions & 1 deletion dbt_semantic_interfaces/validations/validator_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
)

import click
from pydantic import BaseModel, Extra

try:
from pydantic.v1 import BaseModel, Extra # pydantic v2
except ModuleNotFoundError:
from pydantic import BaseModel, Extra # pydantic v1

from dbt_semantic_interfaces.implementations.base import FrozenBaseModel
from dbt_semantic_interfaces.protocols import Metadata, SemanticManifestT, SemanticModel
Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[mypy]
plugins = pydantic.mypy

[mypy-pydantic.*]
ignore_missing_imports = True

[pydantic-mypy]
init_forbid_extra = True
init_typed = True
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"pydantic~=1.10",
"pydantic>=1.10,<3.0",
"jsonschema~=4.0",
"PyYAML~=6.0",
"more-itertools>=8.0,<11.0",
Expand Down

0 comments on commit 04a5d4f

Please sign in to comment.