Skip to content

Commit

Permalink
Pydantic v1 and v2 compatibility, add pydantic_v1 module (jupyter-s…
Browse files Browse the repository at this point in the history
…erver#463)

* 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

Co-authored-by: david qiu <[email protected]>

* 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]>
  • Loading branch information
3 people committed Nov 15, 2023
1 parent 95b117e commit f5101fc
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
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 *
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

0 comments on commit f5101fc

Please sign in to comment.