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

Migrate usage of field_validator to pydantic v2 #38

Closed
wants to merge 2 commits into from
Closed
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
24 changes: 12 additions & 12 deletions src/jobflow_remote/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Annotated, Literal, Optional, Union

from jobflow import JobStore
from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, field_validator
from qtoolkit.io import BaseSchedulerIO, scheduler_mapping

from jobflow_remote.fireworks.launchpad import RemoteLaunchPad
Expand Down Expand Up @@ -133,7 +133,7 @@ class WorkerBase(BaseModel):
model_config = ConfigDict(extra="forbid")

@field_validator("scheduler_type")
def check_scheduler_type(cls, scheduler_type: str, values: dict) -> str:
def check_scheduler_type(cls, scheduler_type: str, values: ValidationInfo) -> str:
"""
Validator to set the default of scheduler_type
"""
Expand Down Expand Up @@ -433,45 +433,45 @@ def get_launchpad(self) -> RemoteLaunchPad:
return RemoteLaunchPad(self.get_queue_store())

@field_validator("base_dir")
def check_base_dir(cls, base_dir: str, values: dict) -> str:
def check_base_dir(cls, base_dir: str, values: ValidationInfo) -> str:
"""
Validator to set the default of base_dir based on the project name
"""
if not base_dir:
from jobflow_remote import SETTINGS

return str(Path(SETTINGS.projects_folder, values["name"]))
return str(Path(SETTINGS.projects_folder, values.data["name"]))
return base_dir

@field_validator("tmp_dir")
def check_tmp_dir(cls, tmp_dir: str, values: dict) -> str:
def check_tmp_dir(cls, tmp_dir: str, values: ValidationInfo) -> str:
"""
Validator to set the default of tmp_dir based on the base_dir
"""
if not tmp_dir:
return str(Path(values["base_dir"], "tmp"))
return str(Path(values.data["base_dir"], "tmp"))
return tmp_dir

@field_validator("log_dir")
def check_log_dir(cls, log_dir: str, values: dict) -> str:
def check_log_dir(cls, log_dir: str, values: ValidationInfo) -> str:
"""
Validator to set the default of log_dir based on the base_dir
"""
if not log_dir:
return str(Path(values["base_dir"], "log"))
return str(Path(values.data["base_dir"], "log"))
return log_dir

@field_validator("daemon_dir")
def check_daemon_dir(cls, daemon_dir: str, values: dict) -> str:
def check_daemon_dir(cls, daemon_dir: str, values: ValidationInfo) -> str:
"""
Validator to set the default of daemon_dir based on the base_dir
"""
if not daemon_dir:
return str(Path(values["base_dir"], "daemon"))
return str(Path(values.data["base_dir"], "daemon"))
return daemon_dir

@field_validator("jobstore")
def check_jobstore(cls, jobstore: dict, values: dict) -> dict:
def check_jobstore(cls, jobstore: dict, values: ValidationInfo) -> dict:
"""
Check that the jobstore configuration could be converted to a JobStore.
"""
Expand All @@ -488,7 +488,7 @@ def check_jobstore(cls, jobstore: dict, values: dict) -> dict:
return jobstore

@field_validator("queue")
def check_queue(cls, queue: dict, values: dict) -> dict:
def check_queue(cls, queue: dict, values: ValidationInfo) -> dict:
"""
Check that the queue configuration could be converted to a Store.
"""
Expand Down