python311Packages.aiopurpleair: apply patch for pydantic>=2

This commit is contained in:
natsukium 2023-11-29 14:19:33 +09:00 committed by Martin Weinelt
parent 2a930da0f4
commit da45c80e1f
No known key found for this signature in database
GPG key ID: 87C1E9888F856759
2 changed files with 114 additions and 0 deletions

View file

@ -38,6 +38,9 @@ buildPythonPackage rec {
url = "https://github.com/bachya/aiopurpleair/commit/8c704c51ea50da266f52a7f53198d29d643b30c5.patch";
hash = "sha256-RLRbHmaR2A8MNc96WHx0L8ccyygoBUaOulAuRJkFuUM=";
})
# based on https://github.com/bachya/aiopurpleair/pull/176
./pydantic_2-compatibility.patch
];
postPatch = ''

View file

@ -0,0 +1,111 @@
diff --git a/aiopurpleair/api.py b/aiopurpleair/api.py
index d3b276b..c557015 100644
--- a/aiopurpleair/api.py
+++ b/aiopurpleair/api.py
@@ -5,7 +5,10 @@ from typing import Any, cast
from aiohttp import ClientSession, ClientTimeout
from aiohttp.client_exceptions import ClientError
-from pydantic import BaseModel, ValidationError
+try:
+ from pydantic.v1 import BaseModel, ValidationError
+except ModuleNotFoundError:
+ from pydantic import BaseModel, ValidationError
from aiopurpleair.const import LOGGER
from aiopurpleair.endpoints.sensors import SensorsEndpoints
diff --git a/aiopurpleair/endpoints/__init__.py b/aiopurpleair/endpoints/__init__.py
index 4d263e1..6632310 100644
--- a/aiopurpleair/endpoints/__init__.py
+++ b/aiopurpleair/endpoints/__init__.py
@@ -4,7 +4,10 @@ from __future__ import annotations
from collections.abc import Awaitable, Callable, Iterable
from typing import Any
-from pydantic import BaseModel, ValidationError
+try:
+ from pydantic.v1 import BaseModel, ValidationError
+except ModuleNotFoundError:
+ from pydantic import BaseModel, ValidationError
from aiopurpleair.errors import InvalidRequestError
from aiopurpleair.helpers.typing import ModelT
diff --git a/aiopurpleair/helpers/typing.py b/aiopurpleair/helpers/typing.py
index 4ae01e6..49f59e6 100644
--- a/aiopurpleair/helpers/typing.py
+++ b/aiopurpleair/helpers/typing.py
@@ -1,6 +1,9 @@
"""Define typing helpers."""
from typing import TypeVar
-from pydantic import BaseModel
+try:
+ from pydantic.v1 import BaseModel
+except ModuleNotFoundError:
+ from pydantic import BaseModel
ModelT = TypeVar("ModelT", bound=BaseModel)
diff --git a/aiopurpleair/models/keys.py b/aiopurpleair/models/keys.py
index 591ae01..ffadbcc 100644
--- a/aiopurpleair/models/keys.py
+++ b/aiopurpleair/models/keys.py
@@ -3,7 +3,10 @@ from __future__ import annotations
from datetime import datetime
-from pydantic import BaseModel, validator
+try:
+ from pydantic.v1 import BaseModel, validator
+except ModuleNotFoundError:
+ from pydantic import BaseModel, validator
from aiopurpleair.backports.enum import StrEnum
from aiopurpleair.helpers.validators import validate_timestamp
diff --git a/aiopurpleair/models/sensors.py b/aiopurpleair/models/sensors.py
index 5b99b51..d435996 100644
--- a/aiopurpleair/models/sensors.py
+++ b/aiopurpleair/models/sensors.py
@@ -5,7 +5,10 @@ from __future__ import annotations
from datetime import datetime
from typing import Any, Optional
-from pydantic import BaseModel, root_validator, validator
+try:
+ from pydantic.v1 import BaseModel, root_validator, validator
+except ModuleNotFoundError:
+ from pydantic import BaseModel, root_validator, validator
from aiopurpleair.const import SENSOR_FIELDS, ChannelFlag, ChannelState, LocationType
from aiopurpleair.helpers.validators import validate_timestamp
diff --git a/tests/models/test_keys.py b/tests/models/test_keys.py
index 0d7d7c8..b2e30c1 100644
--- a/tests/models/test_keys.py
+++ b/tests/models/test_keys.py
@@ -5,7 +5,10 @@ from datetime import datetime
from typing import Any
import pytest
-from pydantic import ValidationError
+try:
+ from pydantic.v1 import ValidationError
+except ModuleNotFoundError:
+ from pydantic import ValidationError
from aiopurpleair.models.keys import ApiKeyType, GetKeysResponse
diff --git a/tests/models/test_sensors.py b/tests/models/test_sensors.py
index a984b36..7b2c84f 100644
--- a/tests/models/test_sensors.py
+++ b/tests/models/test_sensors.py
@@ -5,7 +5,10 @@ from datetime import datetime
from typing import Any
import pytest
-from pydantic import ValidationError
+try:
+ from pydantic.v1 import ValidationError
+except ModuleNotFoundError:
+ from pydantic import ValidationError
from aiopurpleair.models.sensors import (
GetSensorsRequest,