src/eric7/PipInterface/PipLicensesDialog.py

branch
eric7
changeset 9851
ec12090e9cd9
parent 9850
20c49b517679
child 9940
a57c188857e9
child 10439
21c28b0f9e41
diff -r 20c49b517679 -r ec12090e9cd9 src/eric7/PipInterface/PipLicensesDialog.py
--- a/src/eric7/PipInterface/PipLicensesDialog.py	Sun Mar 05 17:07:49 2023 +0100
+++ b/src/eric7/PipInterface/PipLicensesDialog.py	Mon Mar 06 09:50:18 2023 +0100
@@ -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>")
 
@@ -91,19 +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)
             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
@@ -114,16 +117,16 @@
 
             # step 2: show the licenses summary
             self.summaryList.setUpdatesEnabled(False)
-            licenses = self.__pip.getLicensesSummary(self.__environment)
-            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

eric ide

mercurial