Utilities/__init__.py

changeset 6544
51996454f89f
parent 6495
6e73d31af3af
child 6545
f669c4c0d39b
--- a/Utilities/__init__.py	Sun Oct 07 18:18:13 2018 +0200
+++ b/Utilities/__init__.py	Sat Oct 13 14:08:21 2018 +0200
@@ -1957,6 +1957,42 @@
     else:
         return bool(dataStr)
 
+def getSysPath(interpreter):
+    """
+    Module function to get the Python path (sys.path) of a specific
+    interpreter.
+    
+    @param interpreter Python interpreter executable to get sys.path for
+    @type str
+    @return list containing sys.path of the interpreter; an empty list
+        is returned, if the interpreter is the one used to run eric itself
+    @rtype list of str
+    """
+    import json
+    
+    sysPath = []
+    
+    getSysPath = os.path.join(
+        getConfig('ericDir'), "Utilities", "GetSysPath.py")
+    args = [getSysPath]
+    proc = QProcess()
+    proc.setProcessChannelMode(QProcess.MergedChannels)
+    proc.start(interpreter, args)
+    finished = proc.waitForFinished(30000)
+    if finished:
+        if proc.exitCode() == 0:
+            text = proc.readAllStandardOutput()
+            sysPathResult = str(text, "utf-8", "replace").strip()
+            try:
+                sysPath = json.loads(sysPathResult)
+                if "" in sysPath:
+                    sysPath.remove("")
+            except (TypeError, ValueError):
+                # ignore faulty results and return empty list
+                pass
+    
+    return sysPath
+
 ###############################################################################
 # posix compatibility functions below
 ###############################################################################

eric ide

mercurial