eric6/PipInterface/Pip.py

Sat, 27 Apr 2019 19:27:50 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Apr 2019 19:27:50 +0200
changeset 6975
3325bf3e7b2c
parent 6942
2602857055c5
child 7192
a22eee00b052
permissions
-rw-r--r--

Pip, PipPackagesWidget, VirtualenvManager: fixed an issue causing environments for remote debugging being shown in the selection list.

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
6975
3325bf3e7b2c Pip, PipPackagesWidget, VirtualenvManager: fixed an issue causing environments for remote debugging being shown in the selection list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
210 def getVirtualenvNames(self, noRemote=False):
6342
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
6975
3325bf3e7b2c Pip, PipPackagesWidget, VirtualenvManager: fixed an issue causing environments for remote debugging being shown in the selection list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
214 @param noRemote flag indicating to exclude environments for remote
3325bf3e7b2c Pip, PipPackagesWidget, VirtualenvManager: fixed an issue causing environments for remote debugging being shown in the selection list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
215 debugging
3325bf3e7b2c Pip, PipPackagesWidget, VirtualenvManager: fixed an issue causing environments for remote debugging being shown in the selection list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
216 @type bool
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
217 @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
218 @rtype list of str
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
219 """
6792
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
220 return sorted(
6975
3325bf3e7b2c Pip, PipPackagesWidget, VirtualenvManager: fixed an issue causing environments for remote debugging being shown in the selection list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
221 e5App().getObject("VirtualEnvManager").getVirtualenvNames(
3325bf3e7b2c Pip, PipPackagesWidget, VirtualenvManager: fixed an issue causing environments for remote debugging being shown in the selection list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
222 noRemote=noRemote))
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 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
225 """
6795
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6793
diff changeset
226 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
227
6795
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6793
diff changeset
228 @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
229 @type str
6331
758b1cb7a2e6 pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
230 @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
231 directory
758b1cb7a2e6 pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
232 @type bool
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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 interpreter = self.getVirtualenvInterpreter(venvName)
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
235 if not interpreter:
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
236 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
237
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
238 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
239 if userSite:
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
240 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
241 else:
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
242 commands = [(interpreter, ["-m", "ensurepip"])]
6785
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
243 if Preferences.getPip("PipSearchIndex"):
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
244 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
245 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
246 "--upgrade"]
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
247 else:
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
248 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
249 if userSite:
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
250 args.append("--user")
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
251 args.append("pip")
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
252 commands.append((interpreter, args[:]))
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
253
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
254 res = dia.startProcesses(commands)
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
255 if res:
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
256 dia.exec_()
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 @pyqtSlot()
6795
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6793
diff changeset
259 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
260 """
6795
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6793
diff changeset
261 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
262
6795
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6793
diff changeset
263 @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
264 @type str
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 interpreter = self.getVirtualenvInterpreter(venvName)
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
267 if not interpreter:
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
268 return
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
270 # 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
271 if Preferences.getPip("PipSearchIndex"):
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
272 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
273 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
274 "--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
275 else:
6331
758b1cb7a2e6 pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
276 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
277 args.append("pip")
758b1cb7a2e6 pip Interface: continued adding support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
278
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 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
280 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
281 if res:
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 dia.exec_()
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 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
285 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 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
287
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 @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
289 @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
290 @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
291 @rtype bool
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 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
294 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
295 "qscintilla", "sip"]]
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 if bool(pyqtPackages):
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 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
299 None,
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 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
301 self.tr(
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
302 """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
303 """ 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
304 """ 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
305 icon=E5MessageBox.Critical)
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 else:
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 abort = False
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 return abort
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
311 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
312 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 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
314
6327
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
315 @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
316 @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
317 @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
318 @type str
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
319 @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
320 directory
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
321 @type bool
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
322 @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
323 @rtype bool
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 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
326 return False
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
328 if not venvName:
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
329 return False
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
330
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
331 interpreter = self.getVirtualenvInterpreter(venvName)
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
332 if not interpreter:
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
333 return False
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
334
6785
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
335 if Preferences.getPip("PipSearchIndex"):
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
336 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
337 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
338 "--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
339 else:
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
340 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
341 if userSite:
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
342 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
343 args += packages
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 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
345 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
346 if res:
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 dia.exec_()
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 return res
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6819
diff changeset
350 def installPackages(self, packages, venvName="", userSite=False,
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6819
diff changeset
351 interpreter=""):
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 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
354
6327
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
355 @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
356 @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
357 @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
358 @type str
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
359 @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
360 directory
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
361 @type bool
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6819
diff changeset
362 @param interpreter interpreter to be used for execution
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6819
diff changeset
363 @type str
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 """
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
365 if venvName:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
366 interpreter = self.getVirtualenvInterpreter(venvName)
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
367 if not interpreter:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
368 return
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6819
diff changeset
369
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6819
diff changeset
370 if interpreter:
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
371 if Preferences.getPip("PipSearchIndex"):
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
372 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
373 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
374 else:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
375 args = ["-m", "pip", "install"]
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
376 if userSite:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
377 args.append("--user")
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
378 args += packages
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
379 dia = PipDialog(self.tr('Install Packages'))
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
380 res = dia.startProcess(interpreter, args)
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
381 if res:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
382 dia.exec_()
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
383
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
384 def installRequirements(self, venvName):
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
385 """
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
386 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
387
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
388 @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
389 @type str
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 """
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6290
diff changeset
391 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
392 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
393 if dlg.exec_() == QDialog.Accepted:
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
394 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
395 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
396 interpreter = self.getVirtualenvInterpreter(venvName)
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
397 if not interpreter:
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
398 return
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
399
6785
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
400 if Preferences.getPip("PipSearchIndex"):
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
401 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
402 "/simple"
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
403 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
404 else:
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
405 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
406 if user:
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
407 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
408 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
409 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
410 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
411 if res:
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 dia.exec_()
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
414 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
415 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 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
417
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
418 @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
419 @type list of str
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
420 @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
421 @type str
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
422 @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
423 @rtype bool
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 """
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 res = False
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
426 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
427 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
428 DeleteFilesConfirmationDialog
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 dlg = DeleteFilesConfirmationDialog(
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 self.parent(),
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 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
432 self.tr(
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 "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
434 packages)
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 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
436 interpreter = self.getVirtualenvInterpreter(venvName)
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
437 if not interpreter:
6891
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6828
diff changeset
438 return False
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
439 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
440 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
441 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
442 if res:
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 dia.exec_()
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 return res
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
446 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
447 """
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
448 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
449
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
450 @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
451 @type str
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 """
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
453 if venvName:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
454 from .PipFileSelectionDialog import PipFileSelectionDialog
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
455 dlg = PipFileSelectionDialog(self, "requirements",
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
456 install=False)
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
457 if dlg.exec_() == QDialog.Accepted:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
458 requirements, _user = dlg.getData()
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
459 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
460 try:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
461 f = open(requirements, "r")
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
462 reqs = f.read().splitlines()
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
463 f.close()
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
464 except (OSError, IOError):
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
465 return
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
466
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
467 from UI.DeleteFilesConfirmationDialog import \
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
468 DeleteFilesConfirmationDialog
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
469 dlg = DeleteFilesConfirmationDialog(
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
470 self.parent(),
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
471 self.tr("Uninstall Packages"),
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
472 self.tr(
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
473 "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
474 reqs)
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
475 if dlg.exec_() == QDialog.Accepted:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
476 interpreter = self.getVirtualenvInterpreter(venvName)
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
477 if not interpreter:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
478 return
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
479
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
480 args = ["-m", "pip", "uninstall", "--requirement",
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
481 requirements]
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
482 dia = PipDialog(
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
483 self.tr('Uninstall Packages from Requirements'))
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
484 res = dia.startProcess(interpreter, args)
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
485 if res:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
486 dia.exec_()
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487
6793
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
488 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
489 """
6793
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
490 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
491
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
492 @return index URL for PyPI
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
493 @rtype str
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 """
6793
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
495 if Preferences.getPip("PipSearchIndex"):
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
496 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
497 else:
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
498 indexUrl = Pip.DefaultIndexUrlPip
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
499
6793
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
500 return indexUrl
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
501
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
502 def getIndexUrlXml(self):
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
503 """
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
504 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
505
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
506 @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
507 @rtype str
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
508 """
6785
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
509 if Preferences.getPip("PipSearchIndex"):
058d63c537a4 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
510 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
511 else:
6793
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
512 indexUrl = Pip.DefaultIndexUrlXml
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6331
diff changeset
513
6793
cca6a35f3ad2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6792
diff changeset
514 return indexUrl
6011
e6af0dcfbb35 Added the pip interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515
6792
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
516 def getInstalledPackages(self, envName, localPackages=True,
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
517 notRequired=False, usersite=False):
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
518 """
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
519 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
520
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
521 @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
522 @type str
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
523 @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
524 @type bool
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
525 @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
526 dependencies of installed packages as well
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
527 @type bool
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
528 @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
529 in user-site
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
530 @type bool
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
531 @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
532 @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
533 """
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
534 packages = []
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 envName:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
537 interpreter = self.getVirtualenvInterpreter(envName)
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
538 if interpreter:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
539 args = [
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
540 "-m", "pip",
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
541 "list",
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
542 "--format=json",
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
543 ]
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
544 if localPackages:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
545 args.append("--local")
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
546 if notRequired:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
547 args.append("--not-required")
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
548 if usersite:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
549 args.append("--user")
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
550
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
551 proc = QProcess()
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
552 proc.start(interpreter, args)
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
553 if proc.waitForStarted(15000):
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
554 if proc.waitForFinished(30000):
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
555 output = str(proc.readAllStandardOutput(),
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
556 Preferences.getSystem("IOEncoding"),
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
557 'replace').strip()
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
558 try:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
559 jsonList = json.loads(output)
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
560 except Exception:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
561 jsonList = []
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
562
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
563 for package in jsonList:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
564 if isinstance(package, dict):
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
565 packages.append((
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
566 package["name"],
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
567 package["version"],
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
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
570 return packages
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
571
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
572 def getOutdatedPackages(self, envName, localPackages=True,
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
573 notRequired=False, usersite=False):
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
574 """
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
575 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
576
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
577 @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
578 @type str
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
579 @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
580 @type bool
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
581 @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
582 dependencies of installed packages as well
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
583 @type bool
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
584 @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
585 in user-site
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
586 @type bool
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
587 @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
588 and available version
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
589 @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
590 """
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
591 packages = []
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
592
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
593 if envName:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
594 interpreter = self.getVirtualenvInterpreter(envName)
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
595 if interpreter:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
596 args = [
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
597 "-m", "pip",
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
598 "list",
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
599 "--outdated",
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
600 "--format=json",
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
601 ]
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
602 if localPackages:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
603 args.append("--local")
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
604 if notRequired:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
605 args.append("--not-required")
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
606 if usersite:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
607 args.append("--user")
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
608
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
609 proc = QProcess()
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
610 proc.start(interpreter, args)
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
611 if proc.waitForStarted(15000):
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
612 if proc.waitForFinished(30000):
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
613 output = str(proc.readAllStandardOutput(),
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
614 Preferences.getSystem("IOEncoding"),
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
615 'replace').strip()
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
616 try:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
617 jsonList = json.loads(output)
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
618 except Exception:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
619 jsonList = []
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 for package in jsonList:
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
622 if isinstance(package, dict):
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
623 packages.append((
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
624 package["name"],
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
625 package["version"],
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
626 package["latest_version"],
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
627 ))
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
628
9dd854f05c83 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6785
diff changeset
629 return packages
6798
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
630
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
631 def getPackageDetails(self, name, version):
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
632 """
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
633 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
634
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
635 @param name package name
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
636 @type str
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
637 @param version package version
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
638 @type str
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
639 @return dictionary containing PyPI package data
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
640 @rtype dict
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
641 """
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
642 result = {}
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
643
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
644 if name and version:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
645 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
646 request = QNetworkRequest(QUrl(url))
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
647 reply = self.__networkManager.get(request)
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
648 while not reply.isFinished():
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
649 QCoreApplication.processEvents()
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
650
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
651 reply.deleteLater()
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
652 if reply.error() == QNetworkReply.NoError:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
653 data = str(reply.readAll(),
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
654 Preferences.getSystem("IOEncoding"),
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
655 'replace')
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
656 try:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
657 result = json.loads(data)
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
658 except Exception:
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
659 # ignore JSON exceptions
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
660 pass
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
661
3985c1a67fa2 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6795
diff changeset
662 return result

eric ide

mercurial