Skip to content

Commit

Permalink
Custom eprint() is no more necessary [fix #211]
Browse files Browse the repository at this point in the history
In Python 3 the default encoding is utf-8 so it seems we don't
have to explicitly encode the output when tty is not connected.
  • Loading branch information
psss committed Dec 2, 2019
1 parent 485cabd commit a0f514e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion did/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def main(arguments=None):
users = [did.base.User(email=email) for email in emails]

# Print header and prepare team stats object for data merging
utils.eprint(header)
print(header)
team_stats = UserStats(options=options)
if options.merge:
utils.header("Total Report")
Expand Down
11 changes: 2 additions & 9 deletions did/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,9 @@ def load_components(*paths, **kwargs):
return num_loaded


def eprint(text):
""" Print (optionaly encoded) text """
# When there's no terminal we need to explicitly encode strings.
# Otherwise this would cause problems when redirecting output.
print((text if sys.stdout.isatty() else text.encode("utf8")))


def header(text):
""" Show text as a header. """
eprint("\n{0}\n {1}\n{0}".format(79 * "~", text))
print("\n{0}\n {1}\n{0}".format(79 * "~", text))


def shorted(text, width=79):
Expand All @@ -190,7 +183,7 @@ def item(text, level=0, options=None):
indent = 1
# Shorten the text if necessary to match the desired maximum width
width = options.width - indent - 2 if options.width else 333
eprint("{0}* {1}".format(" " * indent, shorted(str(text), width)))
print("{0}* {1}".format(" " * indent, shorted(str(text), width)))


def pluralize(singular=None):
Expand Down
5 changes: 0 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ def test_ascii():
# Logging
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

def test_eprint():
from did.utils import eprint
assert eprint


def test_info():
from did.utils import info
assert info
Expand Down

0 comments on commit a0f514e

Please sign in to comment.