eric6/Utilities/__init__.py

branch
maintenance
changeset 8043
0acf98cd089a
parent 7924
8a96736d465e
parent 7960
e8fc383322f7
child 8142
43248bafe9b2
--- a/eric6/Utilities/__init__.py	Sun Jan 17 13:53:08 2021 +0100
+++ b/eric6/Utilities/__init__.py	Mon Feb 01 10:38:16 2021 +0100
@@ -4,7 +4,7 @@
 #
 
 """
-Package implementing various functions/classes needed everywhere within eric6.
+Package implementing various functions/classes needed everywhere within eric.
 """
 
 import os
@@ -283,7 +283,7 @@
     Function to read a file and decode its contents into proper text.
     
     @param filename name of the file to read (string)
-    @keyparam encoding encoding to be used to read the file (string)
+    @param encoding encoding to be used to read the file (string)
     @return tuple of decoded text and encoding (string, string)
     """
     with open(filename, "rb") as f:
@@ -692,9 +692,9 @@
     comment.
     
     @param line line to extract flags from (string)
-    @keyparam startComment string identifying the start of the comment (string)
-    @keyparam endComment string identifying the end of a comment (string)
-    @keyparam flagsLine flag indicating to check for a flags only line (bool)
+    @param startComment string identifying the start of the comment (string)
+    @param endComment string identifying the end of a comment (string)
+    @param flagsLine flag indicating to check for a flags only line (bool)
     @return list containing the extracted flags (list of strings)
     """
     flags = []
@@ -1559,7 +1559,7 @@
     
     @param filename name of the file with extension (str)
     @param source of the file (str)
-    @keyparam editor reference to the editor, if the file is opened
+    @param editor reference to the editor, if the file is opened
         already (Editor object)
     @return Python version if file is Python3 (int)
     """
@@ -1800,49 +1800,38 @@
     return exe
 
 ###############################################################################
-# PySide2 utility functions below
+# PySide2/PySide6 utility functions below
 ###############################################################################
 
 
-def generatePySideToolPath(toolname, variant="2"):
+def generatePySideToolPath(toolname, variant=2):
     """
-    Module function to generate the executable path for a PySide2 tool.
+    Module function to generate the executable path for a PySide2/PySide6 tool.
     
     @param toolname base name of the tool
     @type str
-    @param variant indicator for the PySide variant (not used)
-    @type str
-    @return the PySide2 tool path with extension
+    @param variant indicator for the PySide variant
+    @type int or str
+    @return the PySide2/PySide6 tool path with extension
     @rtype str
     """
-    if variant == 1:
-        # no PySide support anymore
-        return ""
-    
     if isWindowsPlatform():
         hasPyside = checkPyside(variant)
         if not hasPyside:
             return ""
         
-        venvName = Preferences.getDebugger("Python3VirtualEnv")
+        venvName = Preferences.getQt("PySide{0}VenvName".format(variant))
+        if not venvName:
+            venvName = Preferences.getDebugger("Python3VirtualEnv")
         interpreter = e5App().getObject(
             "VirtualEnvManager").getVirtualenvInterpreter(venvName)
+        if interpreter == "" or not isinpath(interpreter):
+            interpreter = sys.executable
         prefix = os.path.dirname(interpreter)
-        if toolname in ["pyside2-uic"]:
-            return os.path.join(prefix, "Scripts", toolname + '.exe')
-        else:
-            path = os.path.join(prefix, "Scripts", toolname + '.exe')
-            if os.path.exists(path):
-                return path
-            
-            # report it the old style
-            return os.path.join(
-                prefix, "Lib", "site-packages",
-                "PySide{0}".format(variant),
-                toolname + ".exe")
+        return os.path.join(prefix, "Scripts", toolname + '.exe')
     else:
         # step 1: check, if the user has configured a tools path
-        path = Preferences.getQt("PySide2ToolsDir")
+        path = Preferences.getQt("PySide{0}ToolsDir".format(variant))
         if path:
             return os.path.join(path, toolname)
         
@@ -1851,44 +1840,36 @@
         if os.path.exists(os.path.join(dirName, toolname)):
             return os.path.join(dirName, toolname)
         
-        # step 3: if it is not 'pyside2-uic' look in the package directory
-        if toolname == "pyside2-uic":
-            return toolname
-        else:
-            import distutils.sysconfig
-            return os.path.join(distutils.sysconfig.get_python_lib(True),
-                                "PySide2", toolname)
+        return toolname
 
 
-def checkPyside(variant="2"):
+def checkPyside(variant=2):
     """
-    Module function to check the presence of PySide2.
+    Module function to check the presence of PySide2/PySide6.
     
-    @param variant indicator for the PySide variant (not used)
-    @type str
-    @return flags indicating the presence of PySide2
+    @param variant indicator for the PySide variant
+    @type int or str
+    @return flags indicating the presence of PySide2/PySide6
     @rtype bool
     """
-    if variant == 1:
-        # no longer supported PySide
-        return [False, False]
-    
-    venvName = Preferences.getDebugger("Python3VirtualEnv")
+    venvName = Preferences.getQt("PySide{0}VenvName".format(variant))
+    if not venvName:
+        venvName = Preferences.getDebugger("Python3VirtualEnv")
     interpreter = e5App().getObject(
         "VirtualEnvManager").getVirtualenvInterpreter(venvName)
     if interpreter == "" or not isinpath(interpreter):
-        return False
-    else:
-        checker = os.path.join(
-            getConfig('ericDir'), "Utilities", "PySideImporter.py")
-        args = [checker, "-" + variant]
-        proc = QProcess()
-        proc.setProcessChannelMode(QProcess.MergedChannels)
-        proc.start(interpreter, args)
-        finished = proc.waitForFinished(30000)
-        if finished:
-            if proc.exitCode() == 0:
-                return True
+        interpreter = sys.executable
+    
+    checker = os.path.join(
+        getConfig('ericDir'), "Utilities", "PySideImporter.py")
+    args = [checker, "--variant={0}".format(variant)]
+    proc = QProcess()
+    proc.setProcessChannelMode(QProcess.MergedChannels)
+    proc.start(interpreter, args)
+    finished = proc.waitForFinished(30000)
+    if finished:
+        if proc.exitCode() == 0:
+            return True
     
     return False
 

eric ide

mercurial