diff -r 9308099b7d38 -r a57c188857e9 src/eric7/PipInterface/PipLicensesDialog.py --- a/src/eric7/PipInterface/PipLicensesDialog.py Wed Mar 01 09:06:13 2023 +0100 +++ b/src/eric7/PipInterface/PipLicensesDialog.py Wed Mar 29 10:03:06 2023 +0200 @@ -11,6 +11,8 @@ import os import re +from collections import Counter + from PyQt6.QtCore import Qt, pyqtSlot from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem @@ -32,9 +34,7 @@ SummaryCountColumn = 0 SummaryLicenseColumn = 1 - def __init__( - self, pip, environment, localPackages=True, usersite=False, parent=None - ): + def __init__(self, pip, environment, packages=None, parent=None): """ Constructor @@ -42,12 +42,9 @@ @type Pip @param environment name of the environment to show the licenses for @type str - @param localPackages flag indicating to show the licenses for local - packages only - @type bool - @param usersite flag indicating to show the licenses for packages - installed in user-site directory only - @type bool + @param packages list of packages to show licenses for (or None to show all + licenses (defaults to None) + @type list (optional) @param parent reference to the parent widget (defaults to None) @type QWidget (optional) """ @@ -56,6 +53,7 @@ self.__pip = pip self.__environment = environment + self.__packages = packages[:] if packages is not None else None self.__allFilter = self.tr("<All>") @@ -66,12 +64,6 @@ self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) - self.localCheckBox.setChecked(localPackages) - self.userCheckBox.setChecked(usersite) - - self.localCheckBox.toggled.connect(self.__refreshLicenses) - self.userCheckBox.toggled.connect(self.__refreshLicenses) - if environment: self.environmentLabel.setText( "<b>{0}</b>".format(self.tr('Licenses of "{0}"').format(environment)) @@ -84,12 +76,12 @@ self.__filterPackagesByLicense ) - self.__refreshLicenses() + self.__populateLicenses() @pyqtSlot() - def __refreshLicenses(self): + def __populateLicenses(self): """ - Private slot to refresh the license lists. + Private slot to populate the license lists. """ with EricOverrideCursor(): self.licensesList.clear() @@ -97,23 +89,24 @@ self.licenseFilterComboBox.clear() licensesForFilter = set() + licenseSummaryList = [] # step 1: show the licenses per package self.licensesList.setUpdatesEnabled(False) - licenses = self.__pip.getLicenses( - self.__environment, - localPackages=self.localCheckBox.isChecked(), - usersite=self.userCheckBox.isChecked(), - ) + licenses = self.__pip.getLicenses(self.__environment) for lic in licenses: - QTreeWidgetItem( - self.licensesList, - [ - lic["Name"], - lic["Version"], - lic["License"].replace("; ", "\n"), - ], - ) + if self.__packages is None or lic["Name"] in self.__packages: + QTreeWidgetItem( + self.licensesList, + [ + lic["Name"], + lic["Version"], + lic["License"].replace("; ", "\n"), + ], + ) + licenseSummaryList.extend( + x.strip() for x in lic["License"].split("; ") + ) self.licensesList.sortItems( PipLicensesDialog.LicensesPackageColumn, Qt.SortOrder.AscendingOrder @@ -124,20 +117,16 @@ # step 2: show the licenses summary self.summaryList.setUpdatesEnabled(False) - licenses = self.__pip.getLicensesSummary( - self.__environment, - localPackages=self.localCheckBox.isChecked(), - usersite=self.userCheckBox.isChecked(), - ) - for lic in licenses: + licenseCounter = Counter(licenseSummaryList) + for lic in licenseCounter: QTreeWidgetItem( self.summaryList, [ - "{0:4d}".format(lic["Count"]), - lic["License"].replace("; ", "\n"), + "{0:4d}".format(licenseCounter[lic]), + lic, ], ) - licensesForFilter |= set(lic["License"].split("; ")) + licensesForFilter.add(lic) self.summaryList.sortItems( PipLicensesDialog.SummaryLicenseColumn, Qt.SortOrder.AscendingOrder