Utilities/__init__.py

changeset 6291
94e0e688dcad
parent 6289
f481df37413c
child 6292
e08a94e1ecdd
diff -r bf4624957d2d -r 94e0e688dcad Utilities/__init__.py
--- a/Utilities/__init__.py	Tue May 15 18:25:26 2018 +0200
+++ b/Utilities/__init__.py	Tue May 15 19:39:46 2018 +0200
@@ -1748,21 +1748,27 @@
     return exe
 
 ###############################################################################
-# PySide utility functions below
+# PySide/PySide2 utility functions below
 ###############################################################################
 
 
-def generatePySideToolPath(toolname):
+def generatePySideToolPath(toolname, variant="2"):
     """
-    Module function to generate the executable path for a PySide tool.
+    Module function to generate the executable path for a PySide/PySide2 tool.
     
-    @param toolname base name of the tool (string)
-    @return the PySide tool path with extension (string)
+    @param toolname base name of the tool
+    @type str
+    @param variant indicator for the PySide variant
+    @type str
+    @return the PySide/PySide2 tool path with extension
+    @rtype str
     """
+    assert variant in ("1", "2")
+    
     if isWindowsPlatform():
-        pysideInterpreter = checkPyside()
+        pysideInterpreters = checkPyside(variant)
         interpreter = sys.version_info[0] - 2
-        hasPyside = pysideInterpreter[interpreter]
+        hasPyside = pysideInterpreters[interpreter]
         # if it isn't the internal interpreter, it has to be the external one
         if not hasPyside:
             interpreter = not interpreter
@@ -1772,22 +1778,38 @@
         else:
             prefix = os.path.dirname(
                 Preferences.getDebugger("PythonInterpreter"))
-        if toolname == "pyside-uic":
+        # TODO: check this on Windows
+        if toolname in ["pyside-uic", "pyside2-uic"]:
             return os.path.join(prefix, "Scripts", toolname + '.exe')
         else:
-            return os.path.join(prefix, "Lib", "site-packages", "PySide",
-                                toolname + ".exe")
+            return os.path.join(
+                prefix, "Lib", "site-packages",
+                "PySide{0}".format("" if variant == "1" else variant),
+                toolname + ".exe")
     else:
-        return toolname
+        if variant == "1":
+            return toolname
+        
+        elif toolname == "pyside2-uic":
+            return toolname
+        else:
+            import distutils.sysconfig
+            return os.path.join(distutils.sysconfig.get_python_lib(True),
+                                "PySide2", toolname)
 
 
-def checkPyside():
+def checkPyside(variant="2"):
     """
-    Module function to check the presence of PySide.
+    Module function to check the presence of PySide/PySide2.
     
-    @return list of two flags indicating the presence of PySide for Python2
-        and PySide for Python3 (boolean, boolean)
+    @param variant indicator for the PySide variant
+    @type str
+    @return list of two flags indicating the presence of PySide/PySide2 for
+        Python2 and PySide/PySide2 for Python3
+    @rtype tuple of (bool, bool)
     """
+    assert variant in ("1", "2")
+    
     pysideInformation = []
     for interpreterName in ["PythonInterpreter", "Python3Interpreter"]:
         interpreter = Preferences.getDebugger(interpreterName)
@@ -1797,7 +1819,7 @@
             hasPyside = False
             checker = os.path.join(getConfig('ericDir'),
                                    "Utilities", "PySideImporter.py")
-            args = [checker]
+            args = [checker, "-" + variant]
             proc = QProcess()
             proc.setProcessChannelMode(QProcess.MergedChannels)
             proc.start(interpreter, args)

eric ide

mercurial