Skip to content

Commit 6a5b8cc

Browse files
JasonWeillpre-commit-ci[bot]dlqqq
authored
Pydantic v1 and v2 compatibility, add pydantic_v1 module (#463) (#465)
* Custom module to allow Pydantic v1 and v2 compatibility * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update jupyter_scheduler/pydantic_v1/__init__.py * Removes unneeded logic * Adds dataclasses.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: david qiu <[email protected]>
1 parent 95b117e commit 6a5b8cc

File tree

8 files changed

+21
-5
lines changed

8 files changed

+21
-5
lines changed

jupyter_scheduler/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from jupyter_server.base.handlers import APIHandler
55
from jupyter_server.extension.handler import ExtensionHandlerMixin
66
from jupyter_server.utils import ensure_async
7-
from pydantic import ValidationError
87
from tornado.web import HTTPError, authenticated
98

109
from jupyter_scheduler.environments import EnvironmentRetrievalError
@@ -28,6 +27,7 @@
2827
UpdateJob,
2928
UpdateJobDefinition,
3029
)
30+
from jupyter_scheduler.pydantic_v1 import ValidationError
3131

3232

3333
class JobHandlersMixin:

jupyter_scheduler/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
from typing import Dict, List, Optional, Union
44

5-
from pydantic import BaseModel, root_validator
5+
from jupyter_scheduler.pydantic_v1 import BaseModel, root_validator
66

77
Tags = List[str]
88
EnvironmentParameterValues = Union[int, float, bool, str]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from importlib import metadata
2+
3+
# expose Pydantic v1 API, regardless of Pydantic version in current env
4+
5+
try:
6+
from pydantic.v1 import *
7+
except ImportError:
8+
from pydantic import *
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
from pydantic.v1.dataclasses import *
3+
except ImportError:
4+
from pydantic.dataclasses import *

jupyter_scheduler/pydantic_v1/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
from pydantic.v1.main import *
3+
except ImportError:
4+
from pydantic.main import *

jupyter_scheduler/task_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
import traitlets
88
from jupyter_server.transutils import _i18n
9-
from pydantic import BaseModel
109
from sqlalchemy import Boolean, Column, Integer, String, create_engine
1110
from sqlalchemy.orm import sessionmaker
1211
from traitlets.config import LoggingConfigurable
1312

1413
from jupyter_scheduler.models import CreateJob, UpdateJobDefinition
1514
from jupyter_scheduler.orm import JobDefinition, declarative_base
15+
from jupyter_scheduler.pydantic_v1 import BaseModel
1616
from jupyter_scheduler.utils import (
1717
compute_next_run_time,
1818
get_localized_timestamp,

jupyter_scheduler/tests/test_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from unittest.mock import patch
33

44
import pytest
5-
from pydantic import ValidationError
65
from tornado.httpclient import HTTPClientError
76

87
from jupyter_scheduler.exceptions import (
@@ -21,6 +20,7 @@
2120
Status,
2221
UpdateJob,
2322
)
23+
from jupyter_scheduler.pydantic_v1 import ValidationError
2424
from jupyter_scheduler.tests.utils import expected_http_error
2525

2626

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
"jupyter_server>=1.6,<3",
3333
"traitlets~=5.0",
3434
"nbconvert~=7.0",
35-
"pydantic~=1.10",
35+
"pydantic>=1.10,<3",
3636
"sqlalchemy~=1.0",
3737
"croniter~=1.4",
3838
"pytz==2023.3",

0 commit comments

Comments
 (0)