Commit abe2d2cd authored by Greg Wilson's avatar Greg Wilson
Browse files

Merge branch '2016-06' of github.com:swcarpentry/styles into gh-pages

parents c0b232d7 14cce035
......@@ -62,26 +62,39 @@ class Reporter(object):
def add(self, location, fmt, *args):
"""Append error unilaterally."""
if isinstance(location, type(None)):
coords = ''
elif isinstance(location, str):
coords = '{0}: '.format(location)
elif isinstance(location, tuple):
filename, line_number = location
coords = '{0}:{1}: '.format(*location)
else:
assert False, 'Unknown location "{0}"/{1}'.format(location, type(location))
self.messages.append(coords + fmt.format(*args))
self.messages.append((location, fmt.format(*args)))
def report(self, stream=sys.stdout):
"""Report all messages."""
"""Report all messages in order."""
if not self.messages:
return
for m in sorted(self.messages):
print(m, file=stream)
def pretty(item):
location, message = item
if isinstance(location, type(None)):
return message
elif isinstance(location, str):
return location + ': ' + message
elif isinstance(location, tuple):
return '{0}:{1}: '.format(*location) + message
else:
assert False, 'Unknown item "{0}"'.format(item)
def key(item):
location, message = item
if isinstance(location, type(None)):
return ('', -1, message)
elif isinstance(location, str):
return (location, -1, message)
elif isinstance(location, tuple):
return (location[0], location[1], message)
else:
assert False, 'Unknown item "{0}"'.format(item)
for m in sorted(self.messages, key=key):
print(pretty(m), file=stream)
def read_markdown(parser, path):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment