Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Pydantic v1 API from v2 #27

Merged
merged 5 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ defaults:

jobs:
test:
name: Test on ${{ matrix.os }}, Python ${{ matrix.python-version }}, OpenMM ${{ matrix.openmm }}
name: Test on ${{ matrix.os }}, Python ${{ matrix.python-version }}, OpenMM ${{ matrix.openmm }}, Pydantic ${{ matrix.pydantic-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macOS-latest, ubuntu-latest]
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9", "3.9", "3.11"]
pydantic-version: ["1", "2"]
openmm: [true, false]
run-mypy: [false]
exclude:
- python-version: "3.10"
os: macOS-latest
Expand All @@ -44,6 +46,7 @@ jobs:
environment-file: devtools/conda-envs/test_env.yaml
create-args: >-
python=${{ matrix.python-version }}
pydantic=${{ matrix.pydantic-version }}

- name: Install conda environment without OpenMM
if: ${{ matrix.openmm == false }}
Expand All @@ -63,6 +66,7 @@ jobs:
conda list

- name: Run mypy
if: ${{ matrix.run-mypy == true }}
run: |
mypy -p "openff.models"

Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: trailing-whitespace
- id: debug-statements
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
files: ^openff
Expand All @@ -19,7 +19,7 @@ repos:
- id: isort
files: ^openff
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
files: ^openff
Expand All @@ -30,7 +30,7 @@ repos:
'flake8-no-pep420',
]
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.10.1
hooks:
- id: pyupgrade
files: ^openff
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/no_openmm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ channels:
dependencies:
- python
- pip
- pydantic <2.0.0a0
- pydantic
- openff-units
- openff-utilities
- pytest
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ channels:
dependencies:
- python
- pip
- pydantic <2.0.0a0
- pydantic
- openff-units
- openff-utilities
- pytest
Expand Down
7 changes: 6 additions & 1 deletion openff/models/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from typing import Any, Callable, Dict

from openff.units import unit
from pydantic import BaseModel

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


from openff.models.types import custom_quantity_encoder, json_loader

Expand Down
12 changes: 8 additions & 4 deletions openff/models/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import pytest
from openff.units import unit
from openff.utilities.testing import skip_if_missing
from pydantic import ValidationError

from openff.models.exceptions import UnitValidationError
from openff.models.models import DefaultModel
from openff.models.types import ArrayQuantity, FloatQuantity

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


class TestQuantityTypes:
@skip_if_missing("openmm.unit")
Expand Down Expand Up @@ -186,9 +190,9 @@ class Subject(DefaultModel):
)

# Ensure unyt scalars (unyt.unyt_quantity) are stored as floats
assert type(subject.age.m) == float
assert type(subject.height.m) == float
assert type(subject.doses.m) == np.ndarray
assert subject.age.m is float
assert subject.height.m is float
assert subject.doses.m is np.ndarray

@skip_if_missing("unyt")
@skip_if_missing("openmm.unit")
Expand Down