Sat, 02 Jul 2022 18:53:56 +0200
setup Wizard
- added support for 'project_urls'
- added support for 'entry_points'
- added a variant to create a 'setup.cfg' file
- added a variant to create a 'pyproject.toml' file
# -*- coding: utf-8 -*- # Copyright (c) 2013 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the setup.py wizard plug-in. """ import functools from PyQt6.QtCore import QObject from PyQt6.QtWidgets import QDialog from EricWidgets.EricApplication import ericApp from EricGui.EricAction import EricAction from EricWidgets import EricMessageBox import UI.Info # Start-of-Header name = "setup.py Wizard Plug-in" author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True version = UI.Info.VersionOnly className = "SetupWizard" packageName = "__core__" shortDescription = "Wizard for the creation of a setup.py file." longDescription = ( """This plug-in implements a wizard to generate code for""" """ a setup.py file. It supports the 'setuptools' variant.""" ) needsRestart = False pyqtApi = 2 # End-of-Header error = "" class SetupWizard(QObject): """ Class implementing the setup.py wizard plug-in. """ def __init__(self, ui): """ Constructor @param ui reference to the user interface object @type UI.UserInterface """ super().__init__(ui) self.__ui = ui self.__actions = [] def activate(self): """ Public method to activate this plug-in. @return tuple of None and activation status @rtype tuple of (None, boolean) """ self.__initActions() self.__initMenu() return None, True def deactivate(self): """ Public method to deactivate this plug-in. """ menu = self.__ui.getMenu("wizards") if menu: for act in self.__actions: menu.removeAction(act) self.__ui.removeEricActions(self.__actions, 'wizards') def __initActions(self): """ Private method to initialize the actions. """ # 1. action for 'setup.py' creation act = EricAction( self.tr('setup.py Wizard'), self.tr('setup.py Wizard...'), 0, 0, self, 'wizards_setup_py') act.setStatusTip(self.tr('setup.py Wizard')) act.setWhatsThis(self.tr( """<b>setup.py Wizard</b>""" """<p>This wizard opens a dialog for entering all the parameters""" """ needed to create the basic contents of a setup.py file. The""" """ generated code is inserted at the current cursor position.""" """</p>""" )) act.triggered.connect(functools.partial(self.__handle, "setup.py")) self.__actions.append(act) # 2. action for 'setup.cfg' creation act = EricAction( self.tr('setup.cfg Wizard'), self.tr('setup.cfg Wizard...'), 0, 0, self, 'wizards_setup_cfg') act.setStatusTip(self.tr('setup.cfg Wizard')) act.setWhatsThis(self.tr( """<b>setup.cfg Wizard</b>""" """<p>This wizard opens a dialog for entering all the parameters""" """ needed to create the basic contents of a setup.cfg file. The""" """ generated code is inserted at the current cursor position.""" """</p>""" )) act.triggered.connect(functools.partial(self.__handle, "setup.cfg")) self.__actions.append(act) # 3. action for 'pyproject.toml' creation act = EricAction( self.tr('pyproject.toml Wizard'), self.tr('pyproject.toml Wizard...'), 0, 0, self, 'wizards_pyproject_toml') act.setStatusTip(self.tr('pyproject.toml Wizard')) act.setWhatsThis(self.tr( """<b>pyproject.toml Wizard</b>""" """<p>This wizard opens a dialog for entering all the parameters""" """ needed to create the basic contents of a pyproject.toml file. The""" """ generated code is inserted at the current cursor position.""" """</p>""" )) act.triggered.connect(functools.partial(self.__handle, "pyproject.toml")) self.__actions.append(act) self.__ui.addEricActions(self.__actions, 'wizards') def __initMenu(self): """ Private method to add the actions to the right menu. """ menu = self.__ui.getMenu("wizards") if menu: menu.addActions(self.__actions) def __callForm(self, editor, category): """ Private method to display a dialog and get the code. @param editor reference to the current editor @type Editor @param category category of setup file to create @type str @return tuple containing the generated code and a flag indicating an error @rtype tuple of (str, bool) """ from WizardPlugins.SetupWizard.SetupWizardDialog import ( SetupWizardDialog ) dlg = SetupWizardDialog(category, self.__ui) if dlg.exec() == QDialog.DialogCode.Accepted: line, index = editor.getCursorPosition() indLevel = editor.indentation(line) // editor.indentationWidth() if editor.indentationsUseTabs(): indString = '\t' else: indString = editor.indentationWidth() * ' ' return (dlg.getCode(indLevel, indString), True) else: return ("", False) def __handle(self, category): """ Private method to handle the wizards action. @param category category of setup file to create @type str """ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: EricMessageBox.critical( self.__ui, self.tr('No current editor'), self.tr('Please open or create a file first.')) else: sourceCode, ok = self.__callForm(editor, category) if ok: line, index = editor.getCursorPosition() # It should be done this way to allow undo editor.beginUndoAction() editor.insertAt(sourceCode, line, index) editor.endUndoAction() # # eflag: noqa = M801