-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.py
48 lines (35 loc) · 978 Bytes
/
plugins.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (c) 2025 Marcin Zdun
# This code is licensed under MIT license (see LICENSE for details)
"""
The **proj_flow.base.plugins** provide the plugin enumeration helpers.
"""
import json
import os
from typing import cast
import yaml
def load_yaml(filename: str):
with open(filename) as src:
return cast(dict, yaml.load(src, Loader=yaml.Loader))
def load_json(filename: str):
with open(filename) as src:
return cast(dict, json.load(src))
LOADERS = {
".json": load_json,
".yml": load_yaml,
".yaml": load_yaml,
}
def load_data(filename: str):
prefix, ext = os.path.splitext(filename)
loader = LOADERS.get(ext.lower())
if loader:
try:
return loader(filename)
except Exception:
pass
for new_ext, loader in LOADERS.items():
new_filename = prefix + new_ext
try:
return loader(new_filename)
except Exception:
pass
return {}