File size: 665 Bytes
4670a90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
from pathlib import Path
from typing import Any, Dict, Optional, Union

import yaml

from .utils import merge

FILENAME = "chatdocs.yml"


def _get_config(path: Union[Path, str]) -> Dict[str, Any]:
    path = Path(path)
    if path.is_dir():
        path = path / FILENAME
    with open(path) as f:
        return yaml.safe_load(f)


def get_config(path: Optional[Union[Path, str]] = None) -> Dict[str, Any]:
    default_config = _get_config(Path(__file__).parent / "data")
    if path is None:
        path = Path() / FILENAME
        if not path.is_file():
            return default_config
    config = _get_config(path)
    return merge(default_config, config)