Skip to content

Commit

Permalink
plugins.handlers: fix incorrect PyFilePlugin construction
Browse files Browse the repository at this point in the history
Two things:

1. `submodule_search_locations` is expected to be a list, according to
   Python's documentation for `importlib.machinery.ModuleSpec`.
2. The new `module` being inserted into `sys.modules` before checking if
   its spec had a valid `loader` bothered me, so I reordered the steps.
  • Loading branch information
dgw committed Sep 12, 2024
1 parent 1c6aeb9 commit 86efe41
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sopel/plugins/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def __init__(self, filename):
spec = importlib.util.spec_from_file_location(
name,
os.path.join(filename, '__init__.py'),
submodule_search_locations=filename,
submodule_search_locations=[filename],
)
else:
raise exceptions.PluginError('Invalid Sopel plugin: %s' % filename)
Expand All @@ -487,9 +487,9 @@ def __init__(self, filename):

def _load(self):
module = importlib.util.module_from_spec(self.module_spec)
sys.modules[self.name] = module
if not self.module_spec.loader:
raise exceptions.PluginError('Could not determine loader for plugin: %s' % self.filename)
sys.modules[self.name] = module
self.module_spec.loader.exec_module(module)
return module

Expand Down

0 comments on commit 86efe41

Please sign in to comment.