src/eric7/Preferences/ConfigurationPages/PipPage.py

Tue, 12 Sep 2023 16:59:22 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 12 Sep 2023 16:59:22 +0200
branch
eric7
changeset 10206
d6921563be6c
parent 10069
435cc5875135
child 10428
a071d4065202
permissions
-rw-r--r--

pip Interface
- Added capability to disable display of vulnerability data (e.g. if system does not support HTTPS protocol).

6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
3 # Copyright (c) 2015 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6253
diff changeset
7 Package implementing the pip configuration page.
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
10 from eric7 import Preferences
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
11 from eric7.PipInterface.Pip import Pip
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
12
6782
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
13 from .ConfigurationPageBase import ConfigurationPageBase
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from .Ui_PipPage import Ui_PipPage
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class PipPage(ConfigurationPageBase, Ui_PipPage):
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6253
diff changeset
19 Class implementing the pip configuration page.
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
21
6782
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
22 def __init__(self):
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
26 super().__init__()
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 self.setupUi(self)
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 self.setObjectName("PipPage")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
29
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
30 self.indexLabel.setText(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
31 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
32 "<b>Note:</b> Leave empty to use the default index URL ("
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
33 '<a href="{0}">{0}</a>).'
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
34 ).format(Pip.DefaultPyPiUrl)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36 self.safetyDbMirrorLabel.setText(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
37 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
38 "<b>Note:</b> Leave empty to use the default Safety DB URL ({0})."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39 ).format(Preferences.Prefs.pipDefaults["VulnerabilityDbMirror"])
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
40 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
41
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 # set initial values
6782
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
43 self.indexEdit.setText(Preferences.getPip("PipSearchIndex"))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
44
10206
d6921563be6c pip Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
45 self.vulnerabilityGroup.setChecked(
d6921563be6c pip Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
46 Preferences.getPip("VulnerabilityCheckEnabled")
d6921563be6c pip Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
47 )
8981
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
48 safetyDbUrl = Preferences.getPip("VulnerabilityDbMirror")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49 if safetyDbUrl == Preferences.Prefs.pipDefaults["VulnerabilityDbMirror"]:
8981
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
50 safetyDbUrl = ""
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
51 self.safetyDbMirrorEdit.setText(safetyDbUrl)
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
52 self.validitySpinBox.setValue(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53 Preferences.getPip("VulnerabilityDbCacheValidity") // 3600
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
54 )
8981
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
55 # seconds converted to hours
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57 self.noCondaCheckBox.setChecked(Preferences.getPip("ExcludeCondaEnvironments"))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def save(self):
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Public slot to save the pip configuration.
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
8981
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
63 safetyDbUrl = self.safetyDbMirrorEdit.text().strip()
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
64 if not safetyDbUrl:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
65 safetyDbUrl = Preferences.Prefs.pipDefaults["VulnerabilityDbMirror"]
8981
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
66 safetyDbUrl = safetyDbUrl.replace("\\", "/")
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
67 if not safetyDbUrl.endswith("/"):
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
68 safetyDbUrl += "/"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
70 Preferences.setPip("PipSearchIndex", self.indexEdit.text().strip())
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
71
10206
d6921563be6c pip Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
72 Preferences.setPip(
d6921563be6c pip Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
73 "VulnerabilityCheckEnabled", self.vulnerabilityGroup.isChecked()
d6921563be6c pip Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
74 )
8981
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
75 Preferences.setPip("VulnerabilityDbMirror", safetyDbUrl)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
76 Preferences.setPip(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
77 "VulnerabilityDbCacheValidity", self.validitySpinBox.value() * 3600
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78 )
8981
fa03fe1fd672 Completed implementing a vulnerability checker based on the data of the Safety DB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
79 # hours converted to seconds
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
80
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81 Preferences.setPip("ExcludeCondaEnvironments", self.noCondaCheckBox.isChecked())
6782
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
82
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
83
10069
435cc5875135 Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
84 def create(dlg): # noqa: U100
6782
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
85 """
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
86 Module function to create the configuration page.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87
6782
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
88 @param dlg reference to the configuration dialog
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
89 @return reference to the instantiated page (ConfigurationPageBase)
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
90 """
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
91 page = PipPage()
390a45748883 PipInterface: started to convert the pip interface from a menu based plug-in to a widget based interface to be placed in the right side tools bar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
92 return page

eric ide

mercurial