Swap pkgutil.ImpImporter for importlib when loading custom modules from add-ons (#14481)
Replaces #14405
Summary of the issue:
Addons have the ability to import custom code from the add-ons directory. This is used to load install tasks, for example.
This mechanism was based on a deprecated solution in pkgutil and allowed importing modules using backslashes, resulting in malformed module identifiers in sys.modules.
Description of user facing changes
Importing submodules with loadModule should be done with a dot separated name (i.e. loadModule("lib.example") instead of loadModule("lib\\example")
loadModule now raises an exception when a module can't be found
Description of development approach
We no longer rely on pkgutil.ImpImporter.
Testing strategy:
Tested importing a lib module from an example addon as well as modules without init.py and submodules. Also tested modules with malformed content, resulting in tracebacks.
Known issues with pull request:
This would break cases where add-ons would use loadModule with a module name containing backslashes to import submodules. However, this scenario was broken anyway since it added malformed names to sys.modules. Note that this is strictly API breaking but I don't think noone was using it anyway.
As loadModule now raises exceptions, add-on authors need to account for that when using this API.