local.py 730 Bytes
Newer Older
Weizhi Cui's avatar
Weizhi Cui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version     : Python 3.11.4
# @Software    : Sublime Text 4
# @Author      : StudentCWZ
# @Email       : StudentCWZ@outlook.com
# @Date        : 2023/10/28 15:07
# @File        : local.py
# @Description :
"""

import os
from typing import Any

import yaml


class LocalConfig:
    def __init__(self, config_dir: str):
        self.config_dir = config_dir

    def load(self, filename: str) -> Any:
        filepath = os.path.join(self.config_dir, filename)
        if not os.path.exists(filepath):
崔为之's avatar
崔为之 committed
26
            raise FileNotFoundError(f'No such file or directory: {filepath}')
Weizhi Cui's avatar
Weizhi Cui committed
27 28 29
        with open(filepath, 'r') as file:
            cfg = yaml.safe_load(file)
        return cfg