提交 a02bc80d authored 作者: abalkin's avatar abalkin 提交者: Alexander Belopolsky

#1281: Convert to unicode early under Python 3.x. Thanks @delallea for the suggestion.

上级 2d2a8f9f
...@@ -30,7 +30,12 @@ if PY3: ...@@ -30,7 +30,12 @@ if PY3:
from itertools import combinations, product from itertools import combinations, product
from sys import maxsize from sys import maxsize
def decode(x):
return x.decode()
def decode_iter(itr):
for x in itr:
yield x.decode()
else: else:
from operator import div as operator_div from operator import div as operator_div
...@@ -44,3 +49,9 @@ else: ...@@ -44,3 +49,9 @@ else:
from theano.compat.python2x import all, any, partial, defaultdict, deque from theano.compat.python2x import all, any, partial, defaultdict, deque
from theano.compat.python2x import combinations, product, maxsize from theano.compat.python2x import combinations, product, maxsize
from theano.compat.python2x import DictMixin, OrderedDict from theano.compat.python2x import DictMixin, OrderedDict
def decode(x):
return x
def decode_iter(x):
return x
...@@ -19,7 +19,7 @@ import distutils.sysconfig ...@@ -19,7 +19,7 @@ import distutils.sysconfig
import numpy.distutils # TODO: TensorType should handle this import numpy.distutils # TODO: TensorType should handle this
import theano import theano
from theano.compat import PY3, b, next from theano.compat import PY3, next, decode, decode_iter
from theano.gof.utils import flatten from theano.gof.utils import flatten
from theano.configparser import config from theano.configparser import config
from theano.gof.cc import hash_from_code from theano.gof.cc import hash_from_code
...@@ -1543,16 +1543,16 @@ class GCC_compiler(object): ...@@ -1543,16 +1543,16 @@ class GCC_compiler(object):
if p.returncode != 0: if p.returncode != 0:
return None return None
stdout = p.stdout.readlines() stdout = decode_iter(p.stdout.readlines())
stderr = p.stderr.readlines() stderr = decode_iter(p.stderr.readlines())
lines = [] lines = []
if parse: if parse:
for line in stdout + stderr: for line in stdout + stderr:
if b("COLLECT_GCC_OPTIONS=") in line: if "COLLECT_GCC_OPTIONS=" in line:
continue continue
elif b("-march=") in line and b("-march=native") not in line: elif "-march=" in line and "-march=native" not in line:
lines.append(line.strip()) lines.append(line.strip())
elif b("-mtune=") in line and b("-march=native") not in line: elif "-mtune=" in line and "-march=native" not in line:
lines.append(line.strip()) lines.append(line.strip())
lines = list(set(lines)) # to remove duplicate lines = list(set(lines)) # to remove duplicate
else: else:
...@@ -1835,7 +1835,7 @@ class GCC_compiler(object): ...@@ -1835,7 +1835,7 @@ class GCC_compiler(object):
try: try:
p = call_subprocess_Popen(cmd, stderr=subprocess.PIPE) p = call_subprocess_Popen(cmd, stderr=subprocess.PIPE)
compile_stderr = p.communicate()[1] compile_stderr = decode(p.communicate()[1])
except Exception: except Exception:
# An exception can occur e.g. if `g++` is not found. # An exception can occur e.g. if `g++` is not found.
print_command_line_error() print_command_line_error()
...@@ -1856,7 +1856,7 @@ class GCC_compiler(object): ...@@ -1856,7 +1856,7 @@ class GCC_compiler(object):
# prints the exception, having '\n' in the text makes it more # prints the exception, having '\n' in the text makes it more
# difficult to read. # difficult to read.
raise Exception('Compilation failed (return status=%s): %s' % raise Exception('Compilation failed (return status=%s): %s' %
(status, compile_stderr.replace(b('\n'), b('. ')))) (status, compile_stderr.replace('\n', '. ')))
elif config.cmodule.compilation_warning and compile_stderr: elif config.cmodule.compilation_warning and compile_stderr:
# Print errors just below the command line. # Print errors just below the command line.
print compile_stderr print compile_stderr
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论