Skip to content

Commit

Permalink
f-string colorama formatting in helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
callmecampos committed Jun 11, 2020
1 parent bace866 commit 05c78a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -11,6 +11,7 @@ deps =
portend
pytest-services
munch
colorama
passenv =
PYTEST_ADDOPTS
commands =
Expand Down
26 changes: 14 additions & 12 deletions twine/__main__.py
Expand Up @@ -27,21 +27,23 @@ def main() -> Any:
try:
return cli.dispatch(sys.argv[1:])
except (exceptions.TwineException, requests.HTTPError) as exc:
parser = argparse.ArgumentParser()
parser.add_argument(
"--no-color", default=False, required=False, action="store_true",
)
return _format_error(f"{exc.__class__.__name__}: {exc.args[0]}")

args, _ = parser.parse_known_args(sys.argv[1:])

pre_style, post_style = "", ""
if not args.no_color:
colorama.init()
pre_style, post_style = colorama.Fore.RED, colorama.Style.RESET_ALL
def _format_error(err):
parser = argparse.ArgumentParser()
parser.add_argument(
"--no-color", default=False, required=False, action="store_true",
)

return "{}{}: {}{}".format(
pre_style, exc.__class__.__name__, exc.args[0], post_style,
)
args, _ = parser.parse_known_args(sys.argv[1:])

pre_style, post_style = "", ""
if not args.no_color:
colorama.init()
pre_style, post_style = colorama.Fore.RED, colorama.Style.RESET_ALL

return f"{pre_style}{err}{post_style}"


if __name__ == "__main__":
Expand Down

0 comments on commit 05c78a9

Please sign in to comment.