73 develPlugin=None): |
73 develPlugin=None): |
74 """ |
74 """ |
75 Constructor |
75 Constructor |
76 |
76 |
77 The Plugin Manager deals with three different plugin directories. |
77 The Plugin Manager deals with three different plugin directories. |
78 The first is the one, that is part of eric6 (eric6/Plugins). The |
78 The first is the one, that is part of eric7 (eric7/Plugins). The |
79 second one is the global plugin directory called 'eric6plugins', |
79 second one is the global plugin directory called 'eric7plugins', |
80 which is located inside the site-packages directory. The last one |
80 which is located inside the site-packages directory. The last one |
81 is the user plugin directory located inside the .eric6 directory |
81 is the user plugin directory located inside the .eric7 directory |
82 of the users home directory. |
82 of the users home directory. |
83 |
83 |
84 @param parent reference to the parent object |
84 @param parent reference to the parent object |
85 @type QObject |
85 @type QObject |
86 @param disabledPlugins list of plug-ins that have been disabled via |
86 @param disabledPlugins list of plug-ins that have been disabled via |
107 self.__disabledPlugins = [] |
107 self.__disabledPlugins = [] |
108 |
108 |
109 self.__inactivePluginsKey = "PluginManager/InactivePlugins" |
109 self.__inactivePluginsKey = "PluginManager/InactivePlugins" |
110 |
110 |
111 self.pluginDirs = { |
111 self.pluginDirs = { |
112 "eric6": os.path.join(getConfig('ericDir'), "Plugins"), |
112 "eric7": os.path.join(getConfig('ericDir'), "Plugins"), |
113 "global": os.path.join(Utilities.getPythonLibraryDirectory(), |
113 "global": os.path.join(Utilities.getPythonLibraryDirectory(), |
114 "eric6plugins"), |
114 "eric7plugins"), |
115 "user": os.path.join(Utilities.getConfigDir(), "eric6plugins"), |
115 "user": os.path.join(Utilities.getConfigDir(), "eric7plugins"), |
116 } |
116 } |
117 self.__priorityOrder = ["eric6", "global", "user"] |
117 self.__priorityOrder = ["eric7", "global", "user"] |
118 |
118 |
119 self.__defaultDownloadDir = os.path.join( |
119 self.__defaultDownloadDir = os.path.join( |
120 Utilities.getConfigDir(), "Downloads") |
120 Utilities.getConfigDir(), "Downloads") |
121 |
121 |
122 self.__activePlugins = {} |
122 self.__activePlugins = {} |
234 f.write('Package containing the global plugins.' + "\n") |
234 f.write('Package containing the global plugins.' + "\n") |
235 f.write('"""' + "\n") |
235 f.write('"""' + "\n") |
236 except OSError: |
236 except OSError: |
237 del self.pluginDirs["global"] |
237 del self.pluginDirs["global"] |
238 |
238 |
239 if not os.path.exists(self.pluginDirs["eric6"]): |
239 if not os.path.exists(self.pluginDirs["eric7"]): |
240 return ( |
240 return ( |
241 False, |
241 False, |
242 self.tr( |
242 self.tr( |
243 "The internal plugin directory <b>{0}</b>" |
243 "The internal plugin directory <b>{0}</b>" |
244 " does not exits.").format(self.pluginDirs["eric6"])) |
244 " does not exits.").format(self.pluginDirs["eric7"])) |
245 |
245 |
246 return (True, "") |
246 return (True, "") |
247 |
247 |
248 def __pluginModulesExist(self): |
248 def __pluginModulesExist(self): |
249 """ |
249 """ |
256 not os.path.exists(self.__develPluginFile) |
256 not os.path.exists(self.__develPluginFile) |
257 ): |
257 ): |
258 return False |
258 return False |
259 |
259 |
260 self.__foundCoreModules = self.getPluginModules( |
260 self.__foundCoreModules = self.getPluginModules( |
261 self.pluginDirs["eric6"]) |
261 self.pluginDirs["eric7"]) |
262 if Preferences.getPluginManager("ActivateExternal"): |
262 if Preferences.getPluginManager("ActivateExternal"): |
263 if "global" in self.pluginDirs: |
263 if "global" in self.pluginDirs: |
264 self.__foundGlobalModules = self.getPluginModules( |
264 self.__foundGlobalModules = self.getPluginModules( |
265 self.pluginDirs["global"]) |
265 self.pluginDirs["global"]) |
266 if "user" in self.pluginDirs: |
266 if "user" in self.pluginDirs: |
337 self.loadPlugin(pluginName, self.pluginDirs["user"]) |
337 self.loadPlugin(pluginName, self.pluginDirs["user"]) |
338 |
338 |
339 for pluginName in self.__foundCoreModules: |
339 for pluginName in self.__foundCoreModules: |
340 # plug-in under development has priority |
340 # plug-in under development has priority |
341 if pluginName != develPluginName: |
341 if pluginName != develPluginName: |
342 self.loadPlugin(pluginName, self.pluginDirs["eric6"]) |
342 self.loadPlugin(pluginName, self.pluginDirs["eric7"]) |
343 |
343 |
344 if develPluginName: |
344 if develPluginName: |
345 self.loadPlugin(develPluginName, develPluginPath) |
345 self.loadPlugin(develPluginName, develPluginPath) |
346 self.__develPluginName = develPluginName |
346 self.__develPluginName = develPluginName |
347 |
347 |
375 self.loadPlugin(pluginName, self.pluginDirs["user"]) |
375 self.loadPlugin(pluginName, self.pluginDirs["user"]) |
376 |
376 |
377 for pluginName in self.__foundCoreModules: |
377 for pluginName in self.__foundCoreModules: |
378 # plug-in under development has priority |
378 # plug-in under development has priority |
379 if pluginName.startswith("PluginDocumentationSets"): |
379 if pluginName.startswith("PluginDocumentationSets"): |
380 self.loadPlugin(pluginName, self.pluginDirs["eric6"]) |
380 self.loadPlugin(pluginName, self.pluginDirs["eric7"]) |
381 |
381 |
382 def loadPlugin(self, name, directory, reload_=False, install=False): |
382 def loadPlugin(self, name, directory, reload_=False, install=False): |
383 """ |
383 """ |
384 Public method to load a plugin module. |
384 Public method to load a plugin module. |
385 |
385 |
424 ) |
424 ) |
425 self.__failedModules[name] = module |
425 self.__failedModules[name] = module |
426 raise PluginLoadError(name) |
426 raise PluginLoadError(name) |
427 else: |
427 else: |
428 self.__onDemandInactiveModules[name] = module |
428 self.__onDemandInactiveModules[name] = module |
429 module.eric6PluginModuleName = name |
429 module.eric7PluginModuleName = name |
430 module.eric6PluginModuleFilename = fname |
430 module.eric7PluginModuleFilename = fname |
431 if install and hasattr(module, "installDependencies"): |
431 if install and hasattr(module, "installDependencies"): |
432 # ask the module to install its dependencies |
432 # ask the module to install its dependencies |
433 module.installDependencies(self.pipInstall) |
433 module.installDependencies(self.pipInstall) |
434 self.__modulesCount += 1 |
434 self.__modulesCount += 1 |
435 if reload_: |
435 if reload_: |
533 module = self.__onDemandInactiveModules[name] |
533 module = self.__onDemandInactiveModules[name] |
534 except KeyError: |
534 except KeyError: |
535 return |
535 return |
536 |
536 |
537 if not self.__canActivatePlugin(module): |
537 if not self.__canActivatePlugin(module): |
538 raise PluginActivationError(module.eric6PluginModuleName) |
538 raise PluginActivationError(module.eric7PluginModuleName) |
539 version = getattr(module, "version", "0.0.0") |
539 version = getattr(module, "version", "0.0.0") |
540 className = getattr(module, "className", "") |
540 className = getattr(module, "className", "") |
541 pluginClass = getattr(module, className) |
541 pluginClass = getattr(module, className) |
542 pluginObject = None |
542 pluginObject = None |
543 if name not in self.__onDemandInactivePlugins: |
543 if name not in self.__onDemandInactivePlugins: |
544 pluginObject = pluginClass(self.__ui) |
544 pluginObject = pluginClass(self.__ui) |
545 pluginObject.eric6PluginModule = module |
545 pluginObject.eric7PluginModule = module |
546 pluginObject.eric6PluginName = className |
546 pluginObject.eric7PluginName = className |
547 pluginObject.eric6PluginVersion = version |
547 pluginObject.eric7PluginVersion = version |
548 self.__onDemandInactivePlugins[name] = pluginObject |
548 self.__onDemandInactivePlugins[name] = pluginObject |
549 except PluginActivationError: |
549 except PluginActivationError: |
550 return |
550 return |
551 |
551 |
552 def initPluginToolbars(self, toolbarManager): |
552 def initPluginToolbars(self, toolbarManager): |
603 ) |
603 ) |
604 except KeyError: |
604 except KeyError: |
605 return None |
605 return None |
606 |
606 |
607 if not self.__canActivatePlugin(module): |
607 if not self.__canActivatePlugin(module): |
608 raise PluginActivationError(module.eric6PluginModuleName) |
608 raise PluginActivationError(module.eric7PluginModuleName) |
609 version = getattr(module, "version", "0.0.0") |
609 version = getattr(module, "version", "0.0.0") |
610 className = getattr(module, "className", "") |
610 className = getattr(module, "className", "") |
611 pluginClass = getattr(module, className) |
611 pluginClass = getattr(module, className) |
612 pluginObject = None |
612 pluginObject = None |
613 if onDemand and name in self.__onDemandInactivePlugins: |
613 if onDemand and name in self.__onDemandInactivePlugins: |
630 ok = False |
630 ok = False |
631 if not ok: |
631 if not ok: |
632 return None |
632 return None |
633 |
633 |
634 self.pluginActivated.emit(name, pluginObject) |
634 self.pluginActivated.emit(name, pluginObject) |
635 pluginObject.eric6PluginModule = module |
635 pluginObject.eric7PluginModule = module |
636 pluginObject.eric6PluginName = className |
636 pluginObject.eric7PluginName = className |
637 pluginObject.eric6PluginVersion = version |
637 pluginObject.eric7PluginVersion = version |
638 |
638 |
639 if onDemand: |
639 if onDemand: |
640 self.__onDemandInactiveModules.pop(name) |
640 self.__onDemandInactiveModules.pop(name) |
641 with contextlib.suppress(KeyError): |
641 with contextlib.suppress(KeyError): |
642 self.__onDemandInactivePlugins.pop(name) |
642 self.__onDemandInactivePlugins.pop(name) |
665 plug-in class format |
665 plug-in class format |
666 """ |
666 """ |
667 try: |
667 try: |
668 if not hasattr(module, "version"): |
668 if not hasattr(module, "version"): |
669 raise PluginModuleFormatError( |
669 raise PluginModuleFormatError( |
670 module.eric6PluginModuleName, "version") |
670 module.eric7PluginModuleName, "version") |
671 if not hasattr(module, "className"): |
671 if not hasattr(module, "className"): |
672 raise PluginModuleFormatError( |
672 raise PluginModuleFormatError( |
673 module.eric6PluginModuleName, "className") |
673 module.eric7PluginModuleName, "className") |
674 className = getattr(module, "className", "") |
674 className = getattr(module, "className", "") |
675 if not className or not hasattr(module, className): |
675 if not className or not hasattr(module, className): |
676 raise PluginModuleFormatError( |
676 raise PluginModuleFormatError( |
677 module.eric6PluginModuleName, className) |
677 module.eric7PluginModuleName, className) |
678 pluginClass = getattr(module, className) |
678 pluginClass = getattr(module, className) |
679 if not hasattr(pluginClass, "__init__"): |
679 if not hasattr(pluginClass, "__init__"): |
680 raise PluginClassFormatError( |
680 raise PluginClassFormatError( |
681 module.eric6PluginModuleName, |
681 module.eric7PluginModuleName, |
682 className, "__init__") |
682 className, "__init__") |
683 if not hasattr(pluginClass, "activate"): |
683 if not hasattr(pluginClass, "activate"): |
684 raise PluginClassFormatError( |
684 raise PluginClassFormatError( |
685 module.eric6PluginModuleName, |
685 module.eric7PluginModuleName, |
686 className, "activate") |
686 className, "activate") |
687 if not hasattr(pluginClass, "deactivate"): |
687 if not hasattr(pluginClass, "deactivate"): |
688 raise PluginClassFormatError( |
688 raise PluginClassFormatError( |
689 module.eric6PluginModuleName, |
689 module.eric7PluginModuleName, |
690 className, "deactivate") |
690 className, "deactivate") |
691 return True |
691 return True |
692 except PluginModuleFormatError as e: |
692 except PluginModuleFormatError as e: |
693 print(repr(e)) |
693 print(repr(e)) |
694 return False |
694 return False |
890 # should not happen |
890 # should not happen |
891 return None |
891 return None |
892 |
892 |
893 details["moduleName"] = name |
893 details["moduleName"] = name |
894 details["moduleFileName"] = getattr( |
894 details["moduleFileName"] = getattr( |
895 module, "eric6PluginModuleFilename", "") |
895 module, "eric7PluginModuleFilename", "") |
896 details["pluginName"] = getattr(module, "name", "") |
896 details["pluginName"] = getattr(module, "name", "") |
897 details["version"] = getattr(module, "version", "") |
897 details["version"] = getattr(module, "version", "") |
898 details["author"] = getattr(module, "author", "") |
898 details["author"] = getattr(module, "author", "") |
899 details["description"] = getattr(module, "longDescription", "") |
899 details["description"] = getattr(module, "longDescription", "") |
900 details["autoactivate"] = autoactivate |
900 details["autoactivate"] = autoactivate |