CondaInterface/__init__.py

branch
conda
changeset 6681
9c1513b488ef
parent 6677
6299d69a218a
child 6697
2f5c951bdf14
--- a/CondaInterface/__init__.py	Mon Jan 28 20:03:25 2019 +0100
+++ b/CondaInterface/__init__.py	Tue Jan 29 19:48:13 2019 +0100
@@ -6,3 +6,76 @@
 """
 Package implementing the various conda related modules.
 """
+
+from __future__ import unicode_literals
+try:
+    str = unicode
+except NameError:
+    pass
+
+import re
+
+from PyQt5.QtCore import QCoreApplication, QProcess
+
+import Preferences
+
+__CondaVersion = tuple()
+__CondaVersionStr = ""
+
+
+def __determineCondaVersion():
+    """
+    Private module function to get the conda version via the conda executable.
+    """
+    global __CondaVersionStr, __CondaVersion
+    
+    if not __CondaVersion:
+        exe = Preferences.getConda("CondaExecutable")
+        if not exe:
+            exe = "conda"
+        
+        versionRe = re.compile(r"""^conda.*?(\d+\.\d+\.\d+).*""")
+        
+        proc = QProcess()
+        proc.start(exe, ["--version"])
+        if not proc.waitForStarted(15000):
+            __CondaVersionStr = QCoreApplication.translate(
+                "CondaInterface",
+                '<conda not found or not configured.>')
+        else:
+            proc.waitForFinished(15000)
+            output = str(proc.readAllStandardOutput(),
+                         Preferences.getSystem("IOEncoding"),
+                         'replace').strip()
+            match = re.match(versionRe, output)
+            if match:
+                __CondaVersionStr = match.group(1)
+                __CondaVersion = tuple(
+                    int(i) for i in __CondaVersionStr.split(".")
+                )
+            else:
+                __CondaVersionStr = QCoreApplication.translate(
+                    "CondaInterface",
+                    '<conda returned strange version info.')
+
+
+def condaVersion():
+    """
+    Module function to get the conda version.
+    
+    @return tuple containing the conda version
+    @rtype tuple of (int, int, int)
+    """
+    __determineCondaVersion()
+    return __CondaVersion
+
+
+def condaVersionStr():
+    """
+    Module function to get the conda version as a string.
+    
+    @return conda version as a string
+    @rtype str
+    """
+    __determineCondaVersion()
+    return __CondaVersionStr

eric ide

mercurial