mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-06-11 07:11:52 +02:00
[core] Detailed error message for plugin load failure
This commit is contained in:
parent
c4f64d718d
commit
0106a3b588
1 changed files with 15 additions and 4 deletions
|
@ -7,8 +7,8 @@ import tempfile
|
||||||
import uuid
|
import uuid
|
||||||
import logging
|
import logging
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# for cx_freeze
|
# for cx_freeze
|
||||||
|
@ -65,6 +65,7 @@ def loadPlugins(folder, packageName, classType):
|
||||||
package = importlib.import_module(packageName)
|
package = importlib.import_module(packageName)
|
||||||
packageName = package.packageName if hasattr(package, 'packageName') else package.__name__
|
packageName = package.packageName if hasattr(package, 'packageName') else package.__name__
|
||||||
packageVersion = getattr(package, "__version__", None)
|
packageVersion = getattr(package, "__version__", None)
|
||||||
|
packagePath = os.path.dirname(package.__file__)
|
||||||
|
|
||||||
for importer, pluginName, ispkg in pkgutil.iter_modules(package.__path__):
|
for importer, pluginName, ispkg in pkgutil.iter_modules(package.__path__):
|
||||||
pluginModuleName = '.' + pluginName
|
pluginModuleName = '.' + pluginName
|
||||||
|
@ -75,7 +76,7 @@ def loadPlugins(folder, packageName, classType):
|
||||||
if plugin.__module__ == '{}.{}'.format(package.__name__, pluginName)
|
if plugin.__module__ == '{}.{}'.format(package.__name__, pluginName)
|
||||||
and issubclass(plugin, classType)]
|
and issubclass(plugin, classType)]
|
||||||
if not plugins:
|
if not plugins:
|
||||||
logging.warning("No class defined in plugin: {}".format(pluginModuleName))
|
logging.warning(f"No class defined in plugin: {pluginModuleName}")
|
||||||
|
|
||||||
importPlugin = True
|
importPlugin = True
|
||||||
for p in plugins:
|
for p in plugins:
|
||||||
|
@ -88,13 +89,23 @@ def loadPlugins(folder, packageName, classType):
|
||||||
break
|
break
|
||||||
p.packageName = packageName
|
p.packageName = packageName
|
||||||
p.packageVersion = packageVersion
|
p.packageVersion = packageVersion
|
||||||
|
p.packagePath = packagePath
|
||||||
if importPlugin:
|
if importPlugin:
|
||||||
pluginTypes.extend(plugins)
|
pluginTypes.extend(plugins)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errors.append(' * {}: {}'.format(pluginName, str(e)))
|
tb = traceback.extract_tb(e.__traceback__)
|
||||||
|
last_call = tb[-1]
|
||||||
|
errors.append(f' * {pluginName} ({type(e).__name__}): {str(e)}\n'
|
||||||
|
# filename:lineNumber functionName
|
||||||
|
f'{last_call.filename}:{last_call.lineno} {last_call.name}\n'
|
||||||
|
# line of code with the error
|
||||||
|
f'{last_call.line}'
|
||||||
|
# Full traceback
|
||||||
|
f'\n{traceback.format_exc()}\n\n'
|
||||||
|
)
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
logging.warning('== The following "{package}" plugins could not be loaded ==\n'
|
logging.warning(' The following "{package}" plugins could not be loaded:\n'
|
||||||
'{errorMsg}\n'
|
'{errorMsg}\n'
|
||||||
.format(package=packageName, errorMsg='\n'.join(errors)))
|
.format(package=packageName, errorMsg='\n'.join(errors)))
|
||||||
return pluginTypes
|
return pluginTypes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue