29 import Preferences |
29 import Preferences |
30 import Globals |
30 import Globals |
31 |
31 |
32 |
32 |
33 # TODO: 1) change all uses of pip to python3 -m pip |
33 # TODO: 1) change all uses of pip to python3 -m pip |
34 # TODO: 2) support --user for install, install --upgrade and list |
|
35 class Pip(QObject): |
34 class Pip(QObject): |
36 """ |
35 """ |
37 Class implementing the pip GUI logic. |
36 Class implementing the pip GUI logic. |
38 """ |
37 """ |
39 def __init__(self, plugin, parent=None): |
38 def __init__(self, plugin, parent=None): |
181 self, 'pip_install_pip') |
180 self, 'pip_install_pip') |
182 self.installPipAct.setStatusTip(self.tr( |
181 self.installPipAct.setStatusTip(self.tr( |
183 'Install the pip package itself')) |
182 'Install the pip package itself')) |
184 self.installPipAct.setWhatsThis(self.tr( |
183 self.installPipAct.setWhatsThis(self.tr( |
185 """<b>Install Pip</b>""" |
184 """<b>Install Pip</b>""" |
186 """<p>This install the pip package itself.</p>""" |
185 """<p>This installs the pip package itself.</p>""" |
187 )) |
186 )) |
188 self.installPipAct.triggered.connect(self.__installPip) |
187 self.installPipAct.triggered.connect( |
|
188 lambda: self.__installPip(userSite=False)) |
189 self.actions.append(self.installPipAct) |
189 self.actions.append(self.installPipAct) |
|
190 |
|
191 self.installPipUserAct = E5Action( |
|
192 self.tr('Install Pip to User-Site'), |
|
193 self.tr('Install Pip to User-Site'), |
|
194 0, 0, |
|
195 self, 'pip_install_pip_user') |
|
196 self.installPipUserAct.setStatusTip(self.tr( |
|
197 'Install the pip package itself to the user directory')) |
|
198 self.installPipUserAct.setWhatsThis(self.tr( |
|
199 """<b>Install Pip to User-Site</b>""" |
|
200 """<p>This installs the pip package itself to the user""" |
|
201 """ directory.</p>""" |
|
202 )) |
|
203 self.installPipUserAct.triggered.connect( |
|
204 lambda: self.__installPip(userSite=True)) |
|
205 self.actions.append(self.installPipUserAct) |
190 |
206 |
191 self.repairPipAct = E5Action( |
207 self.repairPipAct = E5Action( |
192 self.tr('Repair Pip'), |
208 self.tr('Repair Pip'), |
193 self.tr('Repair Pip'), |
209 self.tr('Repair Pip'), |
194 0, 0, |
210 0, 0, |
369 menu.addAction(self.listPackagesAct) |
385 menu.addAction(self.listPackagesAct) |
370 menu.addAction(self.listUptodatePackagesAct) |
386 menu.addAction(self.listUptodatePackagesAct) |
371 menu.addAction(self.listOutdatedPackagesAct) |
387 menu.addAction(self.listOutdatedPackagesAct) |
372 menu.addSeparator() |
388 menu.addSeparator() |
373 menu.addAction(self.installPipAct) |
389 menu.addAction(self.installPipAct) |
|
390 menu.addAction(self.installPipUserAct) |
|
391 menu.addSeparator() |
374 menu.addAction(self.installPackagesAct) |
392 menu.addAction(self.installPackagesAct) |
375 menu.addAction(self.installLocalPackageAct) |
393 menu.addAction(self.installLocalPackageAct) |
376 menu.addAction(self.installRequirementsAct) |
394 menu.addAction(self.installRequirementsAct) |
377 menu.addSeparator() |
395 menu.addSeparator() |
378 menu.addAction(self.upgradePipAct) |
396 menu.addAction(self.upgradePipAct) |
404 """ |
422 """ |
405 enable = bool(self.__plugin.getPreferences("CurrentPipExecutable")) |
423 enable = bool(self.__plugin.getPreferences("CurrentPipExecutable")) |
406 for act in self.actions: |
424 for act in self.actions: |
407 if act not in [self.selectExecutableAct, |
425 if act not in [self.selectExecutableAct, |
408 self.installPipAct, |
426 self.installPipAct, |
|
427 self.installPipUserAct, |
409 self.editUserConfigAct, |
428 self.editUserConfigAct, |
410 self.editVirtualenvConfigAct, |
429 self.editVirtualenvConfigAct, |
411 self.pipConfigAct]: |
430 self.pipConfigAct]: |
412 act.setEnabled(enable) |
431 act.setEnabled(enable) |
413 |
432 |
667 return |
686 return |
668 |
687 |
669 self.__editor = MiniEditor(cfgFile, "Properties") |
688 self.__editor = MiniEditor(cfgFile, "Properties") |
670 self.__editor.show() |
689 self.__editor.show() |
671 |
690 |
672 # TODO: add support for --user |
691 def __installPip(self, userSite=False): |
673 def __installPip(self): |
|
674 """ |
692 """ |
675 Private slot to install pip. |
693 Private slot to install pip. |
|
694 |
|
695 @param userSite flag indicating an install to the user install |
|
696 directory |
|
697 @type bool |
676 """ |
698 """ |
677 python = E5FileDialog.getOpenFileName( |
699 python = E5FileDialog.getOpenFileName( |
678 None, |
700 None, |
679 self.tr("Select Python Executable")) |
701 self.tr("Select Python Executable")) |
680 if python: |
702 if python: |
681 python = QDir.toNativeSeparators(python) |
703 python = QDir.toNativeSeparators(python) |
682 dia = PipDialog(self.tr('Install PIP')) |
704 dia = PipDialog(self.tr('Install PIP')) |
683 commands = [(python, ["-m", "ensurepip"])] |
705 if userSite: |
|
706 commands = [(python, ["-m", "ensurepip", "--user"])] |
|
707 else: |
|
708 commands = [(python, ["-m", "ensurepip"])] |
684 if self.__plugin.getPreferences("PipSearchIndex"): |
709 if self.__plugin.getPreferences("PipSearchIndex"): |
685 indexUrl = \ |
710 indexUrl = \ |
686 self.__plugin.getPreferences("PipSearchIndex") + "/simple" |
711 self.__plugin.getPreferences("PipSearchIndex") + "/simple" |
687 commands.append( |
712 args = ["-m", "pip", "install", "--index-url", indexUrl, |
688 (python, |
713 "--upgrade"] |
689 ["-m", "pip", "install", "--index-url", indexUrl, |
|
690 "--upgrade", "pip"])) |
|
691 else: |
714 else: |
692 commands.append( |
715 args = ["-m", "pip", "install", "--upgrade"] |
693 (python, ["-m", "pip", "install", "--upgrade", "pip"])) |
716 if userSite: |
|
717 args.append("--user") |
|
718 args.append("pip") |
|
719 commands.append((python, args[:])) |
694 |
720 |
695 res = dia.startProcesses(commands) |
721 res = dia.startProcesses(commands) |
696 if res: |
722 if res: |
697 dia.exec_() |
723 dia.exec_() |
698 pip = E5FileDialog.getOpenFileName( |
724 pip = E5FileDialog.getOpenFileName( |
761 res = dia.startProcess(python, args) |
787 res = dia.startProcess(python, args) |
762 if res: |
788 if res: |
763 dia.exec_() |
789 dia.exec_() |
764 return res |
790 return res |
765 |
791 |
766 # TODO: add support for --user |
|
767 @pyqtSlot() |
792 @pyqtSlot() |
768 def __repairPip(self): |
793 def __repairPip(self): |
769 """ |
794 """ |
770 Private method to repair the pip installation. |
795 Private method to repair the pip installation. |
771 |
796 |
772 @return flag indicating a successful execution |
797 @return flag indicating a successful execution |
773 @rtype bool |
798 @rtype bool |
774 """ |
799 """ |
775 default = self.tr("<Default>") |
800 from .PipSelectionDialog import PipSelectionDialog |
776 pipExecutables = sorted( |
801 dlg = PipSelectionDialog(self.__plugin) |
777 self.__plugin.getPreferences("PipExecutables")) |
802 if dlg.exec_() != QDialog.Accepted: |
778 pip, ok = QInputDialog.getItem( |
|
779 None, |
|
780 self.tr("Upgrade pip"), |
|
781 self.tr("Select pip Executable:"), |
|
782 [default] + pipExecutables, |
|
783 0, False) |
|
784 if not ok or not pip: |
|
785 return False |
803 return False |
786 |
804 |
787 if pip == default: |
805 pip, userSite = dlg.getData() |
|
806 |
|
807 if not pip: |
788 pip = self.__plugin.getPreferences("CurrentPipExecutable") |
808 pip = self.__plugin.getPreferences("CurrentPipExecutable") |
789 |
809 |
790 python = self.__getPython(pip) |
810 python = self.__getPython(pip) |
791 if not python: |
811 if not python: |
792 python = E5FileDialog.getOpenFileName( |
812 python = E5FileDialog.getOpenFileName( |
801 # pip install --ignore-installed pip |
821 # pip install --ignore-installed pip |
802 if self.__plugin.getPreferences("PipSearchIndex"): |
822 if self.__plugin.getPreferences("PipSearchIndex"): |
803 indexUrl = \ |
823 indexUrl = \ |
804 self.__plugin.getPreferences("PipSearchIndex") + "/simple" |
824 self.__plugin.getPreferences("PipSearchIndex") + "/simple" |
805 args = ["-m", "pip", "install", "--index-url", indexUrl, |
825 args = ["-m", "pip", "install", "--index-url", indexUrl, |
806 "--ignore-installed", "pip"] |
826 "--ignore-installed"] |
807 else: |
827 else: |
808 args = ["-m", "pip", "install", "--ignore-installed", "pip"] |
828 args = ["-m", "pip", "install", "--ignore-installed"] |
|
829 if userSite: |
|
830 args.append("--user") |
|
831 args.append("pip") |
|
832 |
809 dia = PipDialog(self.tr('Repair PIP')) |
833 dia = PipDialog(self.tr('Repair PIP')) |
810 res = dia.startProcess(python, args) |
834 res = dia.startProcess(python, args) |
811 if res: |
835 if res: |
812 dia.exec_() |
836 dia.exec_() |
813 |
837 |