Skip to content

Commit

Permalink
update for pydantic 2 (#68)
Browse files Browse the repository at this point in the history
- small changes to avoid deprecation messages
- remove a couple of apparently unused autogenerated files
  • Loading branch information
minrk authored Sep 5, 2024
1 parent c39fcb3 commit 121ff2e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 36 deletions.
13 changes: 0 additions & 13 deletions kbatch-proxy/kbatch_proxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
# generated by datamodel-codegen:
# filename: http://127.0.0.1:8080/openapi/v2
# timestamp: 2021-10-31T19:19:45+00:00

from __future__ import annotations

from typing import Any

from pydantic import BaseModel


class Model(BaseModel):
__root__: Any
14 changes: 8 additions & 6 deletions kbatch-proxy/kbatch_proxy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from typing import List, Optional, Tuple, Dict, Union

import yaml
from pydantic import BaseModel, BaseSettings
from pydantic import BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict
import jupyterhub.services.auth
from fastapi import Depends, FastAPI, HTTPException, Request, status, APIRouter
import kubernetes.client
Expand Down Expand Up @@ -49,15 +50,16 @@ class Settings(BaseSettings):
# Whether to automatically create new namespaces for a users
kbatch_create_user_namespace: bool = True

class Config:
env_file = os.environ.get("KBATCH_SETTINGS_PATH", ".env")
env_file_encoding = "utf-8"
model_config = SettingsConfigDict(
env_file=os.environ.get("KBATCH_SETTINGS_PATH", ".env"),
env_file_encoding="utf-8",
)


class User(BaseModel):
name: str
groups: List[str]
api_token: Optional[str]
api_token: Optional[str] = None

@property
def namespace(self) -> str:
Expand Down Expand Up @@ -254,7 +256,7 @@ def get_root():

@router.get("/authorized")
def authorized(user: User = Depends(get_current_user)) -> UserOut:
return UserOut(**user.dict())
return UserOut(**user.model_dump())


app.include_router(router)
Expand Down
5 changes: 3 additions & 2 deletions kbatch-proxy/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ fastapi
httpx
kubernetes
uvicorn[standard]
gunicorn==20.1.0
gunicorn==23.0.0
jupyterhub
escapism
rich
pydantic[dotenv]<2.0.0
pydantic>=2,<3
pydantic-settings
5 changes: 3 additions & 2 deletions kbatch-proxy/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ install_requires =
httpx
jupyterhub
kubernetes
pydantic[dotenv]<2.0.0
pydantic>=2,<3
pydantic-settings

[options.extras_require]
all =
Expand All @@ -37,4 +38,4 @@ dev =

[options.entry_points]
console_scripts =
kbatch = kbatch.cli:cli
kbatch = kbatch.cli:cli
13 changes: 0 additions & 13 deletions kbatch/kbatch_proxy/__init__.py

This file was deleted.

0 comments on commit 121ff2e

Please sign in to comment.