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

Fix issues in parsing configuration files due to Pydantic upgrade #421

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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
46 changes: 23 additions & 23 deletions nannyml/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import jinja2
import yaml
from pydantic import BaseModel, validator
from pydantic import BaseModel, validator, Field

from nannyml._typing import Self
from nannyml.exceptions import IOException
Expand All @@ -20,55 +20,55 @@

class InputDataConfig(BaseModel):
path: str
credentials: Optional[Dict[str, Any]]
read_args: Optional[Dict[str, Any]]
credentials: Optional[Dict[str, Any]] = Field(default=None)
read_args: Optional[Dict[str, Any]] = Field(default=None)


class TargetDataConfig(InputDataConfig):
join_column: Optional[str]
join_column: Optional[str] = Field(default=None)


class InputConfig(BaseModel):
reference_data: InputDataConfig
analysis_data: InputDataConfig
target_data: Optional[TargetDataConfig]
target_data: Optional[TargetDataConfig] = Field(default=None)


class WriterConfig(BaseModel):
type: str
params: Optional[Dict[str, Any]]
write_args: Optional[Dict[str, Any]]
params: Optional[Dict[str, Any]] = Field(default=None)
write_args: Optional[Dict[str, Any]] = Field(default=None)


class IntervalSchedulingConfig(BaseModel):
weeks: Optional[int]
days: Optional[int]
hours: Optional[int]
minutes: Optional[int]
weeks: Optional[int] = Field(default=None)
days: Optional[int] = Field(default=None)
hours: Optional[int] = Field(default=None)
minutes: Optional[int] = Field(default=None)


class CronSchedulingConfig(BaseModel):
crontab: str


class SchedulingConfig(BaseModel):
interval: Optional[IntervalSchedulingConfig]
cron: Optional[CronSchedulingConfig]
interval: Optional[IntervalSchedulingConfig] = Field(default=None)
cron: Optional[CronSchedulingConfig] = Field(default=None)


class StoreConfig(BaseModel):
path: str
credentials: Optional[Dict[str, Any]]
filename: Optional[str]
credentials: Optional[Dict[str, Any]] = Field(default=None)
filename: Optional[str] = Field(default=None)
invalidate: bool = False


class CalculatorConfig(BaseModel):
type: str
name: Optional[str] = None
enabled: Optional[bool] = True
outputs: Optional[List[WriterConfig]]
store: Optional[StoreConfig]
name: Optional[str] = Field(default=None)
enabled: Optional[bool] = Field(default=True)
outputs: Optional[List[WriterConfig]] = Field(default=None)
store: Optional[StoreConfig] = Field(default=None)
params: Dict[str, Any]

@validator('params')
Expand All @@ -88,18 +88,18 @@


class Config(BaseModel):
input: Optional[InputConfig] = None
input: Optional[InputConfig] = Field(default=None)
calculators: List[CalculatorConfig]
scheduling: Optional[SchedulingConfig] = None
scheduling: Optional[SchedulingConfig] = Field(default=None)

ignore_errors: Optional[bool] = None
ignore_errors: Optional[bool] = Field(default=None)

@classmethod
@lru_cache(maxsize=1)
def load(cls, config_path: Optional[str] = None):
with open(get_config_path(config_path), "r") as config_file:
config_dict = yaml.load(config_file, Loader=yaml.FullLoader)
return Config.parse_obj(config_dict)._render()
return Config.model_validate(config_dict)._render()

Check warning on line 102 in nannyml/config.py

View check run for this annotation

Codecov / codecov/patch

nannyml/config.py#L102

Added line #L102 was not covered by tests

@classmethod
def parse(cls, config: str):
Expand Down
Loading