Sun, 24 Feb 2019 18:13:28 +0100
Pip: fixed an issue related to determining the pip config file path for a global environment.
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 | |
6645
ad476851d7e0
Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6619
diff
changeset
|
3 | # Copyright (c) 2015 - 2019 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 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Package implementing the pip GUI logic. |
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 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | from __future__ import unicode_literals |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | try: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | str = unicode # __IGNORE_EXCEPTION__ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | except NameError: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | pass |
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 | import os |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | import sys |
6792
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
18 | import json |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
20 | from PyQt5.QtCore import pyqtSlot, QObject, QProcess, QUrl, QCoreApplication |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
21 | from PyQt5.QtWidgets import QDialog |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
22 | from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, \ |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
23 | QNetworkReply |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
25 | from E5Gui import E5MessageBox |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | from E5Gui.E5Application import e5App |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
28 | from E5Network.E5NetworkProxyFactory import proxyAuthenticationRequired |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
29 | try: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
30 | from E5Network.E5SslErrorHandler import E5SslErrorHandler |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
31 | SSL_AVAILABLE = True |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
32 | except ImportError: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
33 | SSL_AVAILABLE = False |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
34 | |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | from .PipDialog import PipDialog |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | import Preferences |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | import Globals |
6744
f5249a9927c9
Added a specific icon for the PyPI related menu and config entry.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
39 | |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | class Pip(QObject): |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | Class implementing the pip GUI logic. |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | """ |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
45 | DefaultPyPiUrl = "https://pypi.org" |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
46 | DefaultIndexUrlXml = DefaultPyPiUrl + "/pypi" |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
47 | DefaultIndexUrlPip = DefaultPyPiUrl + "/simple" |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
48 | |
6785
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
49 | def __init__(self, parent=None): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | Constructor |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
53 | @param parent parent |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
54 | @type QObject |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | super(Pip, self).__init__(parent) |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
57 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
58 | # attributes for the network objects |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
59 | self.__networkManager = QNetworkAccessManager(self) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
60 | self.__networkManager.proxyAuthenticationRequired.connect( |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
61 | proxyAuthenticationRequired) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
62 | if SSL_AVAILABLE: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
63 | self.__sslErrorHandler = E5SslErrorHandler(self) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
64 | self.__networkManager.sslErrors.connect( |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
65 | self.__sslErrorHandler.sslErrorsReply) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
66 | self.__replies = [] |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | ########################################################################## |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | ## Methods below implement some utility functions |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | ########################################################################## |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
72 | def runProcess(self, args, interpreter): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | Public method to execute the current pip with the given arguments. |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | The selected pip executable is called with the given arguments and |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | waited for its end. |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
79 | @param args list of command line arguments |
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
80 | @type list of str |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
81 | @param interpreter path of the Python interpreter to be used |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
82 | @type str |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | @return tuple containing a flag indicating success and the output |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
84 | of the process |
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
85 | @rtype tuple of (bool, str) |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | ioEncoding = Preferences.getSystem("IOEncoding") |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | process = QProcess() |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
90 | process.start(interpreter, args) |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | procStarted = process.waitForStarted() |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | if procStarted: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | finished = process.waitForFinished(30000) |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | if finished: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | if process.exitCode() == 0: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | output = str(process.readAllStandardOutput(), ioEncoding, |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | 'replace') |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | return True, output |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | else: |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
100 | return (False, |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
101 | self.tr("python exited with an error ({0}).") |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
102 | .format(process.exitCode())) |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | else: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | process.terminate() |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | process.waitForFinished(2000) |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | process.kill() |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | process.waitForFinished(3000) |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
108 | return False, self.tr("python did not finish within" |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
109 | " 30 seconds.") |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
111 | return False, self.tr("python could not be started.") |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
113 | def getUserConfig(self): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | """ |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
115 | Public method to get the name of the user configuration file. |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
117 | @return path of the user configuration file |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
118 | @rtype str |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | # Unix: ~/.config/pip/pip.conf |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | # OS X: ~/Library/Application Support/pip/pip.conf |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | # Windows: %APPDATA%\pip\pip.ini |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | # Environment: $PIP_CONFIG_FILE |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | try: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | return os.environ["PIP_CONFIG_FILE"] |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | except KeyError: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | pass |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | if Globals.isWindowsPlatform(): |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | config = os.path.join(os.environ["APPDATA"], "pip", "pip.ini") |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | elif Globals.isMacPlatform(): |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | config = os.path.expanduser( |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | "~/Library/Application Support/pip/pip.conf") |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | else: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | config = os.path.expanduser("~/.config/pip/pip.conf") |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | return config |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
140 | def getVirtualenvConfig(self, venvName): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | """ |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
142 | Public method to get the name of the virtualenv configuration file. |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
144 | @param venvName name of the environment to get config file path for |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
145 | @type str |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
146 | @return path of the virtualenv configuration file |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
147 | @rtype str |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | # Unix, OS X: $VIRTUAL_ENV/pip.conf |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | # Windows: %VIRTUAL_ENV%\pip.ini |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | if Globals.isWindowsPlatform(): |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | pip = "pip.ini" |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | else: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | pip = "pip.conf" |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
156 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
157 | venvManager = e5App().getObject("VirtualEnvManager") |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
158 | if venvManager.isGlobalEnvironment(venvName): |
6819
6c49d4ed077d
Pip: fixed an issue related to determining the pip config file path for a global environment.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6798
diff
changeset
|
159 | venvDirectory = os.path.dirname(self.getUserConfig()) |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
160 | else: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
161 | venvDirectory = venvManager.getVirtualenvDirectory(venvName) |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
162 | |
6785
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
163 | if venvDirectory: |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
164 | config = os.path.join(venvDirectory, pip) |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
165 | else: |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
166 | config = "" |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
167 | |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
168 | return config |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
169 | |
6619
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
170 | def getProjectEnvironmentString(self): |
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
171 | """ |
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
172 | Public method to get the string for the project environment. |
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
173 | |
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
174 | @return string for the project environment |
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
175 | @rtype str |
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
176 | """ |
6785
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
177 | if e5App().getObject("Project").isOpen(): |
6619
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
178 | return self.tr("<project>") |
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
179 | else: |
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
180 | return "" |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
181 | |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
182 | def getVirtualenvInterpreter(self, venvName): |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
183 | """ |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
184 | Public method to get the interpreter for a virtual environment. |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
186 | @param venvName logical name for the virtual environment |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
187 | @type str |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
188 | @return interpreter path |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
189 | @rtype str |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
190 | """ |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
191 | if venvName == self.getProjectEnvironmentString(): |
6792
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
192 | venvName = \ |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
193 | e5App().getObject("Project").getDebugProperty("VIRTUALENV") |
6619
1d34365c082c
pip Interface: added an entry to select the virtual environment of the current project if it has one defined.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6394
diff
changeset
|
194 | if not venvName: |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
195 | # fall back to interpreter used to run eric6 |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
196 | return sys.executable |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
197 | |
6792
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
198 | interpreter = \ |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
199 | e5App().getObject("VirtualEnvManager").getVirtualenvInterpreter( |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
200 | venvName) |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
201 | if not interpreter: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
202 | E5MessageBox.critical( |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
203 | None, |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
204 | self.tr("Interpreter for Virtual Environment"), |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
205 | self.tr("""No interpreter configured for the selected""" |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
206 | """ virtual environment.""")) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
207 | |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
208 | return interpreter |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
209 | |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
210 | def getVirtualenvNames(self): |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
211 | """ |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
212 | Public method to get a sorted list of virtual environment names. |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
213 | |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
214 | @return sorted list of virtual environment names |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
215 | @rtype list of str |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
216 | """ |
6792
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
217 | return sorted( |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
218 | e5App().getObject("VirtualEnvManager").getVirtualenvNames()) |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | |
6795
6e2ed2aac325
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6793
diff
changeset
|
220 | def installPip(self, venvName, userSite=False): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | """ |
6795
6e2ed2aac325
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6793
diff
changeset
|
222 | Public method to install pip. |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | |
6795
6e2ed2aac325
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6793
diff
changeset
|
224 | @param venvName name of the environment to install pip into |
6e2ed2aac325
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6793
diff
changeset
|
225 | @type str |
6331
758b1cb7a2e6
pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6327
diff
changeset
|
226 | @param userSite flag indicating an install to the user install |
758b1cb7a2e6
pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6327
diff
changeset
|
227 | directory |
758b1cb7a2e6
pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6327
diff
changeset
|
228 | @type bool |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | """ |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
230 | interpreter = self.getVirtualenvInterpreter(venvName) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
231 | if not interpreter: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
232 | return |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
233 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
234 | dia = PipDialog(self.tr('Install PIP')) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
235 | if userSite: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
236 | commands = [(interpreter, ["-m", "ensurepip", "--user"])] |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
237 | else: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
238 | commands = [(interpreter, ["-m", "ensurepip"])] |
6785
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
239 | if Preferences.getPip("PipSearchIndex"): |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
240 | indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
241 | args = ["-m", "pip", "install", "--index-url", indexUrl, |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
242 | "--upgrade"] |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
243 | else: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
244 | args = ["-m", "pip", "install", "--upgrade"] |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
245 | if userSite: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
246 | args.append("--user") |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
247 | args.append("pip") |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
248 | commands.append((interpreter, args[:])) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
249 | |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
250 | res = dia.startProcesses(commands) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
251 | if res: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
252 | dia.exec_() |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | @pyqtSlot() |
6795
6e2ed2aac325
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6793
diff
changeset
|
255 | def repairPip(self, venvName): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | """ |
6795
6e2ed2aac325
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6793
diff
changeset
|
257 | Public method to repair the pip installation. |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | |
6795
6e2ed2aac325
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6793
diff
changeset
|
259 | @param venvName name of the environment to install pip into |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | @type str |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | """ |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
262 | interpreter = self.getVirtualenvInterpreter(venvName) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
263 | if not interpreter: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
264 | return |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
266 | # python -m pip install --ignore-installed pip |
6785
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
267 | if Preferences.getPip("PipSearchIndex"): |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
268 | indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
269 | args = ["-m", "pip", "install", "--index-url", indexUrl, |
6331
758b1cb7a2e6
pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6327
diff
changeset
|
270 | "--ignore-installed"] |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
271 | else: |
6331
758b1cb7a2e6
pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6327
diff
changeset
|
272 | args = ["-m", "pip", "install", "--ignore-installed"] |
758b1cb7a2e6
pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6327
diff
changeset
|
273 | args.append("pip") |
758b1cb7a2e6
pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6327
diff
changeset
|
274 | |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | dia = PipDialog(self.tr('Repair PIP')) |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
276 | res = dia.startProcess(interpreter, args) |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | if res: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | dia.exec_() |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | def __checkUpgradePyQt(self, packages): |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | Private method to check, if an upgrade of PyQt packages is attempted. |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | @param packages list of packages to upgrade |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | @type list of str |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | @return flag indicating to abort the upgrade attempt |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | @rtype bool |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | pyqtPackages = [p for p in packages |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
290 | if p.lower() in ["pyqt5", "pyqt5-sip", "pyqtwebengine", |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
291 | "qscintilla", "sip"]] |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | if bool(pyqtPackages): |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | abort = not E5MessageBox.yesNo( |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | None, |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | self.tr("Upgrade Packages"), |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | self.tr( |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
298 | """You are trying to upgrade PyQt packages. This might""" |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | """ not work for the current instance of Python ({0}).""" |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | """ Do you want to continue?""").format(sys.executable), |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | icon=E5MessageBox.Critical) |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | else: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | abort = False |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | return abort |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
307 | def upgradePackages(self, packages, venvName, userSite=False): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | Public method to upgrade the given list of packages. |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | |
6327
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
311 | @param packages list of packages to upgrade |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
312 | @type list of str |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
313 | @param venvName name of the virtual environment to be used |
6327
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
314 | @type str |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
315 | @param userSite flag indicating an install to the user install |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
316 | directory |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
317 | @type bool |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
318 | @return flag indicating a successful execution |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
319 | @rtype bool |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | if self.__checkUpgradePyQt(packages): |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | return False |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
324 | if not venvName: |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
325 | return False |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
326 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
327 | interpreter = self.getVirtualenvInterpreter(venvName) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
328 | if not interpreter: |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
329 | return False |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
330 | |
6785
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
331 | if Preferences.getPip("PipSearchIndex"): |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
332 | indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
333 | args = ["-m", "pip", "install", "--index-url", indexUrl, |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
334 | "--upgrade"] |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
335 | else: |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
336 | args = ["-m", "pip", "install", "--upgrade"] |
6327
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
337 | if userSite: |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
338 | args.append("--user") |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
339 | args += packages |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | dia = PipDialog(self.tr('Upgrade Packages')) |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
341 | res = dia.startProcess(interpreter, args) |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | if res: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | dia.exec_() |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | return res |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
346 | def installPackages(self, packages, venvName, userSite=False): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | Public method to install the given list of packages. |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | |
6327
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
350 | @param packages list of packages to install |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
351 | @type list of str |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
352 | @param venvName name of the virtual environment to be used |
6327
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
353 | @type str |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
354 | @param userSite flag indicating an install to the user install |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
355 | directory |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
356 | @type bool |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
357 | """ |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
358 | if venvName: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
359 | interpreter = self.getVirtualenvInterpreter(venvName) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
360 | if not interpreter: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
361 | return |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
362 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
363 | if Preferences.getPip("PipSearchIndex"): |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
364 | indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
365 | args = ["-m", "pip", "install", "--index-url", indexUrl] |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
366 | else: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
367 | args = ["-m", "pip", "install"] |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
368 | if userSite: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
369 | args.append("--user") |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
370 | args += packages |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
371 | dia = PipDialog(self.tr('Install Packages')) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
372 | res = dia.startProcess(interpreter, args) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
373 | if res: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
374 | dia.exec_() |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
375 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
376 | def installRequirements(self, venvName): |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
377 | """ |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
378 | Public method to install packages as given in a requirements file. |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
379 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
380 | @param venvName name of the virtual environment to be used |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
381 | @type str |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | """ |
6294
58f82c179d2b
pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6290
diff
changeset
|
383 | from .PipFileSelectionDialog import PipFileSelectionDialog |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
384 | dlg = PipFileSelectionDialog(self, "requirements") |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
385 | if dlg.exec_() == QDialog.Accepted: |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
386 | requirements, user = dlg.getData() |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | if requirements and os.path.exists(requirements): |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
388 | interpreter = self.getVirtualenvInterpreter(venvName) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
389 | if not interpreter: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
390 | return |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
391 | |
6785
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
392 | if Preferences.getPip("PipSearchIndex"): |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
393 | indexUrl = Preferences.getPip("PipSearchIndex") + \ |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
394 | "/simple" |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
395 | args = ["-m", "pip", "install", "--index-url", indexUrl] |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
396 | else: |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
397 | args = ["-m", "pip", "install"] |
6327
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
398 | if user: |
a1716d9210f4
pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6301
diff
changeset
|
399 | args.append("--user") |
6257
4523c5e6dd43
Added more code to properly override the PyPi index URL used by pip.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
400 | args += ["--requirement", requirements] |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
401 | dia = PipDialog(self.tr('Install Packages from Requirements')) |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
402 | res = dia.startProcess(interpreter, args) |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
403 | if res: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | dia.exec_() |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
405 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
406 | def uninstallPackages(self, packages, venvName): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
408 | Public method to uninstall the given list of packages. |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
410 | @param packages list of packages to uninstall |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
411 | @type list of str |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
412 | @param venvName name of the virtual environment to be used |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
413 | @type str |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
414 | @return flag indicating a successful execution |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
415 | @rtype bool |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
416 | """ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
417 | res = False |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
418 | if packages and venvName: |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
419 | from UI.DeleteFilesConfirmationDialog import \ |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | DeleteFilesConfirmationDialog |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
421 | dlg = DeleteFilesConfirmationDialog( |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | self.parent(), |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | self.tr("Uninstall Packages"), |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | self.tr( |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | "Do you really want to uninstall these packages?"), |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
426 | packages) |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | if dlg.exec_() == QDialog.Accepted: |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
428 | interpreter = self.getVirtualenvInterpreter(venvName) |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
429 | if not interpreter: |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
430 | return |
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
431 | args = ["-m", "pip", "uninstall", "--yes"] + packages |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | dia = PipDialog(self.tr('Uninstall Packages')) |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
433 | res = dia.startProcess(interpreter, args) |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | if res: |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | dia.exec_() |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | return res |
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
438 | def uninstallRequirements(self, venvName): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | """ |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
440 | Public method to uninstall packages as given in a requirements file. |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
441 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
442 | @param venvName name of the virtual environment to be used |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
443 | @type str |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | """ |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
445 | if venvName: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
446 | from .PipFileSelectionDialog import PipFileSelectionDialog |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
447 | dlg = PipFileSelectionDialog(self, "requirements", |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
448 | install=False) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
449 | if dlg.exec_() == QDialog.Accepted: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
450 | requirements, _user = dlg.getData() |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
451 | if requirements and os.path.exists(requirements): |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
452 | try: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
453 | f = open(requirements, "r") |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
454 | reqs = f.read().splitlines() |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
455 | f.close() |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
456 | except (OSError, IOError): |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
457 | return |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
458 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
459 | from UI.DeleteFilesConfirmationDialog import \ |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
460 | DeleteFilesConfirmationDialog |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
461 | dlg = DeleteFilesConfirmationDialog( |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
462 | self.parent(), |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
463 | self.tr("Uninstall Packages"), |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
464 | self.tr( |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
465 | "Do you really want to uninstall these packages?"), |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
466 | reqs) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
467 | if dlg.exec_() == QDialog.Accepted: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
468 | interpreter = self.getVirtualenvInterpreter(venvName) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
469 | if not interpreter: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
470 | return |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
471 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
472 | args = ["-m", "pip", "uninstall", "--requirement", |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
473 | requirements] |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
474 | dia = PipDialog( |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
475 | self.tr('Uninstall Packages from Requirements')) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
476 | res = dia.startProcess(interpreter, args) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
477 | if res: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
478 | dia.exec_() |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
479 | |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
480 | def getIndexUrl(self): |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | """ |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
482 | Public method to get the index URL for PyPI. |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
483 | |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
484 | @return index URL for PyPI |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
485 | @rtype str |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
486 | """ |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
487 | if Preferences.getPip("PipSearchIndex"): |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
488 | indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
489 | else: |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
490 | indexUrl = Pip.DefaultIndexUrlPip |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
491 | |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
492 | return indexUrl |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
493 | |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
494 | def getIndexUrlXml(self): |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
495 | """ |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
496 | Public method to get the index URL for XML RPC calls. |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
497 | |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
498 | @return index URL for XML RPC calls |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
499 | @rtype str |
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
500 | """ |
6785
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
501 | if Preferences.getPip("PipSearchIndex"): |
058d63c537a4
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6782
diff
changeset
|
502 | indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi" |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
503 | else: |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
504 | indexUrl = Pip.DefaultIndexUrlXml |
6342
c79ecba9cde7
pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6331
diff
changeset
|
505 | |
6793
cca6a35f3ad2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6792
diff
changeset
|
506 | return indexUrl |
6011
e6af0dcfbb35
Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | |
6792
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
508 | def getInstalledPackages(self, envName, localPackages=True, |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
509 | notRequired=False, usersite=False): |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
510 | """ |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
511 | Public method to get the list of installed packages. |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
512 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
513 | @param envName name of the environment to get the packages for |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
514 | @type str |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
515 | @param localPackages flag indicating to get local packages only |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
516 | @type bool |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
517 | @param notRequired flag indicating to list packages that are not |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
518 | dependencies of installed packages as well |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
519 | @type bool |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
520 | @param usersite flag indicating to only list packages installed |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
521 | in user-site |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
522 | @type bool |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
523 | @return list of tuples containing the package name and version |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
524 | @rtype list of tuple of (str, str) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
525 | """ |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
526 | packages = [] |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
527 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
528 | if envName: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
529 | interpreter = self.getVirtualenvInterpreter(envName) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
530 | if interpreter: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
531 | args = [ |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
532 | "-m", "pip", |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
533 | "list", |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
534 | "--format=json", |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
535 | ] |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
536 | if localPackages: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
537 | args.append("--local") |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
538 | if notRequired: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
539 | args.append("--not-required") |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
540 | if usersite: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
541 | args.append("--user") |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
542 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
543 | proc = QProcess() |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
544 | proc.start(interpreter, args) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
545 | if proc.waitForStarted(15000): |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
546 | if proc.waitForFinished(30000): |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
547 | output = str(proc.readAllStandardOutput(), |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
548 | Preferences.getSystem("IOEncoding"), |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
549 | 'replace').strip() |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
550 | try: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
551 | jsonList = json.loads(output) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
552 | except Exception: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
553 | jsonList = [] |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
554 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
555 | for package in jsonList: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
556 | if isinstance(package, dict): |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
557 | packages.append(( |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
558 | package["name"], |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
559 | package["version"], |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
560 | )) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
561 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
562 | return packages |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
563 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
564 | def getOutdatedPackages(self, envName, localPackages=True, |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
565 | notRequired=False, usersite=False): |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
566 | """ |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
567 | Public method to get the list of outdated packages. |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
568 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
569 | @param envName name of the environment to get the packages for |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
570 | @type str |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
571 | @param localPackages flag indicating to get local packages only |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
572 | @type bool |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
573 | @param notRequired flag indicating to list packages that are not |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
574 | dependencies of installed packages as well |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
575 | @type bool |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
576 | @param usersite flag indicating to only list packages installed |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
577 | in user-site |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
578 | @type bool |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
579 | @return list of tuples containing the package name, installed version |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
580 | and available version |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
581 | @rtype list of tuple of (str, str, str) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
582 | """ |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
583 | packages = [] |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
584 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
585 | if envName: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
586 | interpreter = self.getVirtualenvInterpreter(envName) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
587 | if interpreter: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
588 | args = [ |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
589 | "-m", "pip", |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
590 | "list", |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
591 | "--outdated", |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
592 | "--format=json", |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
593 | ] |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
594 | if localPackages: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
595 | args.append("--local") |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
596 | if notRequired: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
597 | args.append("--not-required") |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
598 | if usersite: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
599 | args.append("--user") |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
600 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
601 | proc = QProcess() |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
602 | proc.start(interpreter, args) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
603 | if proc.waitForStarted(15000): |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
604 | if proc.waitForFinished(30000): |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
605 | output = str(proc.readAllStandardOutput(), |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
606 | Preferences.getSystem("IOEncoding"), |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
607 | 'replace').strip() |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
608 | try: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
609 | jsonList = json.loads(output) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
610 | except Exception: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
611 | jsonList = [] |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
612 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
613 | for package in jsonList: |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
614 | if isinstance(package, dict): |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
615 | packages.append(( |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
616 | package["name"], |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
617 | package["version"], |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
618 | package["latest_version"], |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
619 | )) |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
620 | |
9dd854f05c83
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6785
diff
changeset
|
621 | return packages |
6798
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
622 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
623 | def getPackageDetails(self, name, version): |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
624 | """ |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
625 | Public method to get package details using the PyPI JSON interface. |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
626 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
627 | @param name package name |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
628 | @type str |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
629 | @param version package version |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
630 | @type str |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
631 | @return dictionary containing PyPI package data |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
632 | @rtype dict |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
633 | """ |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
634 | result = {} |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
635 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
636 | if name and version: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
637 | url = "https://pypi.org/pypi/{0}/{1}/json".format(name, version) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
638 | request = QNetworkRequest(QUrl(url)) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
639 | reply = self.__networkManager.get(request) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
640 | while not reply.isFinished(): |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
641 | QCoreApplication.processEvents() |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
642 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
643 | reply.deleteLater() |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
644 | if reply.error() == QNetworkReply.NoError: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
645 | data = str(reply.readAll(), |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
646 | Preferences.getSystem("IOEncoding"), |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
647 | 'replace') |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
648 | try: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
649 | result = json.loads(data) |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
650 | except Exception: |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
651 | # ignore JSON exceptions |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
652 | pass |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
653 | |
3985c1a67fa2
PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6795
diff
changeset
|
654 | return result |