From 05c78a93c34e4e23e6ae15ee398948870bad6468 Mon Sep 17 00:00:00 2001 From: Felipe Campos Date: Thu, 11 Jun 2020 09:46:11 -0700 Subject: [PATCH] f-string colorama formatting in helper method --- tox.ini | 1 + twine/__main__.py | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tox.ini b/tox.ini index 115b31e0..e28ff85b 100644 --- a/tox.ini +++ b/tox.ini @@ -11,6 +11,7 @@ deps = portend pytest-services munch + colorama passenv = PYTEST_ADDOPTS commands = diff --git a/twine/__main__.py b/twine/__main__.py index 189b7d79..e42346c7 100644 --- a/twine/__main__.py +++ b/twine/__main__.py @@ -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__":