eric6/PluginManager/PluginManager.py

branch
without_py2_and_pyqt4
changeset 7192
a22eee00b052
parent 7023
b025e93cc27d
child 7229
53054eb5b15a
equal deleted inserted replaced
7191:960850ec284c 7192:a22eee00b052
30 except ImportError: 30 except ImportError:
31 SSL_AVAILABLE = False 31 SSL_AVAILABLE = False
32 32
33 from .PluginExceptions import PluginPathError, PluginModulesError, \ 33 from .PluginExceptions import PluginPathError, PluginModulesError, \
34 PluginLoadError, PluginActivationError, PluginModuleFormatError, \ 34 PluginLoadError, PluginActivationError, PluginModuleFormatError, \
35 PluginClassFormatError, PluginPy2IncompatibleError 35 PluginClassFormatError
36 36
37 import UI.PixmapCache 37 import UI.PixmapCache
38 38
39 import Globals 39 import Globals
40 import Utilities 40 import Utilities
380 @param name name of the module to be loaded (string) 380 @param name name of the module to be loaded (string)
381 @param directory name of the plugin directory (string) 381 @param directory name of the plugin directory (string)
382 @param reload_ flag indicating to reload the module (boolean) 382 @param reload_ flag indicating to reload the module (boolean)
383 @exception PluginLoadError raised to indicate an issue loading 383 @exception PluginLoadError raised to indicate an issue loading
384 the plug-in 384 the plug-in
385 @exception PluginPy2IncompatibleError raised to indicate the Python 2
386 incompatibility of a plug-in
387 """ 385 """
388 try: 386 try:
389 fname = "{0}.py".format(os.path.join(directory, name)) 387 fname = "{0}.py".format(os.path.join(directory, name))
390 module = imp.load_source(name, fname) 388 module = imp.load_source(name, fname)
391 if not hasattr(module, "autoactivate"): 389 if not hasattr(module, "autoactivate"):
392 module.error = self.tr( 390 module.error = self.tr(
393 "Module is missing the 'autoactivate' attribute.") 391 "Module is missing the 'autoactivate' attribute.")
394 self.__failedModules[name] = module 392 self.__failedModules[name] = module
395 raise PluginLoadError(name) 393 raise PluginLoadError(name)
396 if sys.version_info[0] < 3:
397 if not hasattr(module, "python2Compatible"):
398 module.error = self.tr(
399 "Module is missing the Python2 compatibility flag."
400 " Please update.")
401 compatible = False
402 elif not getattr(module, "python2Compatible", True):
403 module.error = self.tr(
404 "Module is not Python2 compatible.")
405 compatible = False
406 else:
407 compatible = True
408 if not compatible:
409 self.__failedModules[name] = module
410 raise PluginPy2IncompatibleError(name)
411 if getattr(module, "autoactivate", False): 394 if getattr(module, "autoactivate", False):
412 self.__inactiveModules[name] = module 395 self.__inactiveModules[name] = module
413 else: 396 else:
414 if not hasattr(module, "pluginType") or \ 397 if not hasattr(module, "pluginType") or \
415 not hasattr(module, "pluginTypename"): 398 not hasattr(module, "pluginTypename"):
432 self.__ui, e5App().getObject("ToolbarManager")) 415 self.__ui, e5App().getObject("ToolbarManager"))
433 except (KeyError, AttributeError): 416 except (KeyError, AttributeError):
434 pass 417 pass
435 except PluginLoadError: 418 except PluginLoadError:
436 print("Error loading plug-in module:", name) 419 print("Error loading plug-in module:", name)
437 except PluginPy2IncompatibleError:
438 print("Error loading plug-in module:", name)
439 print("The plug-in is not Python2 compatible.")
440 except Exception as err: 420 except Exception as err:
441 module = imp.new_module(name) 421 module = imp.new_module(name)
442 module.error = self.tr( 422 module.error = self.tr(
443 "Module failed to load. Error: {0}").format(str(err)) 423 "Module failed to load. Error: {0}").format(str(err))
444 self.__failedModules[name] = module 424 self.__failedModules[name] = module

eric ide

mercurial