@@ -29,8 +29,36 @@ def __post_init__(self):
29
29
self .__class__ .instance = self
30
30
self .reload ()
31
31
32
+ @staticmethod
33
+ def _load_plugin (path : Path ):
34
+ if path .suffix .startswith (".json" ):
35
+ with path .open ("r" , encoding = "utf-8" ) as f :
36
+ return json .load (f )
37
+ if path .suffix in (".yaml" , ".yml" ):
38
+ try :
39
+ import yaml
40
+ except ImportError :
41
+ raise RuntimeError ("yaml is not installed" )
42
+
43
+ with path .open ("r" , encoding = "utf-8" ) as f :
44
+ return yaml .safe_load (f )
45
+ raise NotImplementedError (f"unsupported plugin config file format: { path !s} " )
46
+
32
47
def reload (self ):
33
48
self .updater (self )
49
+ plugin_files : list [str ] = self .plugin .pop ("$files" , []) # type: ignore
50
+ for file in plugin_files :
51
+ path = Path (file )
52
+ if not path .exists ():
53
+ raise FileNotFoundError (file )
54
+ if path .is_dir ():
55
+ for _path in path .iterdir ():
56
+ if not _path .is_file ():
57
+ continue
58
+ self .plugin [_path .stem ] = self ._load_plugin (_path )
59
+ else :
60
+ self .plugin [path .stem ] = self ._load_plugin (path )
61
+
34
62
self .plugin .setdefault (".commands" , {})
35
63
self .prelude_plugin = self .plugin .pop ("$prelude" , []) # type: ignore
36
64
disabled = []
@@ -91,7 +119,7 @@ def _updater(self: EntariConfig):
91
119
self .plugin = data .get ("plugins" , {})
92
120
93
121
return cls (_path , _updater )
94
- raise NotImplementedError (f"unsupported config file format: { _path . suffix } " )
122
+ raise NotImplementedError (f"unsupported config file format: { _path !s } " )
95
123
96
124
97
125
load_config = EntariConfig .load
0 commit comments