Commit c9e6cecd authored by Tarek Ziadé's avatar Tarek Ziadé

Fixed #6438: distutils.cygwinccompiler.get_versions was trying to use a re...

Fixed #6438: distutils.cygwinccompiler.get_versions was trying to use a re string pattern on a bytes
parent 1bbb19aa
...@@ -359,7 +359,7 @@ def check_config_h(): ...@@ -359,7 +359,7 @@ def check_config_h():
return (CONFIG_H_UNCERTAIN, return (CONFIG_H_UNCERTAIN,
"couldn't read '%s': %s" % (fn, exc.strerror)) "couldn't read '%s': %s" % (fn, exc.strerror))
RE_VERSION = re.compile('(\d+\.\d+(\.\d+)*)') RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)')
def _find_exe_version(cmd): def _find_exe_version(cmd):
"""Find the version of an executable by running `cmd` in the shell. """Find the version of an executable by running `cmd` in the shell.
...@@ -378,7 +378,9 @@ def _find_exe_version(cmd): ...@@ -378,7 +378,9 @@ def _find_exe_version(cmd):
result = RE_VERSION.search(out_string) result = RE_VERSION.search(out_string)
if result is None: if result is None:
return None return None
return LooseVersion(result.group(1)) # LooseVersion works with strings
# so we need to decode our bytes
return LooseVersion(result.group(1).decode())
def get_versions(): def get_versions():
""" Try to find out the versions of gcc, ld and dllwrap. """ Try to find out the versions of gcc, ld and dllwrap.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import unittest import unittest
import sys import sys
import os import os
from io import StringIO from io import BytesIO
import subprocess import subprocess
from distutils import cygwinccompiler from distutils import cygwinccompiler
...@@ -19,7 +19,8 @@ class FakePopen(object): ...@@ -19,7 +19,8 @@ class FakePopen(object):
self.cmd = cmd.split()[0] self.cmd = cmd.split()[0]
exes = self.test_class._exes exes = self.test_class._exes
if self.cmd in exes: if self.cmd in exes:
self.stdout = StringIO(exes[self.cmd]) # issue #6438 in Python 3.x, Popen returns bytes
self.stdout = BytesIO(exes[self.cmd])
else: else:
self.stdout = os.popen(cmd, 'r') self.stdout = os.popen(cmd, 'r')
...@@ -87,30 +88,30 @@ class CygwinCCompilerTestCase(support.TempdirManager, ...@@ -87,30 +88,30 @@ class CygwinCCompilerTestCase(support.TempdirManager,
self.assertEquals(get_versions(), (None, None, None)) self.assertEquals(get_versions(), (None, None, None))
# Let's fake we have 'gcc' and it returns '3.4.5' # Let's fake we have 'gcc' and it returns '3.4.5'
self._exes['gcc'] = 'gcc (GCC) 3.4.5 (mingw special)\nFSF' self._exes['gcc'] = b'gcc (GCC) 3.4.5 (mingw special)\nFSF'
res = get_versions() res = get_versions()
self.assertEquals(str(res[0]), '3.4.5') self.assertEquals(str(res[0]), '3.4.5')
# and let's see what happens when the version # and let's see what happens when the version
# doesn't match the regular expression # doesn't match the regular expression
# (\d+\.\d+(\.\d+)*) # (\d+\.\d+(\.\d+)*)
self._exes['gcc'] = 'very strange output' self._exes['gcc'] = b'very strange output'
res = get_versions() res = get_versions()
self.assertEquals(res[0], None) self.assertEquals(res[0], None)
# same thing for ld # same thing for ld
self._exes['ld'] = 'GNU ld version 2.17.50 20060824' self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
res = get_versions() res = get_versions()
self.assertEquals(str(res[1]), '2.17.50') self.assertEquals(str(res[1]), '2.17.50')
self._exes['ld'] = '@(#)PROGRAM:ld PROJECT:ld64-77' self._exes['ld'] = b'@(#)PROGRAM:ld PROJECT:ld64-77'
res = get_versions() res = get_versions()
self.assertEquals(res[1], None) self.assertEquals(res[1], None)
# and dllwrap # and dllwrap
self._exes['dllwrap'] = 'GNU dllwrap 2.17.50 20060824\nFSF' self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF'
res = get_versions() res = get_versions()
self.assertEquals(str(res[2]), '2.17.50') self.assertEquals(str(res[2]), '2.17.50')
self._exes['dllwrap'] = 'Cheese Wrap' self._exes['dllwrap'] = b'Cheese Wrap'
res = get_versions() res = get_versions()
self.assertEquals(res[2], None) self.assertEquals(res[2], None)
......
...@@ -132,6 +132,10 @@ Core and Builtins ...@@ -132,6 +132,10 @@ Core and Builtins
Library Library
------- -------
- Issue #6438: Fixed distutils.cygwinccompiler.get_versions : the regular
expression string pattern was trying to match against a bytes returned by
Popen. Tested under win32 to build the py-postgresql project.
- Issue #6258: Support AMD64 in bdist_msi. - Issue #6258: Support AMD64 in bdist_msi.
- Issue #6195: fixed doctest to no longer try to read 'source' data from - Issue #6195: fixed doctest to no longer try to read 'source' data from
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment