src/eric7/PipInterface/Pip.py

branch
eric7
changeset 10209
8bb763e85937
parent 10177
27a6e35c64ed
child 10222
1146cc8fbf5d
child 10372
1444b4bee64b
equal deleted inserted replaced
10208:d2fb44007ed3 10209:8bb763e85937
6 """ 6 """
7 Package implementing the pip GUI logic. 7 Package implementing the pip GUI logic.
8 """ 8 """
9 9
10 import contextlib 10 import contextlib
11 import functools
11 import json 12 import json
12 import os 13 import os
13 import sys 14 import sys
14 15
15 from PyQt6.QtCore import QCoreApplication, QObject, QProcess, QThread, QUrl, pyqtSlot 16 from PyQt6.QtCore import QCoreApplication, QObject, QProcess, QThread, QUrl, pyqtSlot
682 envName, 683 envName,
683 localPackages=True, 684 localPackages=True,
684 notRequired=False, 685 notRequired=False,
685 usersite=False, 686 usersite=False,
686 interpreter=None, 687 interpreter=None,
688 callback=None,
687 ): 689 ):
688 """ 690 """
689 Public method to get the list of outdated packages. 691 Public method to get the list of outdated packages.
690 692
691 @param envName name of the environment to get the packages for 693 @param envName name of the environment to get the packages for
700 in user-site (defaults to False) 702 in user-site (defaults to False)
701 @type bool (optional) 703 @type bool (optional)
702 @param interpreter path of an interpreter executable. If this is not 704 @param interpreter path of an interpreter executable. If this is not
703 None, it will override the given environment name (defaults to None) 705 None, it will override the given environment name (defaults to None)
704 @type str (optional) 706 @type str (optional)
707 @param callback method accepting a list of tuples containing the
708 package name, installed version and available version
709 @type function
705 @return list of tuples containing the package name, installed version 710 @return list of tuples containing the package name, installed version
706 and available version 711 and available version
707 @rtype list of tuple of (str, str, str) 712 @rtype list of tuple of (str, str, str)
708 """ 713 """
709 packages = [] 714 packages = []
729 if Preferences.getPip("PipSearchIndex"): 734 if Preferences.getPip("PipSearchIndex"):
730 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" 735 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
731 args += ["--index-url", indexUrl] 736 args += ["--index-url", indexUrl]
732 737
733 proc = QProcess() 738 proc = QProcess()
739 if callback:
740 self.__outdatedProc = proc
741 proc.finished.connect(
742 functools.partial(self.__outdatedFinished, callback, proc)
743 )
744 proc.start(interpreter, args)
745 return None
746
734 proc.start(interpreter, args) 747 proc.start(interpreter, args)
735 if proc.waitForStarted(15000) and proc.waitForFinished(30000): 748 if proc.waitForStarted(15000) and proc.waitForFinished(30000):
736 output = str( 749 packages = self.__extractOutdatedPackages(proc)
737 proc.readAllStandardOutput(),
738 Preferences.getSystem("IOEncoding"),
739 "replace",
740 ).strip()
741 if output:
742 output = output.splitlines()[0]
743 try:
744 jsonList = json.loads(output)
745 except Exception:
746 jsonList = []
747
748 for package in jsonList:
749 if isinstance(package, dict):
750 packages.append(
751 (
752 package["name"],
753 package["version"],
754 package["latest_version"],
755 )
756 )
757 750
758 return packages 751 return packages
752
753 def __extractOutdatedPackages(self, proc):
754 """
755 Private method to extract the outdated packages list out of the process output.
756
757 @param proc reference to the process
758 @type QProcess
759 @return list of tuples containing the package name, installed version
760 and available version
761 @rtype list of tuple of (str, str, str)
762 """
763 packages = []
764
765 output = str(
766 proc.readAllStandardOutput(),
767 Preferences.getSystem("IOEncoding"),
768 "replace",
769 ).strip()
770 if output:
771 output = output.splitlines()[0]
772 try:
773 jsonList = json.loads(output)
774 except Exception:
775 jsonList = []
776
777 for package in jsonList:
778 if isinstance(package, dict):
779 packages.append(
780 (
781 package["name"],
782 package["version"],
783 package["latest_version"],
784 )
785 )
786
787 return packages
788
789 def __outdatedFinished(self, callback, proc, exitCode, exitStatus):
790 """
791 Private method to handle the process finished signal.
792
793 @param callback reference to the function to be called with the list of
794 outdated packages
795 @type function
796 @param proc reference to the process
797 @type QProcess
798 @param exitCode exit code of the process
799 @type int
800 @param exitStatus exit status of the process
801 @type QProcess.ExitStatus
802 """
803 packages = (
804 self.__extractOutdatedPackages(proc)
805 if exitStatus == QProcess.ExitStatus.NormalExit and exitCode == 0
806 else []
807 )
808 callback(packages)
809 self.__outdatedProc = None
759 810
760 def checkPackagesOutdated(self, packageStarts, envName, interpreter=None): 811 def checkPackagesOutdated(self, packageStarts, envName, interpreter=None):
761 """ 812 """
762 Public method to check, if groups of packages are outdated. 813 Public method to check, if groups of packages are outdated.
763 814

eric ide

mercurial