Skip to content

Commit c9e6cec

Browse files
author
Tarek Ziadé
committed
Fixed python#6438: distutils.cygwinccompiler.get_versions was trying to use a re string pattern on a bytes
1 parent 1bbb19a commit c9e6cec

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

Lib/distutils/cygwinccompiler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def check_config_h():
359359
return (CONFIG_H_UNCERTAIN,
360360
"couldn't read '%s': %s" % (fn, exc.strerror))
361361

362-
RE_VERSION = re.compile('(\d+\.\d+(\.\d+)*)')
362+
RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)')
363363

364364
def _find_exe_version(cmd):
365365
"""Find the version of an executable by running `cmd` in the shell.
@@ -378,7 +378,9 @@ def _find_exe_version(cmd):
378378
result = RE_VERSION.search(out_string)
379379
if result is None:
380380
return None
381-
return LooseVersion(result.group(1))
381+
# LooseVersion works with strings
382+
# so we need to decode our bytes
383+
return LooseVersion(result.group(1).decode())
382384

383385
def get_versions():
384386
""" Try to find out the versions of gcc, ld and dllwrap.

Lib/distutils/tests/test_cygwinccompiler.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import unittest
33
import sys
44
import os
5-
from io import StringIO
5+
from io import BytesIO
66
import subprocess
77

88
from distutils import cygwinccompiler
@@ -19,7 +19,8 @@ def __init__(self, cmd, shell, stdout):
1919
self.cmd = cmd.split()[0]
2020
exes = self.test_class._exes
2121
if self.cmd in exes:
22-
self.stdout = StringIO(exes[self.cmd])
22+
# issue #6438 in Python 3.x, Popen returns bytes
23+
self.stdout = BytesIO(exes[self.cmd])
2324
else:
2425
self.stdout = os.popen(cmd, 'r')
2526

@@ -87,30 +88,30 @@ def test_get_versions(self):
8788
self.assertEquals(get_versions(), (None, None, None))
8889

8990
# Let's fake we have 'gcc' and it returns '3.4.5'
90-
self._exes['gcc'] = 'gcc (GCC) 3.4.5 (mingw special)\nFSF'
91+
self._exes['gcc'] = b'gcc (GCC) 3.4.5 (mingw special)\nFSF'
9192
res = get_versions()
9293
self.assertEquals(str(res[0]), '3.4.5')
9394

9495
# and let's see what happens when the version
9596
# doesn't match the regular expression
9697
# (\d+\.\d+(\.\d+)*)
97-
self._exes['gcc'] = 'very strange output'
98+
self._exes['gcc'] = b'very strange output'
9899
res = get_versions()
99100
self.assertEquals(res[0], None)
100101

101102
# same thing for ld
102-
self._exes['ld'] = 'GNU ld version 2.17.50 20060824'
103+
self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
103104
res = get_versions()
104105
self.assertEquals(str(res[1]), '2.17.50')
105-
self._exes['ld'] = '@(#)PROGRAM:ld PROJECT:ld64-77'
106+
self._exes['ld'] = b'@(#)PROGRAM:ld PROJECT:ld64-77'
106107
res = get_versions()
107108
self.assertEquals(res[1], None)
108109

109110
# and dllwrap
110-
self._exes['dllwrap'] = 'GNU dllwrap 2.17.50 20060824\nFSF'
111+
self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF'
111112
res = get_versions()
112113
self.assertEquals(str(res[2]), '2.17.50')
113-
self._exes['dllwrap'] = 'Cheese Wrap'
114+
self._exes['dllwrap'] = b'Cheese Wrap'
114115
res = get_versions()
115116
self.assertEquals(res[2], None)
116117

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ Core and Builtins
132132
Library
133133
-------
134134

135+
- Issue #6438: Fixed distutils.cygwinccompiler.get_versions : the regular
136+
expression string pattern was trying to match against a bytes returned by
137+
Popen. Tested under win32 to build the py-postgresql project.
138+
135139
- Issue #6258: Support AMD64 in bdist_msi.
136140

137141
- Issue #6195: fixed doctest to no longer try to read 'source' data from

0 commit comments

Comments
 (0)