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

support pydantic 2 #146

Merged
merged 15 commits into from
Feb 8, 2024
12 changes: 9 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
channels:
- defaults
- conda-forge
dependencies:
- python=3.8
Expand All @@ -10,9 +9,16 @@ dependencies:
- pytest-cov
- pytest-mock
- pre-commit
- conda-lock>=1.2
- conda-lock>=2.2
- pydantic
- ruamel.yaml
- setuptools-scm
- setuptools-scm>=6.2
- shellingham
- python-dotenv
- lockfile
- pexpect
- fsspec
- python-libarchive-c
- pip
- pip:
- -e .
3 changes: 1 addition & 2 deletions etc/test-environment.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: test-conda-project
channels:
- defaults
- conda-forge
dependencies:
- conda-lock>=2.1.1
- conda-lock>=2.2
- pexpect
- lockfile
- ruamel.yaml
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
"Topic :: Utilities",
]
dependencies = [
"conda-lock >=1.2",
"conda-lock >=2.2",
"lockfile",
"pexpect",
"ruamel.yaml",
Expand Down
8 changes: 7 additions & 1 deletion src/conda_project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
render_lockfile_for_platform,
)
from fsspec.core import split_protocol
from pydantic import BaseModel, create_model

try:
# Version 2 provides a v1 API
from pydantic.v1 import BaseModel, create_model
except ImportError:
from pydantic import BaseModel # type: ignore
from pydantic import create_model # type: ignore

from .conda import (
CONDA_EXE,
Expand Down
9 changes: 8 additions & 1 deletion src/conda_project/project_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@

from conda_lock._vendor.conda.models.match_spec import MatchSpec
from pkg_resources import Requirement
from pydantic import BaseModel, ValidationError, validator
from ruamel.yaml import YAML

try:
# Version 2 provides a v1 API
from pydantic.v1 import BaseModel, ValidationError, validator
except ImportError:
from pydantic import BaseModel # type: ignore
from pydantic import ValidationError # type: ignore
from pydantic import validator # type: ignore

from .exceptions import CondaProjectError

PROJECT_YAML_FILENAMES = ("conda-project.yml", "conda-project.yaml")
Expand Down
Loading