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

Add config checks #80

Open
Skealz opened this issue Sep 17, 2024 · 0 comments
Open

Add config checks #80

Skealz opened this issue Sep 17, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Skealz
Copy link
Collaborator

Skealz commented Sep 17, 2024

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.

@Skealz Skealz added the enhancement New feature or request label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant