@@ -18,8 +18,9 @@ def package(*names: str):
18
18
19
19
20
20
class PluginLoader (SourceFileLoader ):
21
- def __init__ (self , fullname : str , path : str ) -> None :
21
+ def __init__ (self , fullname : str , path : str , parent_plugin_id : Optional [ str ] = None ) -> None :
22
22
self .loaded = False
23
+ self .parent_plugin_id = parent_plugin_id
23
24
super ().__init__ (fullname , path )
24
25
25
26
def create_module (self , spec ) -> Optional [ModuleType ]:
@@ -29,7 +30,9 @@ def create_module(self, spec) -> Optional[ModuleType]:
29
30
return super ().create_module (spec )
30
31
31
32
def exec_module (self , module : ModuleType ) -> None :
32
- if plugin := _current_plugin .get (None ):
33
+ if plugin := _current_plugin .get (
34
+ service .plugins .get (self .parent_plugin_id ) if self .parent_plugin_id else None
35
+ ):
33
36
if module .__name__ == plugin .module .__name__ : # from . import xxxx
34
37
return
35
38
setattr (module , "__plugin__" , plugin )
@@ -129,6 +132,10 @@ def find_spec(
129
132
if module_spec .name in service .plugins :
130
133
module_spec .loader = PluginLoader (fullname , module_origin )
131
134
return module_spec
135
+ for plug in service .plugins .values ():
136
+ if module_spec .name in plug .submodules :
137
+ module_spec .loader = PluginLoader (fullname , module_origin , plug .id )
138
+ return module_spec
132
139
return
133
140
134
141
0 commit comments