Skip to content

Commit

Permalink
temporarily fix all pydantic warnings by using v1
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed Oct 1, 2023
1 parent 8c6f2fd commit e058e3e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ repos:
- "--paths=belay"
- "--deps-file=pyproject.toml"
- "--sections=tool.poetry.dependencies"
- "--exclude-deps=importlib_resources"
- "--exclude-deps"
- "importlib_resources"
- "pydantic"

- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
Expand Down
8 changes: 6 additions & 2 deletions belay/packagemanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from pathlib import Path
from typing import Dict, List, Optional

from pydantic import BaseModel as PydanticBaseModel
from pydantic import validator
try:
from pydantic.v1 import BaseModel as PydanticBaseModel
from pydantic.v1 import validator
except ImportError:
from pydantic import BaseModel as PydanticBaseModel
from pydantic import validator

validator_reuse = partial(validator, allow_reuse=True)
prevalidator_reuse = partial(validator_reuse, pre=True)
Expand Down
5 changes: 4 additions & 1 deletion belay/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
from threading import Lock, Thread
from typing import Union

from pydantic import ValidationError
try:
from pydantic.v1.error_wrappers import ValidationError
except ImportError:
from pydantic import ValidationError

from .exceptions import BelayException, ConnectionFailedError, DeviceNotFoundError
from .usb_specifier import UsbSpecifier
Expand Down
6 changes: 5 additions & 1 deletion belay/usb_specifier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Dict, List, Optional

from pydantic import BaseModel, Field
try:
from pydantic.v1 import BaseModel, Field
except ImportError:
from pydantic import BaseModel, Field

from serial.tools.list_ports import comports

from .exceptions import DeviceNotFoundError, InsufficientSpecifierError
Expand Down
7 changes: 6 additions & 1 deletion tests/packagemanager/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

from belay.packagemanager import GroupConfig

try:
from pydantic.v1.error_wrappers import ValidationError
except ImportError:
from pydantic import ValidationError


def test_group_config_multiple_rename_to_init():
dependencies = {
Expand All @@ -11,5 +16,5 @@ def test_group_config_multiple_rename_to_init():
{"uri": "bar", "rename_to_init": True},
]
}
with pytest.raises(pydantic.ValidationError):
with pytest.raises(ValidationError):
GroupConfig(dependencies=dependencies)
14 changes: 10 additions & 4 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
"""


from importlib.machinery import SourceFileLoader

import types
import pytest

from importlib.machinery import SourceFileLoader

import belay.inspect


@pytest.fixture
def foo(data_path):
fn = data_path / "foo.py"
foo = SourceFileLoader("foo", str(fn)).load_module()
assert foo.__file__ == str(fn)
module_name = "foo"
# Create a new module object
foo = types.ModuleType(module_name)
foo.__file__ = str(fn)
# Load the source file into the module object
loader = SourceFileLoader(module_name, str(fn))
loader.exec_module(foo)
return foo


Expand Down
7 changes: 6 additions & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from belay.packagemanager import Group
from belay.project import find_pyproject, load_groups, load_pyproject, load_toml

try:
from pydantic.v1.error_wrappers import ValidationError
except ImportError:
from pydantic import ValidationError


@pytest.fixture
def toml_file_standard(tmp_path):
Expand Down Expand Up @@ -77,7 +82,7 @@ def test_load_dependency_groups_main_group(mock_load_toml):
},
},
}
with pytest.raises(pydantic.ValidationError):
with pytest.raises(ValidationError):
load_groups()


Expand Down

0 comments on commit e058e3e

Please sign in to comment.