Skip to content

Commit

Permalink
Support both pydantic v1 and v2
Browse files Browse the repository at this point in the history
  • Loading branch information
thesadru authored Jul 5, 2023
1 parent a261c2b commit a1ec09c
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 21 deletions.
8 changes: 7 additions & 1 deletion genshin/models/genshin/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import collections
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import Aliased, APIModel, Unique

Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import re
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import APIModel, Unique

Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/chronicle/abyss.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import datetime
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.genshin import character
from genshin.models.model import Aliased, APIModel
Expand Down
13 changes: 11 additions & 2 deletions genshin/models/genshin/chronicle/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
import re
import typing

import pydantic.v1 as pydantic
import pydantic.v1.generics as pydantic_generics
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
import pydantic.v1.generics as pydantic_generics
else:
try:
import pydantic.v1 as pydantic
import pydantic.v1.generics as pydantic_generics
except ImportError:
import pydantic
import pydantic.generics as pydantic_generics


from genshin.models.genshin import character
from genshin.models.model import Aliased, APIModel
Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/chronicle/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.genshin import character
from genshin.models.model import Aliased, APIModel, Unique
Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/chronicle/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
import datetime
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import Aliased, APIModel

Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/chronicle/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import re
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models import hoyolab
from genshin.models.model import Aliased, APIModel
Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/chronicle/tcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import enum
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import Aliased, APIModel, Unique

Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/gacha.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import re
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import Aliased, APIModel, Unique

Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/lineup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import datetime
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.genshin import character
from genshin.models.model import Aliased, APIModel, Unique
Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/teapot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import datetime
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import Aliased, APIModel, Unique

Expand Down
8 changes: 7 additions & 1 deletion genshin/models/genshin/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import typing
import unicodedata

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import Aliased, APIModel, Unique

Expand Down
8 changes: 7 additions & 1 deletion genshin/models/honkai/battlesuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import re
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import Aliased, APIModel, Unique

Expand Down
8 changes: 7 additions & 1 deletion genshin/models/honkai/chronicle/battlesuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
import re
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.honkai import battlesuit
from genshin.models.model import Aliased, APIModel, Unique
Expand Down
8 changes: 7 additions & 1 deletion genshin/models/honkai/chronicle/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
import re
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.honkai import battlesuit
from genshin.models.model import Aliased, APIModel, Unique
Expand Down
8 changes: 7 additions & 1 deletion genshin/models/honkai/chronicle/stats.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"""Honkai stats models."""
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models import hoyolab
from genshin.models.model import Aliased, APIModel
Expand Down
8 changes: 7 additions & 1 deletion genshin/models/hoyolab/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
import re
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin import types
from genshin.models.model import Aliased, APIModel, Unique
Expand Down
8 changes: 7 additions & 1 deletion genshin/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
import types
import typing

import pydantic.v1 as pydantic
if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

import genshin.constants as genshin_constants

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiohttp
pydantic==2.*
pydantic

# subdependencies
yarl
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
packages=find_packages(exclude=["tests.*"]),
python_requires=">=3.8",
install_requires=["aiohttp", "pydantic==2.*"],
install_requires=["aiohttp", "pydantic"],
extras_require={
"all": ["browser-cookie3", "rsa", "click"],
"cookies": ["browser-cookie3"],
Expand Down

0 comments on commit a1ec09c

Please sign in to comment.