Skip to content

Commit

Permalink
Merge pull request #787 from mattwthompson/pydantic-v2
Browse files Browse the repository at this point in the history
Enable Pydantic v1/v2 dual-compatibility
  • Loading branch information
bennybp authored Nov 8, 2023
2 parents e53ffd9 + 31055d7 commit e4910c3
Show file tree
Hide file tree
Showing 51 changed files with 196 additions and 56 deletions.
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sphinx_design
pydata_sphinx_theme
sphinx
autodoc-pydantic
sphinx-copybutton
autodoc-pydantic==1.9.0
pydantic==1.10.11
myst-nb
nglview
-e ../qcportal
Expand Down
4 changes: 2 additions & 2 deletions qcarchivetesting/conda-envs/fulltest_qcportal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ dependencies:
- msgpack-python
- requests
- pyyaml
- pydantic<2.0
- pydantic
- zstandard
- qcelemental
- tabulate
- tqdm
- pandas
- pyjwt
- packaging
- packaging
2 changes: 1 addition & 1 deletion qcarchivetesting/conda-envs/fulltest_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- msgpack-python
- requests
- pyyaml
- pydantic<2.0
- pydantic
- zstandard
- qcelemental
- tabulate
Expand Down
4 changes: 2 additions & 2 deletions qcarchivetesting/conda-envs/fulltest_snowflake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
- msgpack-python
- requests
- pyyaml
- pydantic<2.0
- pydantic
- zstandard
- qcelemental
- tabulate
Expand Down Expand Up @@ -49,4 +49,4 @@ dependencies:

- pip:
- "geometric @ git+https://github.com/hjnpark/geomeTRIC"
- scipy # for geometric
- scipy # for geometric
2 changes: 1 addition & 1 deletion qcarchivetesting/conda-envs/fulltest_worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- msgpack-python
- requests
- pyyaml
- pydantic<2.0
- pydantic
- zstandard
- qcelemental
- tabulate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

import numpy as np
import sqlalchemy.orm.attributes
from pydantic import BaseModel, Extra, parse_obj_as
try:
from pydantic.v1 import BaseModel, Extra, parse_obj_as
except ImportError:
from pydantic import BaseModel, Extra, parse_obj_as
from sqlalchemy import select, func
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.orm import lazyload, joinedload, undefer, defer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import json
from typing import TYPE_CHECKING, Tuple, Optional, Dict, Union, Any

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from qcelemental.models import Molecule, FailedOperation, ComputeError, OptimizationResult
from qcelemental.models.procedures import OptimizationProtocols

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from typing import TYPE_CHECKING

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

from qcfractal.components.singlepoint.testing_helpers import submit_test_data
from qcportal import PortalRequestError
Expand Down
5 changes: 4 additions & 1 deletion qcfractal/qcfractal/components/manybody/testing_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from typing import TYPE_CHECKING, Tuple, Optional, Dict, Union, Any

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from qcelemental.models import Molecule, FailedOperation, ComputeError, AtomicResult

from qcarchivetesting.helpers import read_record_data
Expand Down
6 changes: 5 additions & 1 deletion qcfractal/qcfractal/components/neb/record_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import numpy as np
import sqlalchemy.orm.attributes
import tabulate
from pydantic import BaseModel, Extra
try:
from pydantic.v1 import BaseModel, Extra
except ImportError:
from pydantic import BaseModel, Extra

from sqlalchemy import select, func
from sqlalchemy.dialects.postgresql import insert, array_agg, aggregate_order_by, DOUBLE_PRECISION, TEXT
from sqlalchemy.orm import lazyload, joinedload, defer, undefer
Expand Down
5 changes: 4 additions & 1 deletion qcfractal/qcfractal/components/neb/testing_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from typing import TYPE_CHECKING, Tuple, Optional, Dict, List, Union, Any

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from qcelemental.models import Molecule, FailedOperation, ComputeError, AtomicResult, OptimizationResult

from qcarchivetesting.helpers import read_record_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from datetime import datetime
from typing import TYPE_CHECKING, Tuple, Optional, Union, Dict, Any

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from qcelemental.models import Molecule, FailedOperation, ComputeError, OptimizationResult

