Modified the SetupWizardDialog to adhere to the pyproject.toml guidelines wrt. the license entry. eric7

Wed, 02 Apr 2025 16:46:15 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 02 Apr 2025 16:46:15 +0200
branch
eric7
changeset 11203
2ea34362b6b6
parent 11202
6d4838c04feb
child 11204
5cffd6e2b1d6

Modified the SetupWizardDialog to adhere to the pyproject.toml guidelines wrt. the license entry.

pyproject.toml file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardSetup.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.ui file | annotate | diff | comparison | revisions
src/eric7/Plugins/WizardPlugins/SetupWizard/Ui_SetupWizardDialog.py file | annotate | diff | comparison | revisions
--- a/pyproject.toml	Wed Apr 02 16:44:07 2025 +0200
+++ b/pyproject.toml	Wed Apr 02 16:46:15 2025 +0200
@@ -90,6 +90,7 @@
     "fido2",
     "requests",
     "pyusb>=1.2.0",
+    "spdx-license-list>= 3.26.0",
     "pywin32>=1.0;platform_system=='Windows'",
     "command-runner;platform_system=='Windows'",
 ]
--- a/src/eric7/Plugins/PluginWizardSetup.py	Wed Apr 02 16:44:07 2025 +0200
+++ b/src/eric7/Plugins/PluginWizardSetup.py	Wed Apr 02 16:46:15 2025 +0200
@@ -81,44 +81,48 @@
         Private method to initialize the actions.
         """
         # 1. action for 'setup.py' creation
+        # Note: Use of setup.py is deprecated.
         act = EricAction(
-            self.tr("setup.py Wizard"),
-            self.tr("setup.py Wizard..."),
+            self.tr("setup.py Wizard (deprecated)"),
+            self.tr("setup.py Wizard (deprecated)..."),
             0,
             0,
             self,
             "wizards_setup_py",
         )
-        act.setStatusTip(self.tr("setup.py Wizard"))
+        act.setStatusTip(self.tr("setup.py Wizard (deprecated)"))
         act.setWhatsThis(
             self.tr(
-                """<b>setup.py Wizard</b>"""
+                """<b>setup.py Wizard (deprecated)</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>"""
+                """</p><p><b>Note:</b> The use of setup.py is deprecated. Use"""
+                """ <b>pyproject.toml</b> instead."""
             )
         )
         act.triggered.connect(functools.partial(self.__handle, "setup.py"))
         self.__actions.append(act)
 
         # 2. action for 'setup.cfg' creation
+        # Note: Use of setup.cfg is deprecated.
         act = EricAction(
-            self.tr("setup.cfg Wizard"),
-            self.tr("setup.cfg Wizard..."),
+            self.tr("setup.cfg Wizard (deprecated)"),
+            self.tr("setup.cfg Wizard (deprecated)..."),
             0,
             0,
             self,
             "wizards_setup_cfg",
         )
-        act.setStatusTip(self.tr("setup.cfg Wizard"))
+        act.setStatusTip(self.tr("setup.cfg Wizard (deprecated)"))
         act.setWhatsThis(
             self.tr(
-                """<b>setup.cfg Wizard</b>"""
+                """<b>setup.cfg Wizard (deprecated)</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>"""
+                """</p><p><b>Note:</b> The use of setup.cfg is deprecated. Use"""
+                """ <b>pyproject.toml</b> instead."""
             )
         )
         act.triggered.connect(functools.partial(self.__handle, "setup.cfg"))
--- a/src/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.py	Wed Apr 02 16:44:07 2025 +0200
+++ b/src/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.py	Wed Apr 02 16:46:15 2025 +0200
@@ -13,6 +13,7 @@
 import os
 import pathlib
 
+import spdx_license_list
 import tomlkit
 import trove_classifiers
 
@@ -89,6 +90,16 @@
             lineEdit.setStyleSheet(self.__mandatoryStyleSheet)
 
         self.__populateClassifiers()
+        if category == "pyproject.toml":
+            self.licenseClassifierCheckBox.setText(
+                self.tr("Select From SPDX License List")
+            )
+            self.__populateSpdxLicenses()
+        else:
+            self.licenseClassifierCheckBox.setText(
+                self.tr("Select From Trove License Classifiers")
+            )
+            self.__populateTroveLicenses()
 
         self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
         self.__okButton.setEnabled(False)
@@ -141,7 +152,6 @@
         """
         Private method to populate the classifiers.
         """
-        self.licenseClassifierComboBox.clear()
         self.classifiersList.clear()
         self.developmentStatusComboBox.clear()
 
@@ -150,9 +160,8 @@
         self.__classifiersDict = {}
         for classifier in trove_classifiers.sorted_classifiers:
             if classifier.startswith("License ::"):
-                self.licenseClassifierComboBox.addItem(
-                    "/".join(classifier.split(" :: ")[1:]), classifier
-                )
+                # These are handled separately for setup.py and setup.cfg.
+                continue
             elif classifier.startswith("Development Status ::"):
                 self.developmentStatusComboBox.addItem(
                     classifier.split(" :: ")[1], classifier
@@ -161,12 +170,6 @@
                 self.__addClassifierEntry(classifier)
         self.__classifiersDict = {}
 
-        self.licenseClassifierComboBox.setCurrentIndex(
-            self.licenseClassifierComboBox.findText(
-                "(GPLv3)", Qt.MatchFlag.MatchContains | Qt.MatchFlag.MatchCaseSensitive
-            )
-        )
-
     def __addClassifierEntry(self, classifier):
         """
         Private method to add a new entry to the list of trove classifiers.
