File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed
Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -478,7 +478,7 @@ def __init__(self, filename):
478478 spec = importlib .util .spec_from_file_location (
479479 name ,
480480 os .path .join (filename , '__init__.py' ),
481- submodule_search_locations = filename ,
481+ submodule_search_locations = [ filename ] ,
482482 )
483483 else :
484484 raise exceptions .PluginError ('Invalid Sopel plugin: %s' % filename )
@@ -494,9 +494,9 @@ def __init__(self, filename):
494494
495495 def _load (self ):
496496 module = importlib .util .module_from_spec (self .module_spec )
497- sys .modules [self .name ] = module
498497 if not self .module_spec .loader :
499498 raise exceptions .PluginError ('Could not determine loader for plugin: %s' % self .filename )
499+ sys .modules [self .name ] = module
500500 self .module_spec .loader .exec_module (module )
501501 return module
502502
Original file line number Diff line number Diff line change @@ -100,3 +100,45 @@ def test_get_label_entrypoint(plugin_tmpfile):
100100 assert meta ['label' ] == 'plugin label'
101101 assert meta ['type' ] == handlers .EntryPointPlugin .PLUGIN_TYPE
102102 assert meta ['source' ] == 'test_plugin = file_mod'
103+
104+
105+ MOCK_PARENT_MODULE = """
106+ from sopel import plugin
107+
108+ from .sub import foo
109+
110+
111+ @plugin.command('mock')
112+ def mock(bot, trigger):
113+ bot.say(foo)
114+ """
115+
116+ MOCK_SUB_MODULE = """
117+ foo = 'bar baz'
118+ """
119+
120+
121+ @pytest .fixture
122+ def plugin_folder (tmp_path ):
123+ root = tmp_path / 'test_folder_plugin'
124+ root .mkdir ()
125+
126+ parent = root / '__init__.py'
127+ with open (parent , 'w' ) as f :
128+ f .write (MOCK_PARENT_MODULE )
129+
130+ submodule = root / 'sub.py'
131+ with open (submodule , 'w' ) as f :
132+ f .write (MOCK_SUB_MODULE )
133+
134+ return str (root )
135+
136+
137+ def test_folder_plugin_imports (plugin_folder ):
138+ """Ensure submodule imports work as expected in folder plugins.
139+
140+ Regression test for https://github.com/sopel-irc/sopel/issues/2619
141+ """
142+ handler = handlers .PyFilePlugin (plugin_folder )
143+ handler .load ()
144+ assert handler .module .foo == 'bar baz'
You can’t perform that action at this time.
0 commit comments