Skip to content

Commit

Permalink
Popen.communicate() returns bytes-encoded stdout on Python 2 and 3.
Browse files Browse the repository at this point in the history
We want to make sure that we are dealing with str.
  • Loading branch information
rodrigc authored and tardyp committed Feb 25, 2017
1 parent ed090b8 commit 17e4adc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/buildbot_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import distutils.cmd
import os
import subprocess
import sys
from distutils.version import LooseVersion

import setuptools.command.build_py
Expand All @@ -42,7 +43,10 @@ def listdir(path):
def check_output(cmd):
"""Version of check_output which does not throw error"""
popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
return popen.communicate()[0].strip()
out = popen.communicate()[0].strip()
if not isinstance(out, str):
out = out.decode(sys.stdout.encoding)
return out


def getVersion(init_file):
Expand Down Expand Up @@ -73,7 +77,9 @@ def getVersion(init_file):
out = p.communicate()[0]

if (not p.returncode) and out:
v = VERSION_MATCH.search(out.decode('utf-8'))
if not isinstance(out, str):
out = out.decode(sys.stdout.encoding)
v = VERSION_MATCH.search(out)
if v is not None:
return v.group(1)
except OSError:
Expand Down

0 comments on commit 17e4adc

Please sign in to comment.