from qcarchivetesting.helpers import read_record_data
Expand Down
5 changes: 4 additions & 1 deletion qcfractal/qcfractal/components/reaction/testing_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from typing import TYPE_CHECKING, Tuple, Optional, Dict, List, Union, Any

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from qcelemental.models import Molecule, FailedOperation, ComputeError, AtomicResult, OptimizationResult

from qcarchivetesting.helpers import read_record_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from datetime import datetime
from typing import TYPE_CHECKING, Tuple, Optional, Union, Dict, Any

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from qcelemental.models import Molecule, FailedOperation, ComputeError, AtomicResult

from qcarchivetesting.helpers import read_record_data
Expand Down
5 changes: 4 additions & 1 deletion qcfractal/qcfractal/components/tasks/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from datetime import datetime
from typing import TYPE_CHECKING

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from qcelemental.models import FailedOperation
from sqlalchemy import select, func
from sqlalchemy.dialects.postgresql import array
Expand Down
5 changes: 4 additions & 1 deletion qcfractal/qcfractal/components/torsiondrive/record_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from typing import TYPE_CHECKING

import sqlalchemy.orm.attributes
from pydantic import BaseModel, Extra
try:
from pydantic.v1 import BaseModel, Extra
except ImportError:
from pydantic import BaseModel, Extra
from sqlalchemy import select, func
from sqlalchemy.dialects.postgresql import insert, array_agg, aggregate_order_by, DOUBLE_PRECISION, TEXT
from sqlalchemy.orm import lazyload, joinedload, defer, undefer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import json
from typing import TYPE_CHECKING, Tuple, Optional, Dict, List, Union, Any

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from qcelemental.models import Molecule, FailedOperation, ComputeError, OptimizationResult
from qcelemental.models.procedures import OptimizationProtocols

Expand Down
8 changes: 6 additions & 2 deletions qcfractal/qcfractal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

import yaml
from psycopg2.extensions import make_dsn, parse_dsn
from pydantic import BaseSettings, Field, validator, root_validator, ValidationError
from pydantic.env_settings import SettingsSourceCallable
try:
from pydantic.v1 import BaseSettings, Field, validator, root_validator, ValidationError
from pydantic.v1.env_settings import SettingsSourceCallable
except ImportError:
from pydantic import BaseSettings, Field, validator, root_validator, ValidationError
from pydantic.env_settings import SettingsSourceCallable
from sqlalchemy.engine.url import URL, make_url

from qcfractal.port_util import find_open_port
Expand Down
5 changes: 4 additions & 1 deletion qcfractal/qcfractal/db_socket/base_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

if TYPE_CHECKING:
from typing import Any, TypeVar, Type, Dict, Optional, Iterable, Union, List
from pydantic import BaseModel
try:
from pydantic.v1 import BaseModel
except ImportError:
from pydantic import BaseModel

_T = TypeVar("_T")

Expand Down
5 changes: 4 additions & 1 deletion qcfractal/qcfractal/flask_app/api_v1/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from functools import wraps
from typing import Callable

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from flask import request, Response
from werkzeug.exceptions import BadRequest

Expand Down
5 changes: 4 additions & 1 deletion qcfractal/qcfractal/old_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from typing import Optional

import yaml
from pydantic import Field, validator
try:
from pydantic.v1 import Field, validator
except ImportError:
from pydantic import Field, validator

from .config import ConfigBase, ConfigCommon

Expand Down
5 changes: 4 additions & 1 deletion qcfractalcompute/qcfractalcompute/apps/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from qcportal.compression import decompress, CompressionEnum

Expand Down
5 changes: 4 additions & 1 deletion qcfractalcompute/qcfractalcompute/compute_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from parsl.dataflow.dflow import DataFlowKernel
from parsl.dataflow.futures import Future as ParslFuture
from parsl.executors import HighThroughputExecutor, ThreadPoolExecutor
from pydantic import BaseModel, Extra, Field
try:
from pydantic.v1 import BaseModel, Extra, Field
except ImportError:
from pydantic import BaseModel, Extra, Field
from requests.exceptions import Timeout

