Continued to remove all explicit references to Python interpreters and replace them by references to virtual environments.

Fri, 15 Jun 2018 18:49:48 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 15 Jun 2018 18:49:48 +0200
changeset 6348
d6c0b8ab1fc6
parent 6347
bcca9eba56a1
child 6349
17b3c75913de

Continued to remove all explicit references to Python interpreters and replace them by references to virtual environments.

Debugger/DebugServer.py file | annotate | diff | comparison | revisions
Debugger/DebuggerInterfacePython.py file | annotate | diff | comparison | revisions
Preferences/__init__.py file | annotate | diff | comparison | revisions
UI/UserInterface.py file | annotate | diff | comparison | revisions
Utilities/BackgroundService.py file | annotate | diff | comparison | revisions
Utilities/__init__.py file | annotate | diff | comparison | revisions
--- a/Debugger/DebugServer.py	Fri Jun 15 11:56:58 2018 +0200
+++ b/Debugger/DebugServer.py	Fri Jun 15 18:49:48 2018 +0200
@@ -218,10 +218,10 @@
         # Change clientType if dependent interpreter not exist anymore
         # (maybe deinstalled,...)
         elif self.clientType == 'Python2' and Preferences.getDebugger(
-                "PythonInterpreter") == '':
+                "Python2VirtualEnv") == '':
             self.clientType = 'Python3'
         elif self.clientType == 'Python3' and Preferences.getDebugger(
-                "Python3Interpreter") == '':
+                "Python3VirtualEnv") == '':
             self.clientType = 'Python2'
         
         self.lastClientType = ''
--- a/Debugger/DebuggerInterfacePython.py	Fri Jun 15 11:56:58 2018 +0200
+++ b/Debugger/DebuggerInterfacePython.py	Fri Jun 15 18:49:48 2018 +0200
@@ -147,15 +147,17 @@
         """
         if not interpreter:
             if self.__variant == "Python2":
-                interpreter = Preferences.getDebugger("PythonInterpreter")
+                venvName = Preferences.getDebugger("Python2VirtualEnv")
             else:
-                interpreter = Preferences.getDebugger("Python3Interpreter")
+                venvName = Preferences.getDebugger("Python3VirtualEnv")
+        interpreter = e5App().getObject("VirtualEnvManager")\
+            .getVirtualenvInterpreter(venvName)
         if interpreter == "":
             E5MessageBox.critical(
                 None,
                 self.tr("Start Debugger"),
                 self.tr(
-                    """<p>No {0} interpreter configured.</p>""")
+                    """<p>No suitable {0} environment configured.</p>""")
                 .format(self.__variant))
             return None, False, ""
         
@@ -1177,13 +1179,13 @@
             py3Exts.append(".{0}".format(ext))
     
     registryData = []
-    if py2Exts and Preferences.getDebugger("PythonInterpreter"):
+    if py2Exts and Preferences.getDebugger("Python2VirtualEnv"):
         registryData.append(
             ("Python2", ClientDefaultCapabilities, py2Exts,
              createDebuggerInterfacePython2)
         )
     
-    if py3Exts and Preferences.getDebugger("Python3Interpreter"):
+    if py3Exts and Preferences.getDebugger("Python3VirtualEnv"):
         registryData.append(
             ("Python3", ClientDefaultCapabilities, py3Exts,
                 createDebuggerInterfacePython3)
--- a/Preferences/__init__.py	Fri Jun 15 11:56:58 2018 +0200
+++ b/Preferences/__init__.py	Fri Jun 15 18:49:48 2018 +0200
@@ -31,7 +31,7 @@
 from PyQt5.QtCore import QDir, QPoint, QLocale, QSettings, QFileInfo, \
     QCoreApplication, QByteArray, QSize, QUrl, Qt, QLibraryInfo, QDateTime
 from PyQt5.QtGui import QColor, QFont, QPalette
-from PyQt5.QtWidgets import QInputDialog, QApplication
+from PyQt5.QtWidgets import QApplication
 from PyQt5.QtNetwork import QNetworkRequest
 try:
     from PyQt5.QtWebKit import QWebSettings
@@ -48,8 +48,8 @@
 from E5Network.E5Ftp import E5FtpProxyType
 
 from Globals import settingsNameOrganization, settingsNameGlobal, \
-    settingsNameRecent, isWindowsPlatform, findPythonInterpreters, \
-    getPyQt5ModulesDirectory, qVersionTuple
+    settingsNameRecent, isWindowsPlatform, getPyQt5ModulesDirectory, \
+    qVersionTuple
 
 from Project.ProjectBrowserFlags import SourcesBrowserFlag, FormsBrowserFlag, \
     ResourcesBrowserFlag, TranslationsBrowserFlag, InterfacesBrowserFlag, \
@@ -94,8 +94,6 @@
         "ShowExceptionInShell": True,
         "Python2VirtualEnv": "",
         "Python3VirtualEnv": "",
-        "PythonInterpreter": "",
-        "Python3Interpreter": "",
         "RubyInterpreter": "",
         "DebugClientType": "standard",
         # supported "standard", "custom"
@@ -1799,6 +1797,8 @@
             prefClass.settings.value(
                 "Debugger/" + key, prefClass.debuggerDefaults[key]))
     elif key in ["PythonInterpreter", "Python3Interpreter"]:
+        # TODO: Remove this statement when done
+##        raise KeyError("{0} is no longer supported.".format(key))
         # This code is here to ensure backward compatibility.
         if key == "PythonInterpreter":
             newKey = "Python2VirtualEnv"
--- a/UI/UserInterface.py	Fri Jun 15 11:56:58 2018 +0200
+++ b/UI/UserInterface.py	Fri Jun 15 18:49:48 2018 +0200
@@ -238,6 +238,12 @@
         # load the view profiles
         self.profiles = Preferences.getUI("ViewProfiles2")
         
+        # Generate the virtual environment manager
+        from VirtualEnv.VirtualenvManager import VirtualenvManager
+        self.virtualenvManager = VirtualenvManager(self)
+        # register it early because it is needed very soon
+        e5App().registerObject("VirtualEnvManager", self.virtualenvManager)
+        
         # Generate the debug server object
         from Debugger.DebugServer import DebugServer
         debugServer = DebugServer()
@@ -546,9 +552,6 @@
             QDesktopServices.setUrlHandler("http", self.handleUrl)
             QDesktopServices.setUrlHandler("https", self.handleUrl)
         
-        from VirtualEnv.VirtualenvManager import VirtualenvManager
-        self.virtualenvManager = VirtualenvManager(self)
-        
         # register all relevant objects
         splash.showMessage(self.tr("Registering Objects..."))
         e5App().registerObject("UserInterface", self)
@@ -571,7 +574,6 @@
         e5App().registerObject("Symbols", self.symbolsViewer)
         e5App().registerObject("Numbers", self.numbersViewer)
         e5App().registerObject("DocuViewer", self.codeDocumentationViewer)
-        e5App().registerObject("VirtualEnvManager", self.virtualenvManager)
         
         # list of web addresses serving the versions file
         self.__httpAlternatives = Preferences.getUI("VersionsUrls6")
@@ -5084,9 +5086,15 @@
         pythonDocDir = Preferences.getHelp("PythonDocDir")
         if not pythonDocDir:
             if Utilities.isWindowsPlatform():
-                pythonDocDir = Utilities.getEnvironmentEntry(
-                    "PYTHON3DOCDIR",
-                    os.path.join(os.path.dirname(sys.executable), "doc"))
+                venvName = Preferences.getDebugger("Python3VirtualEnv")
+                interpreter = e5App().getObject("VirtualEnvManager")\
+                    .getVirtualenvInterpreter(venvName)
+                if interpreter:
+                    default = os.path.join(os.path.dirname(interpreter), "doc")
+                else:
+                    default = ""
+                pythonDocDir = \
+                    Utilities.getEnvironmentEntry("PYTHON3DOCDIR", default)
             else:
                 pythonDocDir = Utilities.getEnvironmentEntry(
                     "PYTHON3DOCDIR",
@@ -5147,11 +5155,13 @@
         Private slot to show the Python 2 documentation.
         """
         pythonDocDir = Preferences.getHelp("Python2DocDir")
