Thu, 19 Apr 2018 19:13:37 +0200
Added more code to properly override the PyPi index URL used by pip.
--- a/Plugins/UiExtensionPlugins/PipInterface/Pip.py Tue Apr 17 19:11:51 2018 +0200 +++ b/Plugins/UiExtensionPlugins/PipInterface/Pip.py Thu Apr 19 19:13:37 2018 +0200 @@ -439,10 +439,13 @@ The selected pip executable is called with the given arguments and waited for its end. - @param args list of command line arguments (list of string) - @param cmd pip command to be used (string) + @param args list of command line arguments + @type list of str + @param cmd pip executable to be used + @type str @return tuple containing a flag indicating success and the output - of the process (string) + of the process + @rtype tuple of (bool, str) """ if not cmd: cmd = self.__plugin.getPreferences("CurrentPipExecutable") @@ -658,10 +661,19 @@ if python: python = QDir.toNativeSeparators(python) dia = PipDialog(self.tr('Install PIP')) - res = dia.startProcesses([ - (python, ["-m", "ensurepip"]), - (python, ["-m", "pip", "install", "--upgrade", "pip"]), - ]) + commands = [(python, ["-m", "ensurepip"])] + if self.__plugin.getPreferences("PipSearchIndex"): + indexUrl = \ + self.__plugin.getPreferences("PipSearchIndex") + "/simple" + commands.append( + (python, + ["-m", "pip", "install", "--index-url", indexUrl, + "--upgrade", "pip"])) + else: + commands.append( + (python, ["-m", "pip", "install", "--upgrade", "pip"])) + + res = dia.startProcesses(commands) if res: dia.exec_() pip = E5FileDialog.getOpenFileName( @@ -717,7 +729,13 @@ else: return False - args = ["-m", "pip", "install", "--upgrade", "pip"] + if self.__plugin.getPreferences("PipSearchIndex"): + indexUrl = \ + self.__plugin.getPreferences("PipSearchIndex") + "/simple" + args = ["-m", "pip", "install", "--index-url", indexUrl, + "--upgrade", "pip"] + else: + args = ["-m", "pip", "install", "--upgrade", "pip"] dia = PipDialog(self.tr('Upgrade PIP')) res = dia.startProcess(python, args) if res: @@ -759,7 +777,13 @@ return False # pip install --ignore-installed pip - args = ["-m", "pip", "install", "--ignore-installed", "pip"] + if self.__plugin.getPreferences("PipSearchIndex"): + indexUrl = \ + self.__plugin.getPreferences("PipSearchIndex") + "/simple" + args = ["-m", "pip", "install", "--index-url", indexUrl, + "--ignore-installed", "pip"] + else: + args = ["-m", "pip", "install", "--ignore-installed", "pip"] dia = PipDialog(self.tr('Repair PIP')) res = dia.startProcess(python, args) if res: @@ -849,7 +873,13 @@ if not cmd: cmd = self.__plugin.getPreferences("CurrentPipExecutable") - args = ["install", "--upgrade"] + packages + if self.__plugin.getPreferences("PipSearchIndex"): + indexUrl = \ + self.__plugin.getPreferences("PipSearchIndex") + "/simple" + args = ["install", "--index-url", indexUrl, "--upgrade"] + else: + args = ["install", "--upgrade"] + args += packages dia = PipDialog(self.tr('Upgrade Packages')) res = dia.startProcess(cmd, args) if res: @@ -877,7 +907,13 @@ """ if not cmd: cmd = self.__plugin.getPreferences("CurrentPipExecutable") - args = ["install"] + packages + if self.__plugin.getPreferences("PipSearchIndex"): + indexUrl = \ + self.__plugin.getPreferences("PipSearchIndex") + "/simple" + args = ["install", "--index-url", indexUrl] + else: + args = ["install"] + args += packages dia = PipDialog(self.tr('Install Packages')) res = dia.startProcess(cmd, args) if res: @@ -908,7 +944,14 @@ if not command: command = self.__plugin.getPreferences( "CurrentPipExecutable") - args = ["install", "--requirement", requirements] + if self.__plugin.getPreferences("PipSearchIndex"): + indexUrl = \ + self.__plugin.getPreferences("PipSearchIndex") + \ + "/simple" + args = ["install", "--index-url", indexUrl] + else: + args = ["install"] + args += ["--requirement", requirements] dia = PipDialog(self.tr('Install Packages from Requirements')) res = dia.startProcess(command, args) if res:
--- a/Plugins/UiExtensionPlugins/PipInterface/PipListDialog.py Tue Apr 17 19:11:51 2018 +0200 +++ b/Plugins/UiExtensionPlugins/PipInterface/PipListDialog.py Thu Apr 19 19:13:37 2018 +0200 @@ -81,6 +81,7 @@ self.__mode = mode self.__defaultCommand = plugin.getPreferences("CurrentPipExecutable") self.__ioEncoding = Preferences.getSystem("IOEncoding") + self.__indexUrl = plugin.getPreferences("PipSearchIndex") self.__errors = "" self.__output = [] @@ -270,6 +271,10 @@ if self.notRequiredCheckBox.isChecked(): args.append("--not-required") + if self.__indexUrl: + args.append("--index-url") + args.append(self.__indexUrl + "/simple") + self.process.start(command, args) procStarted = self.process.waitForStarted(5000) if not procStarted: @@ -288,18 +293,23 @@ Private method to process the captured output. """ if self.__output: - packageData = json.loads("\n".join(self.__output)) - for package in packageData: - data = [ - package["name"], - package["version"], - ] - if self.__mode == "outdated": - data.extend([ - package["latest_version"], - package["latest_filetype"], - ]) - QTreeWidgetItem(self.packageList, data) + try: + packageData = json.loads("\n".join(self.__output)) + for package in packageData: + data = [ + package["name"], + package["version"], + ] + if self.__mode == "outdated": + data.extend([ + package["latest_version"], + package["latest_filetype"], + ]) + QTreeWidgetItem(self.packageList, data) + except ValueError as err: + self.__errors += str(err) + "\n" + self.__errors += "received output:\n" + self.__errors += "\n".join(self.__output) def __readStdout(self): """
--- a/Plugins/UiExtensionPlugins/PipInterface/PipSearchDialog.py Tue Apr 17 19:11:51 2018 +0200 +++ b/Plugins/UiExtensionPlugins/PipInterface/PipSearchDialog.py Thu Apr 19 19:13:37 2018 +0200 @@ -23,7 +23,7 @@ from .Ui_PipSearchDialog import Ui_PipSearchDialog -from . import DefaultIndexUrl +from . import DefaultIndexUrlXml class PipSearchDialog(QDialog, Ui_PipSearchDialog): @@ -63,9 +63,11 @@ self.__showDetailsButton.setEnabled(False) self.__pip = pip - self.__client = E5XmlRpcClient( - plugin.getPreferences("PipSearchIndex") or DefaultIndexUrl, - self) + if plugin.getPreferences("PipSearchIndex"): + indexUrl = plugin.getPreferences("PipSearchIndex") + "/pypi" + else: + indexUrl = DefaultIndexUrlXml + self.__client = E5XmlRpcClient(indexUrl, self) self.__default = self.tr("<Default>") pipExecutables = sorted(plugin.getPreferences("PipExecutables"))
--- a/Plugins/UiExtensionPlugins/PipInterface/__init__.py Tue Apr 17 19:11:51 2018 +0200 +++ b/Plugins/UiExtensionPlugins/PipInterface/__init__.py Thu Apr 19 19:13:37 2018 +0200 @@ -10,4 +10,5 @@ from __future__ import unicode_literals DefaultPyPiUrl = "https://pypi.org" -DefaultIndexUrl = DefaultPyPiUrl + "/pypi" +DefaultIndexUrlXml = DefaultPyPiUrl + "/pypi" +DefaultIndexUrlPip = DefaultPyPiUrl + "/simple"