src/eric7/PipInterface/PipLicensesDialog.py

branch
eric7
changeset 9851
ec12090e9cd9
parent 9850
20c49b517679
child 9940
a57c188857e9
child 10439
21c28b0f9e41
equal deleted inserted replaced
9850:20c49b517679 9851:ec12090e9cd9
8 """ 8 """
9 9
10 import csv 10 import csv
11 import os 11 import os
12 import re 12 import re
13
14 from collections import Counter
13 15
14 from PyQt6.QtCore import Qt, pyqtSlot 16 from PyQt6.QtCore import Qt, pyqtSlot
15 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem 17 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem
16 18
17 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor 19 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor
30 LicensesLicenseColumn = 2 32 LicensesLicenseColumn = 2
31 33
32 SummaryCountColumn = 0 34 SummaryCountColumn = 0
33 SummaryLicenseColumn = 1 35 SummaryLicenseColumn = 1
34 36
35 def __init__( 37 def __init__(self, pip, environment, packages=None, parent=None):
36 self, pip, environment, localPackages=True, usersite=False, parent=None
37 ):
38 """ 38 """
39 Constructor 39 Constructor
40 40
41 @param pip reference to the pip interface object 41 @param pip reference to the pip interface object
42 @type Pip 42 @type Pip
43 @param environment name of the environment to show the licenses for 43 @param environment name of the environment to show the licenses for
44 @type str 44 @type str
45 @param localPackages flag indicating to show the licenses for local 45 @param packages list of packages to show licenses for (or None to show all
46 packages only 46 licenses (defaults to None)
47 @type bool 47 @type list (optional)
48 @param usersite flag indicating to show the licenses for packages
49 installed in user-site directory only
50 @type bool
51 @param parent reference to the parent widget (defaults to None) 48 @param parent reference to the parent widget (defaults to None)
52 @type QWidget (optional) 49 @type QWidget (optional)
53 """ 50 """
54 super().__init__(parent) 51 super().__init__(parent)
55 self.setupUi(self) 52 self.setupUi(self)
56 53
57 self.__pip = pip 54 self.__pip = pip
58 self.__environment = environment 55 self.__environment = environment
56 self.__packages = packages[:] if packages is not None else None
59 57
60 self.__allFilter = self.tr("<All>") 58 self.__allFilter = self.tr("<All>")
61 59
62 self.__saveCSVButton = self.buttonBox.addButton( 60 self.__saveCSVButton = self.buttonBox.addButton(
63 self.tr("Save as CSV..."), QDialogButtonBox.ButtonRole.ActionRole 61 self.tr("Save as CSV..."), QDialogButtonBox.ButtonRole.ActionRole
89 self.licensesList.clear() 87 self.licensesList.clear()
90 self.summaryList.clear() 88 self.summaryList.clear()
91 self.licenseFilterComboBox.clear() 89 self.licenseFilterComboBox.clear()
92 90
93 licensesForFilter = set() 91 licensesForFilter = set()
92 licenseSummaryList = []
94 93
95 # step 1: show the licenses per package 94 # step 1: show the licenses per package
96 self.licensesList.setUpdatesEnabled(False) 95 self.licensesList.setUpdatesEnabled(False)
97 licenses = self.__pip.getLicenses(self.__environment) 96 licenses = self.__pip.getLicenses(self.__environment)
98 for lic in licenses: 97 for lic in licenses:
99 QTreeWidgetItem( 98 if self.__packages is None or lic["Name"] in self.__packages:
100 self.licensesList, 99 QTreeWidgetItem(
101 [ 100 self.licensesList,
102 lic["Name"], 101 [
103 lic["Version"], 102 lic["Name"],
104 lic["License"].replace("; ", "\n"), 103 lic["Version"],
105 ], 104 lic["License"].replace("; ", "\n"),
106 ) 105 ],
106 )
107 licenseSummaryList.extend(
108 x.strip() for x in lic["License"].split("; ")
109 )
107 110
108 self.licensesList.sortItems( 111 self.licensesList.sortItems(
109 PipLicensesDialog.LicensesPackageColumn, Qt.SortOrder.AscendingOrder 112 PipLicensesDialog.LicensesPackageColumn, Qt.SortOrder.AscendingOrder
110 ) 113 )
111 for col in range(self.licensesList.columnCount()): 114 for col in range(self.licensesList.columnCount()):
112 self.licensesList.resizeColumnToContents(col) 115 self.licensesList.resizeColumnToContents(col)
113 self.licensesList.setUpdatesEnabled(True) 116 self.licensesList.setUpdatesEnabled(True)
114 117
115 # step 2: show the licenses summary 118 # step 2: show the licenses summary
116 self.summaryList.setUpdatesEnabled(False) 119 self.summaryList.setUpdatesEnabled(False)
117 licenses = self.__pip.getLicensesSummary(self.__environment) 120 licenseCounter = Counter(licenseSummaryList)
118 for lic in licenses: 121 for lic in licenseCounter:
119 QTreeWidgetItem( 122 QTreeWidgetItem(
120 self.summaryList, 123 self.summaryList,
121 [ 124 [
122 "{0:4d}".format(lic["Count"]), 125 "{0:4d}".format(licenseCounter[lic]),
123 lic["License"].replace("; ", "\n"), 126 lic,
124 ], 127 ],
125 ) 128 )
126 licensesForFilter |= set(lic["License"].split("; ")) 129 licensesForFilter.add(lic)
127 130
128 self.summaryList.sortItems( 131 self.summaryList.sortItems(
129 PipLicensesDialog.SummaryLicenseColumn, Qt.SortOrder.AscendingOrder 132 PipLicensesDialog.SummaryLicenseColumn, Qt.SortOrder.AscendingOrder
130 ) 133 )
131 for col in range(self.summaryList.columnCount()): 134 for col in range(self.summaryList.columnCount()):

eric ide

mercurial