11 import datetime |
11 import datetime |
12 import io |
12 import io |
13 import os |
13 import os |
14 import pathlib |
14 import pathlib |
15 |
15 |
|
16 import spdx_license_list |
16 import tomlkit |
17 import tomlkit |
17 import trove_classifiers |
18 import trove_classifiers |
18 |
19 |
19 from PyQt6.QtCore import Qt, pyqtSlot |
20 from PyQt6.QtCore import Qt, pyqtSlot |
20 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem, QTreeWidgetItem |
21 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem, QTreeWidgetItem |
87 self.maintainerEmailEdit, |
88 self.maintainerEmailEdit, |
88 ]: |
89 ]: |
89 lineEdit.setStyleSheet(self.__mandatoryStyleSheet) |
90 lineEdit.setStyleSheet(self.__mandatoryStyleSheet) |
90 |
91 |
91 self.__populateClassifiers() |
92 self.__populateClassifiers() |
|
93 if category == "pyproject.toml": |
|
94 self.licenseClassifierCheckBox.setText( |
|
95 self.tr("Select From SPDX License List") |
|
96 ) |
|
97 self.__populateSpdxLicenses() |
|
98 else: |
|
99 self.licenseClassifierCheckBox.setText( |
|
100 self.tr("Select From Trove License Classifiers") |
|
101 ) |
|
102 self.__populateTroveLicenses() |
92 |
103 |
93 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) |
104 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) |
94 self.__okButton.setEnabled(False) |
105 self.__okButton.setEnabled(False) |
95 |
106 |
96 projectOpen = ericApp().getObject("Project").isOpen() |
107 projectOpen = ericApp().getObject("Project").isOpen() |
139 |
150 |
140 def __populateClassifiers(self): |
151 def __populateClassifiers(self): |
141 """ |
152 """ |
142 Private method to populate the classifiers. |
153 Private method to populate the classifiers. |
143 """ |
154 """ |
144 self.licenseClassifierComboBox.clear() |
|
145 self.classifiersList.clear() |
155 self.classifiersList.clear() |
146 self.developmentStatusComboBox.clear() |
156 self.developmentStatusComboBox.clear() |
147 |
157 |
148 self.developmentStatusComboBox.addItem("", "") |
158 self.developmentStatusComboBox.addItem("", "") |
149 |
159 |
150 self.__classifiersDict = {} |
160 self.__classifiersDict = {} |
151 for classifier in trove_classifiers.sorted_classifiers: |
161 for classifier in trove_classifiers.sorted_classifiers: |
152 if classifier.startswith("License ::"): |
162 if classifier.startswith("License ::"): |
153 self.licenseClassifierComboBox.addItem( |
163 # These are handled separately for setup.py and setup.cfg. |
154 "/".join(classifier.split(" :: ")[1:]), classifier |
164 continue |
155 ) |
|
156 elif classifier.startswith("Development Status ::"): |
165 elif classifier.startswith("Development Status ::"): |
157 self.developmentStatusComboBox.addItem( |
166 self.developmentStatusComboBox.addItem( |
158 classifier.split(" :: ")[1], classifier |
167 classifier.split(" :: ")[1], classifier |
159 ) |
168 ) |
160 else: |
169 else: |
161 self.__addClassifierEntry(classifier) |
170 self.__addClassifierEntry(classifier) |
162 self.__classifiersDict = {} |
171 self.__classifiersDict = {} |
163 |
|
164 self.licenseClassifierComboBox.setCurrentIndex( |
|
165 self.licenseClassifierComboBox.findText( |
|
166 "(GPLv3)", Qt.MatchFlag.MatchContains | Qt.MatchFlag.MatchCaseSensitive |
|
167 ) |
|
168 ) |
|
169 |
172 |
170 def __addClassifierEntry(self, classifier): |
173 def __addClassifierEntry(self, classifier): |
171 """ |
174 """ |
172 Private method to add a new entry to the list of trove classifiers. |
175 Private method to add a new entry to the list of trove classifiers. |
173 |
176 |
189 self.__classifiersDict[key] = itm |
192 self.__classifiersDict[key] = itm |
190 else: |
193 else: |
191 pitm = self.__classifiersDict[key] |
194 pitm = self.__classifiersDict[key] |
192 itm.setCheckState(0, Qt.CheckState.Unchecked) |
195 itm.setCheckState(0, Qt.CheckState.Unchecked) |
193 itm.setData(0, Qt.ItemDataRole.UserRole, classifier) |
196 itm.setData(0, Qt.ItemDataRole.UserRole, classifier) |
|
197 |
|
198 def __populateTroveLicenses(self): |
|
199 """ |
|
200 Private method to populate the license selector for the creation of a |
|
201 setup.py or setup.cfg file. |
|
202 |
|
203 Note: These files are deprecated in favor of pyproject.toml. |
|
204 """ |
|
205 self.licenseClassifierComboBox.clear() |
|
206 |
|
207 for classifier in trove_classifiers.sorted_classifiers: |
|
208 if classifier.startswith("License ::"): |
|
209 self.licenseClassifierComboBox.addItem( |
|
210 "/".join(classifier.split(" :: ")[1:]), classifier |
|
211 ) |
|
212 |
|
213 self.licenseClassifierComboBox.setCurrentIndex( |
|
214 self.licenseClassifierComboBox.findText( |
|
215 "(GPLv3)", |
|
216 Qt.MatchFlag.MatchContains | Qt.MatchFlag.MatchCaseSensitive, |
|
217 ) |
|
218 ) |
|
219 |
|
220 def __populateSpdxLicenses(self): |
|
221 """ |
|
222 Private method to populate the license selector for the creation of a |
|
223 pyproject.toml file. |
|
224 """ |
|
225 self.licenseClassifierComboBox.clear() |
|
226 |
|
227 for spdxLicense in spdx_license_list.LICENSES.values(): |
|
228 if not spdxLicense.deprecated_id: |
|
229 self.licenseClassifierComboBox.addItem(spdxLicense.name, spdxLicense.id) |
|
230 |
|
231 self.licenseClassifierComboBox.setCurrentIndex( |
|
232 self.licenseClassifierComboBox.findData( |
|
233 "GPL-3.0", |
|
234 flags=Qt.MatchFlag.MatchStartsWith | Qt.MatchFlag.MatchCaseSensitive, |
|
235 ) |
|
236 ) |
194 |
237 |
195 def __getLicenseText(self): |
238 def __getLicenseText(self): |
196 """ |
239 """ |
197 Private method to get the license text. |
240 Private method to get the license text. |
198 |
241 |
686 for row in range(self.projectUrlsList.topLevelItemCount()): |
729 for row in range(self.projectUrlsList.topLevelItemCount()): |
687 urlItem = self.projectUrlsList.topLevelItem(row) |
730 urlItem = self.projectUrlsList.topLevelItem(row) |
688 urls[urlItem.text(0)] = urlItem.text(1) |
731 urls[urlItem.text(0)] = urlItem.text(1) |
689 project["urls"] = urls |
732 project["urls"] = urls |
690 |
733 |
|
734 if self.licenseClassifierCheckBox.isChecked(): |
|
735 project["license"] = self.licenseClassifierComboBox.itemData( |
|
736 self.licenseClassifierComboBox.currentIndex() |
|
737 ) |
|
738 else: |
|
739 project["license"] = self.licenseEdit.text() |
|
740 |
691 classifiers = [] |
741 classifiers = [] |
692 if not self.licenseClassifierCheckBox.isChecked(): |
|
693 licenseTbl = tomlkit.table() |
|
694 licenseTbl["text"] = self.licenseEdit.text() |
|
695 project["license"] = licenseTbl |
|
696 else: |
|
697 classifiers.append( |
|
698 self.licenseClassifierComboBox.itemData( |
|
699 self.licenseClassifierComboBox.currentIndex() |
|
700 ) |
|
701 ) |
|
702 |
742 |
703 if self.developmentStatusComboBox.currentIndex() != 0: |
743 if self.developmentStatusComboBox.currentIndex() != 0: |
704 classifiers.append(self.developmentStatusComboBox.currentData()) |
744 classifiers.append(self.developmentStatusComboBox.currentData()) |
705 |
745 |
706 itm = self.classifiersList.topLevelItem(0) |
746 itm = self.classifiersList.topLevelItem(0) |