Plugins/UiExtensionPlugins/PipInterface/Pip.py

changeset 6327
a1716d9210f4
parent 6301
f488d2cc5841
child 6331
758b1cb7a2e6
equal deleted inserted replaced
6326:5ef9456a0cbe 6327:a1716d9210f4
667 return 667 return
668 668
669 self.__editor = MiniEditor(cfgFile, "Properties") 669 self.__editor = MiniEditor(cfgFile, "Properties")
670 self.__editor.show() 670 self.__editor.show()
671 671
672 # TODO: add support for --user
672 def __installPip(self): 673 def __installPip(self):
673 """ 674 """
674 Private slot to install pip. 675 Private slot to install pip.
675 """ 676 """
676 python = E5FileDialog.getOpenFileName( 677 python = E5FileDialog.getOpenFileName(
706 pipExecutables.append(pip) 707 pipExecutables.append(pip)
707 self.__plugin.setPreferences( 708 self.__plugin.setPreferences(
708 "PipExecutables", pipExecutables) 709 "PipExecutables", pipExecutables)
709 710
710 @pyqtSlot() 711 @pyqtSlot()
711 def upgradePip(self, pip=""): 712 def upgradePip(self, pip="", userSite=False):
712 """ 713 """
713 Public method to upgrade pip itself. 714 Public method to upgrade pip itself.
714 715
715 @param pip pip command to be used 716 @param pip pip command to be used
716 @type str 717 @type str
718 @param userSite flag indicating an install to the user install
719 directory
720 @type bool
717 @return flag indicating a successful execution 721 @return flag indicating a successful execution
718 @rtype bool 722 @rtype bool
719 """ 723 """
720 # Upgrading pip needs to be treated specially because 724 # Upgrading pip needs to be treated specially because
721 # it must be done using the python executable 725 # it must be done using the python executable
722 726
723 if not pip: 727 if not pip:
724 default = self.tr("<Default>") 728 from .PipSelectionDialog import PipSelectionDialog
725 pipExecutables = sorted( 729 dlg = PipSelectionDialog(self.__plugin)
726 self.__plugin.getPreferences("PipExecutables")) 730 if dlg.exec_() != QDialog.Accepted:
727 pip, ok = QInputDialog.getItem( 731 return
728 None,
729 self.tr("Upgrade pip"),
730 self.tr("Select pip Executable:"),
731 [default] + pipExecutables,
732 0, False)
733 if not ok or not pip:
734 return False
735 732
736 if pip == default: 733 pip, userSite = dlg.getData()
734
735 if not pip:
737 pip = self.__plugin.getPreferences("CurrentPipExecutable") 736 pip = self.__plugin.getPreferences("CurrentPipExecutable")
738 737
739 python = self.__getPython(pip) 738 python = self.__getPython(pip)
740 if not python: 739 if not python:
741 python = E5FileDialog.getOpenFileName( 740 python = E5FileDialog.getOpenFileName(
749 748
750 if self.__plugin.getPreferences("PipSearchIndex"): 749 if self.__plugin.getPreferences("PipSearchIndex"):
751 indexUrl = \ 750 indexUrl = \
752 self.__plugin.getPreferences("PipSearchIndex") + "/simple" 751 self.__plugin.getPreferences("PipSearchIndex") + "/simple"
753 args = ["-m", "pip", "install", "--index-url", indexUrl, 752 args = ["-m", "pip", "install", "--index-url", indexUrl,
754 "--upgrade", "pip"] 753 "--upgrade"]
755 else: 754 else:
756 args = ["-m", "pip", "install", "--upgrade", "pip"] 755 args = ["-m", "pip", "install", "--upgrade"]
756 if userSite:
757 args.append("--user")
758 args.append("pip")
759
757 dia = PipDialog(self.tr('Upgrade PIP')) 760 dia = PipDialog(self.tr('Upgrade PIP'))
758 res = dia.startProcess(python, args) 761 res = dia.startProcess(python, args)
759 if res: 762 if res:
760 dia.exec_() 763 dia.exec_()
761 return res 764 return res
762 765
766 # TODO: add support for --user
763 @pyqtSlot() 767 @pyqtSlot()
764 def __repairPip(self): 768 def __repairPip(self):
765 """ 769 """
766 Private method to repair the pip installation. 770 Private method to repair the pip installation.
767 771
876 else: 880 else:
877 abort = False 881 abort = False
878 882
879 return abort 883 return abort
880 884
881 # TODO: add parameter userSite=False; arg: --user 885 def upgradePackages(self, packages, cmd="", userSite=False):
882 def upgradePackages(self, packages, cmd=""):
883 """ 886 """
884 Public method to upgrade the given list of packages. 887 Public method to upgrade the given list of packages.
885 888
886 @param packages list of packages to upgrade (list of string) 889 @param packages list of packages to upgrade
887 @param cmd pip command to be used (string) 890 @type list of str
888 @return flag indicating a successful execution (boolean) 891 @param cmd pip command to be used
892 @type str
893 @param userSite flag indicating an install to the user install
894 directory
895 @type bool
896 @return flag indicating a successful execution
897 @rtype bool
889 """ 898 """
890 if self.__checkUpgradePyQt(packages): 899 if self.__checkUpgradePyQt(packages):
891 return False 900 return False
892 901
893 if not cmd: 902 if not cmd:
896 indexUrl = \ 905 indexUrl = \
897 self.__plugin.getPreferences("PipSearchIndex") + "/simple" 906 self.__plugin.getPreferences("PipSearchIndex") + "/simple"
898 args = ["install", "--index-url", indexUrl, "--upgrade"] 907 args = ["install", "--index-url", indexUrl, "--upgrade"]
899 else: 908 else:
900 args = ["install", "--upgrade"] 909 args = ["install", "--upgrade"]
910 if userSite:
911 args.append("--user")
901 args += packages 912 args += packages
902 dia = PipDialog(self.tr('Upgrade Packages')) 913 dia = PipDialog(self.tr('Upgrade Packages'))
903 res = dia.startProcess(cmd, args) 914 res = dia.startProcess(cmd, args)
904 if res: 915 if res:
905 dia.exec_() 916 dia.exec_()
911 """ 922 """
912 from .PipPackagesInputDialog import PipPackagesInputDialog 923 from .PipPackagesInputDialog import PipPackagesInputDialog
913 dlg = PipPackagesInputDialog( 924 dlg = PipPackagesInputDialog(
914 self.__plugin, self.tr("Upgrade Packages")) 925 self.__plugin, self.tr("Upgrade Packages"))
915 if dlg.exec_() == QDialog.Accepted: 926 if dlg.exec_() == QDialog.Accepted:
916 command, packages = dlg.getData() 927 command, packages, user = dlg.getData()
917 if packages: 928 if packages:
918 self.upgradePackages(packages, cmd=command) 929 self.upgradePackages(packages, cmd=command, userSite=user)
919 930
920 # TODO: add parameter userSite=False; arg: --user 931 def installPackages(self, packages, cmd="", userSite=False):
921 def installPackages(self, packages, cmd=""):
922 """ 932 """
923 Public method to install the given list of packages. 933 Public method to install the given list of packages.
924 934
925 @param packages list of packages to install (list of string) 935 @param packages list of packages to install
926 @param cmd pip command to be used (string) 936 @type list of str
937 @param cmd pip command to be used
938 @type str
939 @param userSite flag indicating an install to the user install
940 directory
941 @type bool
927 """ 942 """
928 if not cmd: 943 if not cmd:
929 cmd = self.__plugin.getPreferences("CurrentPipExecutable") 944 cmd = self.__plugin.getPreferences("CurrentPipExecutable")
930 if self.__plugin.getPreferences("PipSearchIndex"): 945 if self.__plugin.getPreferences("PipSearchIndex"):
931 indexUrl = \ 946 indexUrl = \
932 self.__plugin.getPreferences("PipSearchIndex") + "/simple" 947 self.__plugin.getPreferences("PipSearchIndex") + "/simple"
933 args = ["install", "--index-url", indexUrl] 948 args = ["install", "--index-url", indexUrl]
934 else: 949 else:
935 args = ["install"] 950 args = ["install"]
951 if userSite:
952 args.append("--user")
936 args += packages 953 args += packages
937 dia = PipDialog(self.tr('Install Packages')) 954 dia = PipDialog(self.tr('Install Packages'))
938 res = dia.startProcess(cmd, args) 955 res = dia.startProcess(cmd, args)
939 if res: 956 if res:
940 dia.exec_() 957 dia.exec_()
945 """ 962 """
946 from .PipPackagesInputDialog import PipPackagesInputDialog 963 from .PipPackagesInputDialog import PipPackagesInputDialog
947 dlg = PipPackagesInputDialog( 964 dlg = PipPackagesInputDialog(
948 self.__plugin, self.tr("Install Packages")) 965 self.__plugin, self.tr("Install Packages"))
949 if dlg.exec_() == QDialog.Accepted: 966 if dlg.exec_() == QDialog.Accepted:
950 command, packages = dlg.getData() 967 command, packages, user = dlg.getData()
951 if packages: 968 if packages:
952 self.installPackages(packages, cmd=command) 969 self.installPackages(packages, cmd=command, userSite=user)
953 970
954 def __installLocalPackage(self): 971 def __installLocalPackage(self):
955 """ 972 """
956 Private slot to install a package available on local storage. 973 Private slot to install a package available on local storage.
957 """ 974 """
958 from .PipFileSelectionDialog import PipFileSelectionDialog 975 from .PipFileSelectionDialog import PipFileSelectionDialog
959 dlg = PipFileSelectionDialog(self.__plugin, "package") 976 dlg = PipFileSelectionDialog(self.__plugin, "package")
960 if dlg.exec_() == QDialog.Accepted: 977 if dlg.exec_() == QDialog.Accepted:
961 command, package = dlg.getData() 978 command, package, user = dlg.getData()
962 if package and os.path.exists(package): 979 if package and os.path.exists(package):
963 self.installPackages([package], cmd=command) 980 self.installPackages([package], cmd=command, userSite=user)
964 981
965 def __installRequirements(self): 982 def __installRequirements(self):
966 """ 983 """
967 Private slot to install packages as given in a requirements file. 984 Private slot to install packages as given in a requirements file.
968 """ 985 """
969 from .PipFileSelectionDialog import PipFileSelectionDialog 986 from .PipFileSelectionDialog import PipFileSelectionDialog
970 dlg = PipFileSelectionDialog(self.__plugin, "requirements") 987 dlg = PipFileSelectionDialog(self.__plugin, "requirements")
971 if dlg.exec_() == QDialog.Accepted: 988 if dlg.exec_() == QDialog.Accepted:
972 command, requirements = dlg.getData() 989 command, requirements, user = dlg.getData()
973 if requirements and os.path.exists(requirements): 990 if requirements and os.path.exists(requirements):
974 if not command: 991 if not command:
975 command = self.__plugin.getPreferences( 992 command = self.__plugin.getPreferences(
976 "CurrentPipExecutable") 993 "CurrentPipExecutable")
977 if self.__plugin.getPreferences("PipSearchIndex"): 994 if self.__plugin.getPreferences("PipSearchIndex"):
979 self.__plugin.getPreferences("PipSearchIndex") + \ 996 self.__plugin.getPreferences("PipSearchIndex") + \
980 "/simple" 997 "/simple"
981 args = ["install", "--index-url", indexUrl] 998 args = ["install", "--index-url", indexUrl]
982 else: 999 else:
983 args = ["install"] 1000 args = ["install"]
1001 if user:
1002 args.append("--user")
984 args += ["--requirement", requirements] 1003 args += ["--requirement", requirements]
985 dia = PipDialog(self.tr('Install Packages from Requirements')) 1004 dia = PipDialog(self.tr('Install Packages from Requirements'))
986 res = dia.startProcess(command, args) 1005 res = dia.startProcess(command, args)
987 if res: 1006 if res:
988 dia.exec_() 1007 dia.exec_()
1019 """ 1038 """
1020 Private slot to uninstall packages to be given by the user. 1039 Private slot to uninstall packages to be given by the user.
1021 """ 1040 """
1022 from .PipPackagesInputDialog import PipPackagesInputDialog 1041 from .PipPackagesInputDialog import PipPackagesInputDialog
1023 dlg = PipPackagesInputDialog( 1042 dlg = PipPackagesInputDialog(
1024 self.__plugin, self.tr("Uninstall Packages")) 1043 self.__plugin, self.tr("Uninstall Packages"), install=False)
1025 if dlg.exec_() == QDialog.Accepted: 1044 if dlg.exec_() == QDialog.Accepted:
1026 command, packages = dlg.getData() 1045 command, packages, _user = dlg.getData()
1027 if packages: 1046 if packages:
1028 self.uninstallPackages(packages, cmd=command) 1047 self.uninstallPackages(packages, cmd=command)
1029 1048
1030 def __uninstallRequirements(self): 1049 def __uninstallRequirements(self):
1031 """ 1050 """
1032 Private slot to uninstall packages as given in a requirements file. 1051 Private slot to uninstall packages as given in a requirements file.
1033 """ 1052 """
1034 from .PipFileSelectionDialog import PipFileSelectionDialog 1053 from .PipFileSelectionDialog import PipFileSelectionDialog
1035 dlg = PipFileSelectionDialog(self.__plugin, "requirements") 1054 dlg = PipFileSelectionDialog(self.__plugin, "requirements",
1055 install=False)
1036 if dlg.exec_() == QDialog.Accepted: 1056 if dlg.exec_() == QDialog.Accepted:
1037 command, requirements = dlg.getData() 1057 command, requirements, _user = dlg.getData()
1038 if requirements and os.path.exists(requirements): 1058 if requirements and os.path.exists(requirements):
1039 try: 1059 try:
1040 f = open(requirements, "r") 1060 f = open(requirements, "r")
1041 reqs = f.read().splitlines() 1061 reqs = f.read().splitlines()
1042 f.close() 1062 f.close()

eric ide

mercurial