File size: 649 Bytes
81a6de1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import ruamel.yaml

def read_yaml_file(yaml_path: str, to_dict=True):
    """read from yaml file"""
    yaml = ruamel.yaml.YAML()
    with open(yaml_path, "r") as file:
        # yaml_content = yaml.safe_load(file)
        yaml_content = yaml.load(file)
    yaml_content = dict(yaml_content) if to_dict else yaml_content
    return yaml_content

class Singleton(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args,
                                                                 **kwargs)
        return cls._instances[cls]