diff --git a/.gitignore b/.gitignore index 147e545..f0b4ce7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,8 @@ __pycache__/ # Generated by build /dist + +# IDEs configs/caches +.vscode +.idea +.run diff --git a/pyproject.toml b/pyproject.toml index 6eb7b56..a1f3f8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ dev = [ "pytest", "pytest-cov", "twine", + "ruff", ] [project.scripts] diff --git a/src/flynt/api.py b/src/flynt/api.py index ce4e681..1823f49 100644 --- a/src/flynt/api.py +++ b/src/flynt/api.py @@ -5,7 +5,6 @@ import os import sys import time -import traceback from difflib import unified_diff from typing import Collection, List, Optional, Tuple @@ -100,10 +99,10 @@ def fstringify_code( new_code, state=state, ) - except Exception: - msg = traceback.format_exc() - log.error("Transforming concatenation of literal strings failed") - log.error(msg) + except Exception as exc: + log.error( + "Transforming concatenation of literal strings failed", exc_info=exc + ) else: changes += concat_changes state.concat_changes += concat_changes @@ -113,10 +112,10 @@ def fstringify_code( new_code, state=state, ) - except Exception: - msg = traceback.format_exc() - log.error("Transforming concatenation of literal strings failed") - log.error(msg) + except Exception as exc: + log.error( + "Transforming concatenation of literal strings failed", exc_info=exc + ) else: changes += join_changes state.join_changes += join_changes diff --git a/src/flynt/cli.py b/src/flynt/cli.py index c04c1f1..3d563be 100644 --- a/src/flynt/cli.py +++ b/src/flynt/cli.py @@ -29,9 +29,9 @@ def run_flynt_cli(arglist: Optional[List[str]] = None) -> int: verbosity_group.add_argument( "-v", "--verbose", - action="store_true", + action="count", help="run with verbose output", - default=False, + default=0, ) verbosity_group.add_argument( "-q", @@ -194,8 +194,10 @@ def run_flynt_cli(arglist: Optional[List[str]] = None) -> int: ) state = state_from_args(args) - if args.verbose: - logging.getLogger("flynt").setLevel(logging.DEBUG) + if args.verbose > 0: + logging.getLogger("flynt").setLevel( + logging.DEBUG if args.verbose > 1 else logging.INFO + ) if args.string: content = " ".join(args.src) diff --git a/src/flynt/transform/transform.py b/src/flynt/transform/transform.py index 1016c09..ce39fd4 100644 --- a/src/flynt/transform/transform.py +++ b/src/flynt/transform/transform.py @@ -1,7 +1,6 @@ import ast import copy import logging -import traceback from typing import Tuple from flynt.exceptions import ConversionRefused @@ -38,9 +37,9 @@ def transform_chunk( log.warning("Not converting code due to: %s", cr) state.invalid_conversions += 1 return None, False # type:ignore # ideally should return one optional str - except Exception: - msg = traceback.format_exc() - log.exception("Exception during conversion of code: %s", msg) + except Exception as exc: + level = logging.DEBUG if isinstance(exc, AssertionError) else logging.ERROR + log.log(level, "Exception during conversion of code", exc_info=exc) state.invalid_conversions += 1 return None, False # type:ignore # ideally should return one optional str else: