| 240 | |
| 241 | #################### Parse #################### |
| 242 | def parse_config(config): |
| 243 | # Check whether need parse, all object except str do not need to be parsed |
| 244 | if not isinstance(config, str): |
| 245 | return config |
| 246 | # Check whether config is file |
| 247 | yaml = YAML(typ="safe", pure=True) |
| 248 | if os.path.exists(config): |
| 249 | with open(config, "r") as f: |
| 250 | return yaml.load(f) |
| 251 | # Check whether the str can be parsed |
| 252 | try: |
| 253 | return yaml.load(config) |
| 254 | except BaseException as base_exp: |
| 255 | raise ValueError("cannot parse config!") from base_exp |
| 256 | |
| 257 | |
| 258 | #################### Other #################### |