Merged revisions 74024 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74024 | tarek.ziade | 2009-07-16 17:35:45 +0200 (Thu, 16 Jul 2009) | 1 line

  #6466 refactored distutils duplicate get_versions() functions (used to get gcc/ld/dllwrap versions)
........
diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py
index 8504371..d9f4a43 100644
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -50,16 +50,15 @@
 import os
 import sys
 import copy
-from subprocess import Popen, PIPE
 import re
+from warnings import warn
 
 from distutils.ccompiler import gen_preprocess_options, gen_lib_options
 from distutils.unixccompiler import UnixCCompiler
 from distutils.file_util import write_file
 from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
 from distutils import log
-from distutils.version import LooseVersion
-from distutils.spawn import find_executable
+from distutils.util import get_compiler_versions
 
 def get_msvcr():
     """Include the appropriate MSVC runtime library if Python was built
@@ -110,7 +109,7 @@
                 % details)
 
         self.gcc_version, self.ld_version, self.dllwrap_version = \
-            get_versions()
+            get_compiler_versions()
         self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
                          (self.gcc_version,
                           self.ld_version,
@@ -359,33 +358,27 @@
         return (CONFIG_H_UNCERTAIN,
                 "couldn't read '%s': %s" % (fn, exc.strerror))
 
-RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)')
+class _Deprecated_SRE_Pattern(object):
+    def __init__(self, pattern):
+        self.pattern = pattern
 
-def _find_exe_version(cmd):
-    """Find the version of an executable by running `cmd` in the shell.
+    def __getattr__(self, name):
+        if name in ('findall', 'finditer', 'match', 'scanner', 'search',
+                    'split', 'sub', 'subn'):
+            warn("'distutils.cygwinccompiler.RE_VERSION' is deprecated "
+                 "and will be removed in the next version", DeprecationWarning)
+        return getattr(self.pattern, name)
 
-    If the command is not found, or the output does not match
-    `RE_VERSION`, returns None.
-    """
-    executable = cmd.split()[0]
-    if find_executable(executable) is None:
-        return None
-    out = Popen(cmd, shell=True, stdout=PIPE).stdout
-    try:
-        out_string = out.read()
-    finally:
-        out.close()
-    result = RE_VERSION.search(out_string)
-    if result is None:
-        return None
-    # LooseVersion works with strings
-    # so we need to decode our bytes
-    return LooseVersion(result.group(1).decode())
+
+RE_VERSION = _Deprecated_SRE_Pattern(re.compile('(\d+\.\d+(\.\d+)*)'))
 
 def get_versions():
     """ Try to find out the versions of gcc, ld and dllwrap.
 
     If not possible it returns None for it.
     """
-    commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
-    return tuple([_find_exe_version(cmd) for cmd in commands])
+    warn("'distutils.cygwinccompiler.get_versions' is deprecated "
+         "use 'distutils.util.get_compiler_versions' instead",
+         DeprecationWarning)
+
+    return get_compiler_versions()