from qcfractalcompute.apps.app_manager import AppManager
Expand Down
5 changes: 4 additions & 1 deletion qcfractalcompute/qcfractalcompute/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from typing import List, Optional, Union, Dict, Any

import yaml
from pydantic import BaseModel, Field, validator
try:
from pydantic.v1 import BaseModel, Field, validator
except ImportError:
from pydantic import BaseModel, Field, validator
from typing_extensions import Literal

from qcportal.utils import seconds_to_hms
Expand Down
2 changes: 1 addition & 1 deletion qcportal/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = [
"msgpack",
"requests",
"pyyaml",
"pydantic<2.0",
"pydantic",
"zstandard",
"qcelemental",
"tabulate",
Expand Down
5 changes: 4 additions & 1 deletion qcportal/qcportal/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from enum import Enum
from typing import Optional, Union, List

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

from ..exceptions import InvalidPasswordError, InvalidUsernameError, InvalidRolenameError, InvalidGroupnameError

Expand Down
5 changes: 4 additions & 1 deletion qcportal/qcportal/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from typing import Optional, List, Iterator, Generic, TypeVar

from pydantic import BaseModel, validator, Extra
try:
from pydantic.v1 import BaseModel, validator, Extra
except ImportError:
from pydantic import BaseModel, validator, Extra

T = TypeVar("T")

Expand Down
5 changes: 4 additions & 1 deletion qcportal/qcportal/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
)

import jwt
import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
import requests
import yaml
from packaging.version import parse as parse_version
Expand Down
8 changes: 6 additions & 2 deletions qcportal/qcportal/dataset_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
from typing import Optional, Dict, Any, List, Iterable, Type, Tuple, Union, Callable, ClassVar, Sequence

import pandas as pd
import pydantic
from pydantic import BaseModel, Extra, validator, PrivateAttr, Field
try:
import pydantic.v1 as pydantic
from pydantic.v1 import BaseModel, Extra, validator, PrivateAttr, Field
except ImportError:
import pydantic
from pydantic import BaseModel, Extra, validator, PrivateAttr, Field
from qcelemental.models.types import Array
from tabulate import tabulate
from tqdm import tqdm
Expand Down
5 changes: 4 additions & 1 deletion qcportal/qcportal/dataset_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from typing import Optional, Dict, Any, List, Iterable

import zstandard
from pydantic import BaseModel, validator, PrivateAttr, parse_obj_as, Extra
try:
from pydantic.v1 import BaseModel, validator, PrivateAttr, parse_obj_as, Extra
except ImportError:
from pydantic import BaseModel, validator, PrivateAttr, parse_obj_as, Extra

from qcportal.serialization import deserialize

Expand Down
5 changes: 4 additions & 1 deletion qcportal/qcportal/gridoptimization/dataset_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Dict, Any, Union, Optional, Iterable, Tuple

from pydantic import BaseModel, Extra
try:
from pydantic.v1 import BaseModel, Extra
except ImportError:
from pydantic import BaseModel, Extra
from typing_extensions import Literal

from qcportal.dataset_models import BaseDataset
Expand Down
5 changes: 4 additions & 1 deletion qcportal/qcportal/gridoptimization/record_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from enum import Enum
from typing import List, Union, Optional, Dict, Iterable, Tuple, Sequence, Any

from pydantic import BaseModel, Extra, Field, constr, validator
try:
from pydantic.v1 import BaseModel, Extra, Field, constr, validator
except ImportError:
from pydantic import BaseModel, Extra, Field, constr, validator
from typing_extensions import Literal

from qcportal.molecules import Molecule
Expand Down
5 changes: 4 additions & 1 deletion qcportal/qcportal/internal_jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from typing import Optional, Dict, Any, List, Union

from dateutil.parser import parse as date_parser
from pydantic import BaseModel, Extra, validator
try:
from pydantic.v1 import BaseModel, Extra, validator
except ImportError:
from pydantic import BaseModel, Extra, validator

from qcportal.base_models import QueryProjModelBase
from ..base_models import QueryIteratorBase
Expand Down
Loading

0 comments on commit e4910c3

Please sign in to comment.