@@ -192,6 +195,46 @@
         itm.setCheckState(0, Qt.CheckState.Unchecked)
         itm.setData(0, Qt.ItemDataRole.UserRole, classifier)
 
+    def __populateTroveLicenses(self):
+        """
+        Private method to populate the license selector for the creation of a
+        setup.py or setup.cfg file.
+
+        Note: These files are deprecated in favor of pyproject.toml.
+        """
+        self.licenseClassifierComboBox.clear()
+
+        for classifier in trove_classifiers.sorted_classifiers:
+            if classifier.startswith("License ::"):
+                self.licenseClassifierComboBox.addItem(
+                    "/".join(classifier.split(" :: ")[1:]), classifier
+                )
+
+        self.licenseClassifierComboBox.setCurrentIndex(
+            self.licenseClassifierComboBox.findText(
+                "(GPLv3)",
+                Qt.MatchFlag.MatchContains | Qt.MatchFlag.MatchCaseSensitive,
+            )
+        )
+
+    def __populateSpdxLicenses(self):
+        """
+        Private method to populate the license selector for the creation of a
+        pyproject.toml file.
+        """
+        self.licenseClassifierComboBox.clear()
+
+        for spdxLicense in spdx_license_list.LICENSES.values():
+            if not spdxLicense.deprecated_id:
+                self.licenseClassifierComboBox.addItem(spdxLicense.name, spdxLicense.id)
+
+        self.licenseClassifierComboBox.setCurrentIndex(
+            self.licenseClassifierComboBox.findData(
+                "GPL-3.0",
+                flags=Qt.MatchFlag.MatchStartsWith | Qt.MatchFlag.MatchCaseSensitive,
+            )
+        )
+
     def __getLicenseText(self):
         """
         Private method to get the license text.
@@ -688,17 +731,14 @@
                 urls[urlItem.text(0)] = urlItem.text(1)
         project["urls"] = urls
 
-        classifiers = []
-        if not self.licenseClassifierCheckBox.isChecked():
-            licenseTbl = tomlkit.table()
-            licenseTbl["text"] = self.licenseEdit.text()
-            project["license"] = licenseTbl
+        if self.licenseClassifierCheckBox.isChecked():
+            project["license"] = self.licenseClassifierComboBox.itemData(
+                self.licenseClassifierComboBox.currentIndex()
+            )
         else:
-            classifiers.append(
-                self.licenseClassifierComboBox.itemData(
-                    self.licenseClassifierComboBox.currentIndex()
-                )
-            )
+            project["license"] = self.licenseEdit.text()
+
+        classifiers = []
 
         if self.developmentStatusComboBox.currentIndex() != 0:
             classifiers.append(self.developmentStatusComboBox.currentData())
--- a/src/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.ui	Wed Apr 02 16:44:07 2025 +0200
+++ b/src/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.ui	Wed Apr 02 16:46:15 2025 +0200
@@ -72,7 +72,7 @@
         </sizepolicy>
        </property>
        <property name="focusPolicy">
-        <enum>Qt::StrongFocus</enum>
+        <enum>Qt::FocusPolicy::StrongFocus</enum>
        </property>
        <property name="toolTip">
         <string>Enter the root directory</string>
@@ -84,7 +84,7 @@
    <item>
     <widget class="QTabWidget" name="dataTabWidget">
      <property name="currentIndex">
-      <number>8</number>
+      <number>0</number>
      </property>
      <widget class="QWidget" name="basicTab">
       <attribute name="title">
@@ -234,7 +234,7 @@
        <item row="7" column="1" colspan="2">
         <spacer name="verticalSpacer">
          <property name="orientation">
-          <enum>Qt::Vertical</enum>
+          <enum>Qt::Orientation::Vertical</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
@@ -373,7 +373,7 @@
           <string>Project URLs:</string>
          </property>
          <property name="alignment">
-          <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+          <set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
          </property>
         </widget>
        </item>
@@ -383,7 +383,7 @@
           <bool>true</bool>
          </property>
          <property name="selectionMode">
-          <enum>QAbstractItemView::ExtendedSelection</enum>
+          <enum>QAbstractItemView::SelectionMode::ExtendedSelection</enum>
          </property>
          <property name="rootIsDecorated">
           <bool>false</bool>
@@ -447,7 +447,7 @@
          <item>
           <spacer name="horizontalSpacer_2">
            <property name="orientation">
-            <enum>Qt::Horizontal</enum>
+            <enum>Qt::Orientation::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
@@ -496,7 +496,7 @@
        <item>
         <spacer name="verticalSpacer_3">
          <property name="orientation">
-          <enum>Qt::Vertical</enum>
+          <enum>Qt::Orientation::Vertical</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
@@ -549,7 +549,7 @@
          <item>
           <spacer name="horizontalSpacer_3">
            <property name="orientation">
-            <enum>Qt::Horizontal</enum>
+            <enum>Qt::Orientation::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
@@ -600,7 +600,7 @@
        <item row="0" column="1">
         <widget class="EricPathPicker" name="sourceDirectoryPicker" native="true">
          <property name="focusPolicy">
-          <enum>Qt::StrongFocus</enum>
+          <enum>Qt::FocusPolicy::StrongFocus</enum>
          </property>
          <property name="toolTip">
           <string>Enter the source directory for the 'find_packages()' call</string>
@@ -613,7 +613,7 @@
           <string>Exclude Patterns:</string>
          </property>
          <property name="alignment">
-          <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+          <set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
          </property>
         </widget>
        </item>
@@ -623,7 +623,7 @@
           <bool>true</bool>
          </property>
          <property name="selectionMode">
-          <enum>QAbstractItemView::ExtendedSelection</enum>
+          <enum>QAbstractItemView::SelectionMode::ExtendedSelection</enum>
          </property>
          <property name="sortingEnabled">
           <bool>true</bool>
@@ -690,7 +690,7 @@
           <bool>true</bool>
          </property>
          <property name="selectionMode">
-          <enum>QAbstractItemView::ExtendedSelection</enum>
+          <enum>QAbstractItemView::SelectionMode::ExtendedSelection</enum>
          </property>
          <property name="sortingEnabled">
           <bool>true</bool>
@@ -725,7 +725,7 @@
          <item>
           <spacer name="horizontalSpacer_5">
            <property name="orientation">
-            <enum>Qt::Horizontal</enum>
+            <enum>Qt::Orientation::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
@@ -750,7 +750,7 @@
           <bool>true</bool>
          </property>
          <property name="selectionMode">
-          <enum>QAbstractItemView::ExtendedSelection</enum>
+          <enum>QAbstractItemView::SelectionMode::ExtendedSelection</enum>
          </property>
          <property name="rootIsDecorated">
           <bool>false</bool>
@@ -819,7 +819,7 @@
          <item>
           <spacer name="horizontalSpacer_4">
            <property name="orientation">
-            <enum>Qt::Horizontal</enum>
+            <enum>Qt::Orientation::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
@@ -850,7 +850,7 @@
      <item>
       <spacer name="horizontalSpacer">
        <property name="orientation">
-        <enum>Qt::Horizontal</enum>
+        <enum>Qt::Orientation::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
@@ -863,10 +863,10 @@
      <item>
       <widget class="QDialogButtonBox" name="buttonBox">
        <property name="orientation">
-        <enum>Qt::Horizontal</enum>
+        <enum>Qt::Orientation::Horizontal</enum>
        </property>
        <property name="standardButtons">
-        <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+        <set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
        </property>
       </widget>
      </item>
--- a/src/eric7/Plugins/WizardPlugins/SetupWizard/Ui_SetupWizardDialog.py	Wed Apr 02 16:44:07 2025 +0200
+++ b/src/eric7/Plugins/WizardPlugins/SetupWizard/Ui_SetupWizardDialog.py	Wed Apr 02 16:46:15 2025 +0200
@@ -1,6 +1,6 @@
 # Form implementation generated from reading ui file 'src/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.ui'
 #
-# Created by: PyQt6 UI code generator 6.7.0
+# Created by: PyQt6 UI code generator 6.8.1
 #
 # WARNING: Any manual changes made to this file will be lost when pyuic6 is
 # run again.  Do not edit this file unless you know what you are doing.
@@ -349,7 +349,7 @@
         self.verticalLayout.addLayout(self.horizontalLayout)
 
         self.retranslateUi(SetupWizardDialog)
-        self.dataTabWidget.setCurrentIndex(8)
+        self.dataTabWidget.setCurrentIndex(0)
         self.buttonBox.accepted.connect(SetupWizardDialog.accept) # type: ignore
         self.buttonBox.rejected.connect(SetupWizardDialog.reject) # type: ignore
         self.licenseClassifierCheckBox.toggled['bool'].connect(self.licenseClassifierComboBox.setEnabled) # type: ignore

eric ide

mercurial