src/eric7/PipInterface/Pip.py

branch
eric7-maintenance
changeset 9654
7328efba128b
parent 9549
67295777d9fe
parent 9653
e67609152c5e
child 9832
3885b9d7bd31
equal deleted inserted replaced
9555:88f10deec960 9654:7328efba128b
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2015 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2015 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Package implementing the pip GUI logic. 7 Package implementing the pip GUI logic.
8 """ 8 """
14 14
15 from PyQt6.QtCore import QCoreApplication, QObject, QProcess, QThread, QUrl, pyqtSlot 15 from PyQt6.QtCore import QCoreApplication, QObject, QProcess, QThread, QUrl, pyqtSlot
16 from PyQt6.QtNetwork import QNetworkAccessManager, QNetworkReply, QNetworkRequest 16 from PyQt6.QtNetwork import QNetworkAccessManager, QNetworkReply, QNetworkRequest
17 from PyQt6.QtWidgets import QDialog, QInputDialog, QLineEdit 17 from PyQt6.QtWidgets import QDialog, QInputDialog, QLineEdit
18 18
19 from eric7 import Globals, Preferences 19 from eric7 import Preferences
20 from eric7.EricNetwork.EricNetworkProxyFactory import proxyAuthenticationRequired 20 from eric7.EricNetwork.EricNetworkProxyFactory import proxyAuthenticationRequired
21 from eric7.EricWidgets import EricMessageBox 21 from eric7.EricWidgets import EricMessageBox
22 from eric7.EricWidgets.EricApplication import ericApp 22 from eric7.EricWidgets.EricApplication import ericApp
23 from eric7.SystemUtilities import OSUtilities, PythonUtilities
23 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog 24 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
24 25
25 try: 26 try:
26 from eric7.EricNetwork.EricSslErrorHandler import EricSslErrorHandler 27 from eric7.EricNetwork.EricSslErrorHandler import EricSslErrorHandler
27 28
145 # Environment: $PIP_CONFIG_FILE 146 # Environment: $PIP_CONFIG_FILE
146 147
147 with contextlib.suppress(KeyError): 148 with contextlib.suppress(KeyError):
148 return os.environ["PIP_CONFIG_FILE"] 149 return os.environ["PIP_CONFIG_FILE"]
149 150
150 if Globals.isWindowsPlatform(): 151 if OSUtilities.isWindowsPlatform():
151 config = os.path.join(os.environ["APPDATA"], "pip", "pip.ini") 152 config = os.path.join(os.environ["APPDATA"], "pip", "pip.ini")
152 elif Globals.isMacPlatform(): 153 elif OSUtilities.isMacPlatform():
153 config = os.path.expanduser("~/Library/Application Support/pip/pip.conf") 154 config = os.path.expanduser("~/Library/Application Support/pip/pip.conf")
154 else: 155 else:
155 config = os.path.expanduser("~/.config/pip/pip.conf") 156 config = os.path.expanduser("~/.config/pip/pip.conf")
156 157
157 return config 158 return config
166 @rtype str 167 @rtype str
167 """ 168 """
168 # Unix, OS X: $VIRTUAL_ENV/pip.conf 169 # Unix, OS X: $VIRTUAL_ENV/pip.conf
169 # Windows: %VIRTUAL_ENV%\pip.ini 170 # Windows: %VIRTUAL_ENV%\pip.ini
170 171
171 pip = "pip.ini" if Globals.isWindowsPlatform() else "pip.conf" 172 pip = "pip.ini" if OSUtilities.isWindowsPlatform() else "pip.conf"
172 173
173 venvManager = ericApp().getObject("VirtualEnvManager") 174 venvManager = ericApp().getObject("VirtualEnvManager")
174 venvDirectory = ( 175 venvDirectory = (
175 os.path.dirname(self.getUserConfig()) 176 os.path.dirname(self.getUserConfig())
176 if venvManager.isGlobalEnvironment(venvName) 177 if venvManager.isGlobalEnvironment(venvName)
202 @return interpreter path 203 @return interpreter path
203 @rtype str 204 @rtype str
204 """ 205 """
205 interpreter = ( 206 interpreter = (
206 ericApp().getObject("Project").getProjectInterpreter() 207 ericApp().getObject("Project").getProjectInterpreter()
207 if venvName == self.getProjectEnvironmentString() 208 if venvName in (self.getProjectEnvironmentString(), "<project>")
208 else ericApp() 209 else ericApp()
209 .getObject("VirtualEnvManager") 210 .getObject("VirtualEnvManager")
210 .getVirtualenvInterpreter(venvName) 211 .getVirtualenvInterpreter(venvName)
211 ) 212 )
212 if not interpreter: 213 if not interpreter:
361 if not venvName: 362 if not venvName:
362 return False 363 return False
363 364
364 if self.getVirtualenvInterpreter(venvName) in ( 365 if self.getVirtualenvInterpreter(venvName) in (
365 sys.executable, 366 sys.executable,
366 Globals.getPythonExecutable(), 367 PythonUtilities.getPythonExecutable(),
367 ): 368 ):
368 upgradePyQt = self.__checkUpgradePyQt(packages) 369 upgradePyQt = self.__checkUpgradePyQt(packages)
369 upgradeEric = self.__checkUpgradeEric(packages) 370 upgradeEric = self.__checkUpgradeEric(packages)
370 if upgradeEric or upgradePyQt: 371 if upgradeEric or upgradePyQt:
371 try: 372 try:
673 ) 674 )
674 675
675 return packages 676 return packages
676 677
677 def getOutdatedPackages( 678 def getOutdatedPackages(
678 self, envName, localPackages=True, notRequired=False, usersite=False 679 self,
680 envName,
681 localPackages=True,
682 notRequired=False,
683 usersite=False,
684 interpreter=None,
679 ): 685 ):
680 """ 686 """
681 Public method to get the list of outdated packages. 687 Public method to get the list of outdated packages.
682 688
683 @param envName name of the environment to get the packages for 689 @param envName name of the environment to get the packages for
684 @type str 690 @type str
685 @param localPackages flag indicating to get local packages only 691 @param localPackages flag indicating to get local packages only
686 @type bool 692 (defaults to False)
693 @type bool (optional)
687 @param notRequired flag indicating to list packages that are not 694 @param notRequired flag indicating to list packages that are not
688 dependencies of installed packages as well 695 dependencies of installed packages as well (defaults to False)
689 @type bool 696 @type bool (optional)
690 @param usersite flag indicating to only list packages installed 697 @param usersite flag indicating to only list packages installed
691 in user-site 698 in user-site (defaults to False)
692 @type bool 699 @type bool (optional)
700 @param interpreter path of an interpreter executable. If this is not
701 None, it will override the given environment name (defaults to None)
702 @type str (optional)
693 @return list of tuples containing the package name, installed version 703 @return list of tuples containing the package name, installed version
694 and available version 704 and available version
695 @rtype list of tuple of (str, str, str) 705 @rtype list of tuple of (str, str, str)
696 """ 706 """
697 packages = [] 707 packages = []
698 708
699 if envName: 709 if envName:
700 interpreter = self.getVirtualenvInterpreter(envName) 710 if interpreter is None:
711 interpreter = self.getVirtualenvInterpreter(envName)
701 if interpreter: 712 if interpreter:
702 args = [ 713 args = [
703 "-m", 714 "-m",
704 "pip", 715 "pip",
705 "list", 716 "list",
744 ) 755 )
745 ) 756 )
746 757
747 return packages 758 return packages
748 759
749 def checkPackageOutdated(self, packageStart, envName): 760 def checkPackagesOutdated(self, packageStarts, envName, interpreter=None):
750 """ 761 """
751 Public method to check, if a group of packages is outdated. 762 Public method to check, if groups of packages are outdated.
752 763
753 @param packageStart start string for package names to be checked 764 @param packageStarts list of start strings for package names to be checked
754 (case insensitive) 765 (case insensitive)
755 @type str 766 @type str
756 @param envName name of the environment to get the packages for 767 @param envName name of the environment to get the packages for
757 @type str 768 @type str
758 @return tuple containing a flag indicating outdated packages and the 769 @param interpreter path of an interpreter executable. If this is not
759 list of tuples containing the package name, installed version 770 None, it will override the given environment name (defaults to None)
760 and available version 771 @type str (optional)
761 @rtype tuple of (bool, (str, str, str)) 772 @return list of tuples containing the package name, installed version
762 """ 773 and available version of outdated packages
763 filteredPackages = [] 774 @rtype tuple of (str, str, str)
764 775 """
765 if bool(envName) and bool(packageStart): 776 if (bool(envName) or bool(interpreter)) and any(bool(p) for p in packageStarts):
766 packages = self.getOutdatedPackages(envName) 777 packages = self.getOutdatedPackages(envName, interpreter=interpreter)
767 filterStr = packageStart.lower() 778 filterStrings = tuple(
779 start.lower() for start in packageStarts if bool(start)
780 )
768 filteredPackages = [ 781 filteredPackages = [
769 p for p in packages if p[0].lower().startswith(filterStr) 782 p for p in packages if p[0].lower().startswith(filterStrings)
770 ] 783 ]
771 784 else:
772 return bool(filteredPackages), filteredPackages 785 filteredPackages = []
786
787 return filteredPackages
773 788
774 def getPackageDetails(self, name, version): 789 def getPackageDetails(self, name, version):
775 """ 790 """
776 Public method to get package details using the PyPI JSON interface. 791 Public method to get package details using the PyPI JSON interface.
777 792

eric ide

mercurial