CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package. conda

Tue, 29 Jan 2019 19:48:13 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 29 Jan 2019 19:48:13 +0100
branch
conda
changeset 6681
9c1513b488ef
parent 6679
c5f7b2e9a06d
child 6682
4326e802ff56

CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.

CondaInterface/__init__.py file | annotate | diff | comparison | revisions
VirtualEnv/VirtualenvConfigurationDialog.py file | annotate | diff | comparison | revisions
--- 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
--- a/VirtualEnv/VirtualenvConfigurationDialog.py	Mon Jan 28 20:03:25 2019 +0100
+++ b/VirtualEnv/VirtualenvConfigurationDialog.py	Tue Jan 29 19:48:13 2019 +0100
@@ -28,6 +28,8 @@
 import Preferences
 import Utilities
 
+import CondaInterface
+
 
 class VirtualenvConfigurationDialog(QDialog, Ui_VirtualenvConfigurationDialog):
     """
@@ -98,6 +100,9 @@
         elif self.__condaFound:
             self.condaButton.setChecked(True)
         
+        self.condaInsecureCheckBox.setEnabled(
+            CondaInterface.condaVersion() >= (4, 3, 18))
+        
         msh = self.minimumSizeHint()
         self.resize(max(self.width(), msh.width()), msh.height())
     
@@ -145,7 +150,8 @@
         enable = not self.condaCloneGroup.isChecked()
         self.condaPackagesEdit.setEnabled(enable)
         self.condaPythonEdit.setEnabled(enable)
-        self.condaInsecureCheckBox.setEnabled(enable)
+        self.condaInsecureCheckBox.setEnabled(
+            enable and CondaInterface.condaVersion() >= (4, 3, 18))
         self.condaDryrunCheckBox.setEnabled(enable)
         
         # select page
@@ -367,29 +373,9 @@
         Private method to determine the conda version and set the respective
         label.
         """
-        exe = Preferences.getConda("CondaExecutable")
-        if not exe:
-            exe = "conda"
-        
-        proc = QProcess()
-        proc.start(exe, ["--version"])
-        if not proc.waitForStarted(5000):
-            self.__condaFound = False
-            version = self.tr('<conda not found or not configured.>')
-        else:
-            proc.waitForFinished(5000)
-            output = str(proc.readAllStandardOutput(),
-                         Preferences.getSystem("IOEncoding"),
-                         'replace').strip()
-            match = re.match(self.__versionRe, output)
-            if match:
-                self.__condaFound = True
-                version = match.group(1)
-            else:
-                self.__condaFound = False
-                version = self.tr('<conda returned strange version info.')
+        self.__condaFound = bool(CondaInterface.condaVersion())
         self.condaButton.setText(self.tr(
-            "conda Version: {0}".format(version)))
+            "conda Version: {0}".format(CondaInterface.condaVersionStr())))
         self.condaButton.setEnabled(self.__condaFound)
         if not self.__condaFound:
             self.condaButton.setChecked(False)

eric ide

mercurial