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 |
1017 dependencies = [] |
1068 dependencies = [] |
1018 |
1069 |
1019 if envName: |
1070 if envName: |
1020 interpreter = self.getVirtualenvInterpreter(envName) |
1071 interpreter = self.getVirtualenvInterpreter(envName) |
1021 if interpreter: |
1072 if interpreter: |
1022 args = [ |
1073 args = ["-m", "pipdeptree", "--python", interpreter, "--json-tree"] |
1023 os.path.join(os.path.dirname(__file__), "pipdeptree.py"), |
|
1024 "--json-tree", |
|
1025 ] |
|
1026 if localPackages: |
1074 if localPackages: |
1027 args.append("--local-only") |
1075 args.append("--local-only") |
1028 if usersite: |
1076 if usersite: |
1029 args.append("--user-only") |
1077 args.append("--user-only") |
1030 if reverse: |
1078 if reverse: |
1031 args.append("--reverse") |
1079 args.append("--reverse") |
1032 |
1080 |
1033 proc = QProcess() |
1081 proc = QProcess() |
1034 proc.start(interpreter, args) |
1082 proc.start(PythonUtilities.getPythonExecutable(), args) |
1035 if proc.waitForStarted(15000) and proc.waitForFinished(30000): |
1083 if proc.waitForStarted(15000) and proc.waitForFinished(30000): |
1036 output = str( |
1084 output = str( |
1037 proc.readAllStandardOutput(), |
1085 proc.readAllStandardOutput(), |
1038 Preferences.getSystem("IOEncoding"), |
1086 Preferences.getSystem("IOEncoding"), |
1039 "replace", |
1087 "replace", |