Skip to content

Add config checks #80

@Skealz

Description

@Skealz

Example :

from typing import List, Optional, Dict, Union
from pydantic import BaseModel, EmailStr, Field, HttpUrl, ValidationError
import yaml
import os

class Config(BaseModel):
    processor: str
    conda_executable: str
    l2plugins: List[str]
    chain_topdir_data: str
    conda_env_base_path: str
    processing_subdir: str
    report_subdir: str
    listing_subdir: str
    configs_directory: str
    grdwind_config_file: str
    l2_status_subdir: str
    l2_status_filename: str
    l2c_status_filename: str
    l2m_res: List[int]
    postproc_subdir: str
    envs: Dict[str, List[EnvItem]]
    conda_channels: List[str]
    symlink_plugin_l2: Optional[List[Dict[str, List[int]]]]
    symlink_plugin_l2c: Optional[List[Dict[str, List[int]]]]
    symlink_plugin_l2m: Optional[List[Dict[str, List[int]]]]
    reduce: Dict[str, Reduce]


def validate_load_yaml(file_path: str):
    with open(file_path, "r") as file:
        data = yaml.safe_load(file)
        config = Config(**data)
        return config

This can be used to specified expected types and even allowed/default values for the config. This helps warn the user if a wrong value is given. See pydantic documentation for more details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions