src/eric7/PipInterface/Pip.py

branch
eric7-maintenance
changeset 10460
3b34efa2857c
parent 10222
1146cc8fbf5d
parent 10439
21c28b0f9e41
child 10534
783d835d7fe4
--- a/src/eric7/PipInterface/Pip.py	Sun Dec 03 14:54:00 2023 +0100
+++ b/src/eric7/PipInterface/Pip.py	Mon Jan 01 11:10:45 2024 +0100
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Copyright (c) 2015 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
+# Copyright (c) 2015 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
 #
 
 """
@@ -21,7 +21,7 @@
 from eric7.EricNetwork.EricNetworkProxyFactory import proxyAuthenticationRequired
 from eric7.EricWidgets import EricMessageBox
 from eric7.EricWidgets.EricApplication import ericApp
-from eric7.SystemUtilities import OSUtilities, PythonUtilities
+from eric7.SystemUtilities import FileSystemUtilities, OSUtilities, PythonUtilities
 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
 
 try:
@@ -130,7 +130,7 @@
                 process.waitForFinished(2000)
                 process.kill()
                 process.waitForFinished(3000)
-                return False, self.tr("python did not finish within" " 30 seconds.")
+                return False, self.tr("python did not finish within 30 seconds.")
 
         return False, self.tr("python could not be started.")
 
@@ -324,7 +324,7 @@
             p
             for p in packages
             if p.lower()
-            in [
+            in (
                 "pyqt6",
                 "pyqt6-sip",
                 "pyqt6-webengine",
@@ -333,7 +333,7 @@
                 "pyqt6-qt6",
                 "pyqt6-webengine-qt6",
                 "pyqt6-charts-qt6",
-            ]
+            )
         ]
         return bool(pyqtPackages)
 
@@ -350,6 +350,33 @@
         ericPackages = [p for p in packages if p.lower() == "eric-ide"]
         return bool(ericPackages)
 
+    def __filterUpgradePackages(self, packages):
+        """
+        Private method to filter out the packages that cannot be upgraded without
+        stopping eric first.
+
+        @param packages list of packages to upgrade
+        @type list of str
+        @return list of packages that can be upgraded
+        @rtype list of str
+        """
+        return [
+            p
+            for p in packages
+            if p.lower()
+            not in (
+                "eric-ide",
+                "pyqt6",
+                "pyqt6-sip",
+                "pyqt6-webengine",
+                "pyqt6-charts",
+                "pyqt6-qscintilla",
+                "pyqt6-qt6",
+                "pyqt6-webengine-qt6",
+                "pyqt6-charts-qt6",
+            )
+        ]
+
     def upgradePackages(self, packages, venvName, userSite=False):
         """
         Public method to upgrade the given list of packages.
@@ -367,28 +394,32 @@
         if not venvName:
             return False
 
-        if self.getVirtualenvInterpreter(venvName) in (
-            sys.executable,
-            PythonUtilities.getPythonExecutable(),
+        interpreter = self.getVirtualenvInterpreter(venvName)
+        if not interpreter:
+            return False
+
+        if FileSystemUtilities.samefilepath(
+            interpreter, sys.executable, followSymlinks=False
         ):
             upgradePyQt = self.__checkUpgradePyQt(packages)
             upgradeEric = self.__checkUpgradeEric(packages)
             if upgradeEric or upgradePyQt:
                 try:
                     if upgradeEric and upgradePyQt:
-                        self.__ui.upgradeEricPyQt()
+                        res = self.__ui.upgradeEricPyQt()
                     elif upgradeEric:
-                        self.__ui.upgradeEric()
+                        res = self.__ui.upgradeEric()
                     elif upgradePyQt:
-                        self.__ui.upgradePyQt()
-                    return None  # should not be reached; play it safe
+                        res = self.__ui.upgradePyQt()
+                    else:
+                        return None  # should not be reached; play it safe
+
+                    if not res:
+                        # user rejected PyQt6 and/or eric-ide/eric7 update
+                        packages = self.__filterUpgradePackages(packages)
                 except AttributeError:
                     return False
 
-        interpreter = self.getVirtualenvInterpreter(venvName)
-        if not interpreter:
-            return False
-
         if Preferences.getPip("PipSearchIndex"):
             indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
             args = ["-m", "pip", "install", "--index-url", indexUrl, "--upgrade"]
@@ -895,7 +926,7 @@
                 )
                 with contextlib.suppress(json.JSONDecodeError, KeyError):
                     data = json.loads(dataStr)
-                    result = list(data["releases"].keys())
+                    result = list(data["releases"])
 
         return result
 

eric ide

mercurial