-        executable = Preferences.getDebugger("PythonInterpreter")
         if not pythonDocDir:
             if Utilities.isWindowsPlatform():
-                if executable:
-                    default = os.path.join(os.path.dirname(executable), "doc")
+                venvName = Preferences.getDebugger("Python2VirtualEnv")
+                interpreter = e5App().getObject("VirtualEnvManager")\
+                    .getVirtualenvInterpreter(venvName)
+                if interpreter:
+                    default = os.path.join(os.path.dirname(interpreter), "doc")
                 else:
                     default = ""
                 pythonDocDir = \
--- a/Utilities/BackgroundService.py	Fri Jun 15 11:56:58 2018 +0200
+++ b/Utilities/BackgroundService.py	Fri Jun 15 18:49:48 2018 +0200
@@ -68,14 +68,15 @@
         ## Note: Need the port if started external in debugger:
         print('BackgroundService listening on: {0:d}'.format(port))
         # __IGNORE_WARNING__
-        for pyName in ['Python', 'Python3']:
-            interpreter = Preferences.getDebugger(
-                pyName + "Interpreter")
-            process = self.__startExternalClient(interpreter, port)
-            if process:
-                if pyName == 'Python':
-                    pyName = 'Python2'
-                self.processes[pyName] = process, interpreter
+        for pyName in ['Python2', 'Python3']:
+            venvName = Preferences.getDebugger(
+                pyName + "VirtualEnv")
+            interpreter = e5App().getObject("VirtualEnvManager")\
+                .getVirtualenvInterpreter(venvName)
+            if interpreter:
+                process = self.__startExternalClient(interpreter, port)
+                if process:
+                    self.processes[pyName] = process, interpreter
 
     def __startExternalClient(self, interpreter, port):
         """
--- a/Utilities/__init__.py	Fri Jun 15 11:56:58 2018 +0200
+++ b/Utilities/__init__.py	Fri Jun 15 18:49:48 2018 +0200
@@ -1766,17 +1766,18 @@
     
     if isWindowsPlatform():
         pysideInterpreters = checkPyside(variant)
-        interpreter = sys.version_info[0] - 2
-        hasPyside = pysideInterpreters[interpreter]
+        interpreterIndex = sys.version_info[0] - 2
+        hasPyside = pysideInterpreters[interpreterIndex]
         # if it isn't the internal interpreter, it has to be the external one
         if not hasPyside:
-            interpreter = not interpreter
-        if interpreter:
-            prefix = os.path.dirname(
-                Preferences.getDebugger("Python3Interpreter"))
+            interpreterIndex = not interpreterIndex
+        if interpreterIndex:
+            venvName = Preferences.getDebugger("Python3VirtualEnv")
         else:
-            prefix = os.path.dirname(
-                Preferences.getDebugger("PythonInterpreter"))
+            venvName = Preferences.getDebugger("Python2VirtualEnv")
+        interpreter = e5App().getObject("VirtualEnvManager")\
+            .getVirtualenvInterpreter(venvName)
+        prefix = os.path.dirname(interpreter)
         if toolname in ["pyside-uic", "pyside2-uic"]:
             return os.path.join(prefix, "Scripts", toolname + '.exe')
         else:
@@ -1809,8 +1810,10 @@
     assert variant in ("1", "2")
     
     pysideInformation = []
-    for interpreterName in ["PythonInterpreter", "Python3Interpreter"]:
-        interpreter = Preferences.getDebugger(interpreterName)
+    for venvNameKey in ["Python2VirtualEnv", "Python3VirtualEnv"]:
+        venvName = Preferences.getDebugger(venvNameKey)
+        interpreter = e5App().getObject("VirtualEnvManager")\
+            .getVirtualenvInterpreter(venvName)
         if interpreter == "" or not isinpath(interpreter):
             hasPyside = False
         else:

eric ide

mercurial