Handle unicode correctly when detecting compiler version

This commit is contained in:
Massimiliano Culpo 2018-12-25 10:12:55 +01:00
parent a061c4a7ad
commit 16f402a6c0
No known key found for this signature in database
GPG Key ID: D1ADB1014FF1118C
5 changed files with 28 additions and 16 deletions

View File

@ -3,7 +3,8 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from datetime import datetime
from __future__ import unicode_literals
import fcntl
import os
import struct
@ -11,6 +12,8 @@
import termios
import textwrap
import traceback
import six
from datetime import datetime
from six import StringIO
from six.moves import input
@ -155,7 +158,7 @@ def msg(message, *args, **kwargs):
cwrite("@*b{%s==>} %s%s" % (
st_text, get_timestamp(), cescape(message)))
for arg in args:
print(indent + str(arg))
print(indent + six.text_type(arg))
def info(message, *args, **kwargs):
@ -172,17 +175,17 @@ def info(message, *args, **kwargs):
if _stacktrace:
st_text = process_stacktrace(st_countback)
cprint("@%s{%s==>} %s%s" % (
format, st_text, get_timestamp(), cescape(str(message))),
stream=stream)
format, st_text, get_timestamp(), cescape(six.text_type(message))
), stream=stream)
for arg in args:
if wrap:
lines = textwrap.wrap(
str(arg), initial_indent=indent, subsequent_indent=indent,
break_long_words=break_long_words)
six.text_type(arg), initial_indent=indent,
subsequent_indent=indent, break_long_words=break_long_words)
for line in lines:
stream.write(line + '\n')
else:
stream.write(indent + str(arg) + '\n')
stream.write(indent + six.text_type(arg) + '\n')
def verbose(message, *args, **kwargs):
@ -204,7 +207,7 @@ def error(message, *args, **kwargs):
kwargs.setdefault('format', '*r')
kwargs.setdefault('stream', sys.stderr)
info("Error: " + str(message), *args, **kwargs)
info("Error: " + six.text_type(message), *args, **kwargs)
def warn(message, *args, **kwargs):
@ -213,7 +216,7 @@ def warn(message, *args, **kwargs):
kwargs.setdefault('format', '*Y')
kwargs.setdefault('stream', sys.stderr)
info("Warning: " + str(message), *args, **kwargs)
info("Warning: " + six.text_type(message), *args, **kwargs)
def die(message, *args, **kwargs):
@ -237,7 +240,7 @@ def get_number(prompt, **kwargs):
while number is None:
msg(prompt, newline=False)
ans = input()
if ans == str(abort):
if ans == six.text_type(abort):
return None
if ans:
@ -303,7 +306,7 @@ def hline(label=None, **kwargs):
cols -= 2
cols = min(max_width, cols)
label = str(label)
label = six.text_type(label)
prefix = char * 2 + " "
suffix = " " + (cols - len(prefix) - clen(label)) * char

View File

@ -6,7 +6,7 @@
"""
Routines for printing columnar output. See ``colify()`` for more information.
"""
from __future__ import division
from __future__ import division, unicode_literals
import os
import sys

View File

@ -59,10 +59,14 @@
To output an @, use '@@'. To output a } inside braces, use '}}'.
"""
from __future__ import unicode_literals
import re
import sys
from contextlib import contextmanager
import six
class ColorParseError(Exception):
"""Raised when a color format fails to parse."""
@ -244,7 +248,7 @@ def cescape(string):
Returns:
(str): the string with color codes escaped
"""
string = str(string)
string = six.text_type(string)
string = string.replace('@', '@@')
string = string.replace('}', '}}')
return string

View File

@ -5,6 +5,8 @@
"""Utility classes for logging the output of blocks of code.
"""
from __future__ import unicode_literals
import multiprocessing
import os
import re

View File

@ -10,6 +10,7 @@
import functools_backport
import platform as py_platform
import six
import llnl.util.lang
import llnl.util.multiproc
@ -366,16 +367,18 @@ def detect_version_command(callback, path):
"""
try:
version = callback(path)
if version and str(version).strip():
if version and six.text_type(version).strip():
return (version, path), None
error = "Couldn't get version for compiler {0}".format(path)
except spack.util.executable.ProcessError as e:
error = "Couldn't get version for compiler {0}\n".format(path) + str(e)
error = "Couldn't get version for compiler {0}\n".format(path) + \
six.text_type(e)
except Exception as e:
# Catching "Exception" here is fine because it just
# means something went wrong running a candidate executable.
error = "Error while executing candidate compiler {0}" \
"\n{1}: {2}".format(path, e.__class__.__name__, str(e))
"\n{1}: {2}".format(path, e.__class__.__name__,
six.text_type(e))
return None, error