[commands] update sys.modules in load_extension again
6f71552c508c61d9b6bf024fc259063ad056b7c4 introduced a regression: loading a module that is not in a package does not add it to sys.modules. Updating sys.modules is required after all.
This commit is contained in:
parent
92b3a4f8f4
commit
042a234eac
@ -590,19 +590,23 @@ class BotBase(GroupMixin):
|
|||||||
def _load_from_module_spec(self, spec, key):
|
def _load_from_module_spec(self, spec, key):
|
||||||
# precondition: key not in self.__extensions
|
# precondition: key not in self.__extensions
|
||||||
lib = importlib.util.module_from_spec(spec)
|
lib = importlib.util.module_from_spec(spec)
|
||||||
|
sys.modules[key] = lib
|
||||||
try:
|
try:
|
||||||
spec.loader.exec_module(lib)
|
spec.loader.exec_module(lib)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
del sys.modules[key]
|
||||||
raise errors.ExtensionFailed(key, e) from e
|
raise errors.ExtensionFailed(key, e) from e
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setup = getattr(lib, 'setup')
|
setup = getattr(lib, 'setup')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
del sys.modules[key]
|
||||||
raise errors.NoEntryPointError(key)
|
raise errors.NoEntryPointError(key)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setup(self)
|
setup(self)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
del sys.modules[key]
|
||||||
self._remove_module_references(lib.__name__)
|
self._remove_module_references(lib.__name__)
|
||||||
self._call_module_finalizers(lib, key)
|
self._call_module_finalizers(lib, key)
|
||||||
raise errors.ExtensionFailed(key, e) from e
|
raise errors.ExtensionFailed(key, e) from e
|
||||||
@ -635,7 +639,7 @@ class BotBase(GroupMixin):
|
|||||||
NoEntryPointError
|
NoEntryPointError
|
||||||
The extension does not have a setup function.
|
The extension does not have a setup function.
|
||||||
ExtensionFailed
|
ExtensionFailed
|
||||||
The extension setup function had an execution error.
|
The extension or its setup function had an execution error.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if name in self.__extensions:
|
if name in self.__extensions:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user