Skip to content

Commit

Permalink
Add pydantic v2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Jan 21, 2024
1 parent 1b06bc9 commit f94d741
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 516 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### [0.4.1] - Unreleased
- Added `credentials`-field
- Updated dependencies
- Add pydantic v2 compatibility

### [0.4.0] - 2022-11-24
- Added test for error on extra fields
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### [0.4.1] - Unreleased
- Added `credentials`-field
- Updated dependencies
- Add pydantic v2 compatibility

### [0.4.0] - 2022-11-24
- Added test for error on extra fields
Expand Down
10 changes: 7 additions & 3 deletions iscc_schema/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# -*- coding: utf-8 -*-
import json

import jcs
from pydantic import BaseModel as OriginalBaseModel
from pydantic import root_validator

try:
from pydantic.v1 import BaseModel as OriginalBaseModel
from pydantic.v1 import root_validator
except ImportError:
from pydantic import BaseModel as OriginalBaseModel
from pydantic import root_validator


class BaseModel(OriginalBaseModel):
Expand Down
9 changes: 7 additions & 2 deletions iscc_schema/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
import re
from re import Pattern
from typing import Dict, Any, cast
from pydantic.utils import update_not_none
from pydantic.validators import constr_length_validator

try:
from pydantic.v1.utils import update_not_none
from pydantic.v1.validators import constr_length_validator
except ImportError:
from pydantic.utils import update_not_none
from pydantic.validators import constr_length_validator


class RFC3986Regex:
Expand Down
9 changes: 4 additions & 5 deletions iscc_schema/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from enum import Enum
from typing import Any, Dict, List, Optional

from pydantic import Field
try:
from pydantic.v1 import Field
except ImportError:
from pydantic import Field
from iscc_schema.fields import AnyUrl
from iscc_schema.base import BaseModel

Expand Down Expand Up @@ -547,16 +550,12 @@ class NftFreezePostRequest(BaseModel):
Any JSON object that can be serialized with JCS canonicaliztion.
"""

pass


class MediaEmbeddedMetadata(IsccExtraMetadata, IsccBasicMetadata):
"""
Media Metadata
"""

pass


class IsccCodePostRequest(MediaEmbeddedMetadata, MediaUpload):
pass
7 changes: 4 additions & 3 deletions iscc_schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from enum import Enum
from typing import Any, Dict, List, Optional, Union

from pydantic import Field
try:
from pydantic.v1 import Field
except ImportError:
from pydantic import Field
from iscc_schema.fields import AnyUrl
from iscc_schema.base import BaseModel

Expand Down Expand Up @@ -541,5 +544,3 @@ class IsccMeta(
"""
ISCC Metadata Schema
"""

pass
Loading

0 comments on commit f94d741

Please sign in to comment.