Skip to content

Commit

Permalink
Fix reporting bytes vs unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Arellano committed Jul 30, 2018
1 parent 1726506 commit 691a79f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/python/pants/reporting/html_reporter.py
Expand Up @@ -317,7 +317,7 @@ def handle_output(self, workunit, label, s):
output_files[path] = f
else:
f = output_files[path]
f.write(self._htmlify_text(s).encode('utf-8'))
f.write(self._htmlify_text(s))
# We must flush in the same thread as the write.
f.flush()

Expand Down Expand Up @@ -454,7 +454,7 @@ def _overwrite(self, filename, func, force=False):

def _htmlify_text(self, s):
"""Make text HTML-friendly."""
colored = self._handle_ansi_color_codes(cgi.escape(s.decode('utf-8', 'replace')))
colored = self._handle_ansi_color_codes(cgi.escape(s))
return linkify(self._buildroot, colored, self._linkify_memo).replace('\n', '</br>')

_ANSI_COLOR_CODE_RE = re.compile(r'\033\[((?:\d|;)*)m')
Expand Down
24 changes: 12 additions & 12 deletions src/python/pants/reporting/plaintext_reporter.py
Expand Up @@ -133,11 +133,11 @@ def start_workunit(self, workunit):
# Start output on a new line.
tool_output_format = self._get_tool_output_format(workunit)
if tool_output_format == ToolOutputFormat.INDENT:
self.emit(self._prefix(workunit, b'\n'))
self.emit(self._prefix(workunit, '\n'))
elif tool_output_format == ToolOutputFormat.UNINDENTED:
self.emit(b'\n')
self.emit('\n')
elif label_format == LabelFormat.DOT:
self.emit(b'.')
self.emit('.')

self.flush()

Expand All @@ -151,7 +151,7 @@ def end_workunit(self, workunit):
if self._get_label_format(workunit) != LabelFormat.FULL:
self._emit_indented_workunit_label(workunit)
for name, outbuf in workunit.outputs().items():
self.emit(self._prefix(workunit, b'\n==== {} ====\n'.format(name)))
self.emit(self._prefix(workunit, '\n==== {} ====\n'.format(name)))
self.emit(self._prefix(workunit, outbuf.read_from(0)))
self.flush()

Expand All @@ -163,7 +163,7 @@ def do_handle_log(self, workunit, level, *msg_elements):
# If the element is a (msg, detail) pair, we ignore the detail. There's no
# useful way to display it on the console.
elements = [e if isinstance(e, six.string_types) else e[0] for e in msg_elements]
msg = b'\n' + b''.join(elements)
msg = '\n' + ''.join(elements)
if self.use_color_for_workunit(workunit, self.settings.color):
msg = self._COLOR_BY_LEVEL.get(level, lambda x: x)(msg)

Expand Down Expand Up @@ -216,7 +216,7 @@ def _get_tool_output_format(self, workunit):
return ToolOutputFormat.SUPPRESS

def _emit_indented_workunit_label(self, workunit):
self.emit(b'\n{} {} {}[{}]'.format(
self.emit('\n{} {} {}[{}]'.format(
workunit.start_time_string,
workunit.start_delta_string,
self._indent(workunit),
Expand All @@ -229,23 +229,23 @@ def _show_output(self, workunit):
return not tool_output_format == ToolOutputFormat.SUPPRESS

def _format_aggregated_timings(self, aggregated_timings):
return b'\n'.join([b'{timing:.3f} {label}'.format(**x) for x in aggregated_timings.get_all()])
return '\n'.join(['{timing:.3f} {label}'.format(**x) for x in aggregated_timings.get_all()])

def _format_artifact_cache_stats(self, artifact_cache_stats):
stats = artifact_cache_stats.get_all()
return b'No artifact cache reads.' if not stats else \
b'\n'.join([b'{cache_name} - Hits: {num_hits} Misses: {num_misses}'.format(**x)
return 'No artifact cache reads.' if not stats else \
'\n'.join(['{cache_name} - Hits: {num_hits} Misses: {num_misses}'.format(**x)
for x in stats])

def _indent(self, workunit):
return b' ' * (len(workunit.ancestors()) - 1)
return ' ' * (len(workunit.ancestors()) - 1)

_time_string_filler = b' ' * len('HH:MM:SS mm:ss ')
_time_string_filler = ' ' * len('HH:MM:SS mm:ss ')

def _prefix(self, workunit, s):
if self.settings.indent:
def replace(x, c):
return x.replace(c, c + PlainTextReporter._time_string_filler + self._indent(workunit))
return replace(replace(s, b'\r'), b'\n')
return replace(replace(s, '\r'), '\n')
else:
return PlainTextReporter._time_string_filler + s
18 changes: 9 additions & 9 deletions src/python/pants/reporting/plaintext_reporter_base.py
Expand Up @@ -11,27 +11,27 @@ class PlainTextReporterBase(Reporter):
"""Base class for plain-text reporting to stdout."""

def generate_epilog(self, settings):
ret = b''
ret = ''
if settings.timing:
ret += b'\nCumulative Timings\n==================\n{}\n'.format(
ret += '\nCumulative Timings\n==================\n{}\n'.format(
self._format_aggregated_timings(self.run_tracker.cumulative_timings)
)
ret += b'\nSelf Timings\n============\n{}\n'.format(
ret += '\nSelf Timings\n============\n{}\n'.format(
self._format_aggregated_timings(self.run_tracker.self_timings))

ret += b'\nCritical Path Timings\n=====================\n{}\n'.format(
ret += '\nCritical Path Timings\n=====================\n{}\n'.format(
self._format_aggregated_timings(self.run_tracker.get_critical_path_timings())
)
if settings.cache_stats:
ret += b'\nCache Stats\n===========\n{}\n'.format(
ret += '\nCache Stats\n===========\n{}\n'.format(
self._format_artifact_cache_stats(self.run_tracker.artifact_cache_stats))
ret += b'\n'
ret += '\n'
return ret

def _format_aggregated_timings(self, aggregated_timings):
return b'\n'.join([b'{timing:.3f} {label}'.format(**x) for x in aggregated_timings.get_all()])
return '\n'.join(['{timing:.3f} {label}'.format(**x) for x in aggregated_timings.get_all()])

def _format_artifact_cache_stats(self, artifact_cache_stats):
stats = artifact_cache_stats.get_all()
return b'No artifact cache reads.' if not stats else b'\n'.join(
[b'{cache_name} - Hits: {num_hits} Misses: {num_misses}'.format(**x) for x in stats])
return 'No artifact cache reads.' if not stats else '\n'.join(
['{cache_name} - Hits: {num_hits} Misses: {num_misses}'.format(**x) for x in stats])

0 comments on commit 691a79f

Please sign in to comment.