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

Pydantic v1 and v2 compatibility, add pydantic_v1 module #463

Merged
merged 5 commits into from
Nov 15, 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
2 changes: 1 addition & 1 deletion jupyter_scheduler/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from jupyter_server.base.handlers import APIHandler
from jupyter_server.extension.handler import ExtensionHandlerMixin
from jupyter_server.utils import ensure_async
from pydantic import ValidationError
from tornado.web import HTTPError, authenticated

from jupyter_scheduler.environments import EnvironmentRetrievalError
Expand All @@ -28,6 +27,7 @@
UpdateJob,
UpdateJobDefinition,
)
from jupyter_scheduler.pydantic_v1 import ValidationError


class JobHandlersMixin:
Expand Down
2 changes: 1 addition & 1 deletion jupyter_scheduler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from typing import Dict, List, Optional, Union

from pydantic import BaseModel, root_validator
from jupyter_scheduler.pydantic_v1 import BaseModel, root_validator

Tags = List[str]
EnvironmentParameterValues = Union[int, float, bool, str]
Expand Down
8 changes: 8 additions & 0 deletions jupyter_scheduler/pydantic_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from importlib import metadata

# expose Pydantic v1 API, regardless of Pydantic version in current env

try:
from pydantic.v1 import *
except ImportError:
from pydantic import *
4 changes: 4 additions & 0 deletions jupyter_scheduler/pydantic_v1/dataclasses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
try:
from pydantic.v1.dataclasses import *
except ImportError:
from pydantic.dataclasses import *
4 changes: 4 additions & 0 deletions jupyter_scheduler/pydantic_v1/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
try:
from pydantic.v1.main import *
except ImportError:
from pydantic.main import *
JasonWeill marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion jupyter_scheduler/task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import traitlets
from jupyter_server.transutils import _i18n
from pydantic import BaseModel
from sqlalchemy import Boolean, Column, Integer, String, create_engine
from sqlalchemy.orm import sessionmaker
from traitlets.config import LoggingConfigurable

from jupyter_scheduler.models import CreateJob, UpdateJobDefinition
from jupyter_scheduler.orm import JobDefinition, declarative_base
from jupyter_scheduler.pydantic_v1 import BaseModel
from jupyter_scheduler.utils import (
compute_next_run_time,
get_localized_timestamp,
Expand Down
2 changes: 1 addition & 1 deletion jupyter_scheduler/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from unittest.mock import patch

import pytest
from pydantic import ValidationError
from tornado.httpclient import HTTPClientError

from jupyter_scheduler.exceptions import (
Expand All @@ -21,6 +20,7 @@
Status,
UpdateJob,
)
from jupyter_scheduler.pydantic_v1 import ValidationError
from jupyter_scheduler.tests.utils import expected_http_error


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"jupyter_server>=1.6,<3",
"traitlets~=5.0",
"nbconvert~=7.0",
"pydantic~=1.10",
"pydantic>=1.10,<3",
"sqlalchemy~=1.0",
"croniter~=1.4",
"pytz==2023.3",
Expand Down
Loading