Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add verbosity levels arguments #206

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fmigneault
Copy link

@fmigneault fmigneault commented Feb 19, 2025

Adds multiple -v arguments to control the level of verbosity.

Technically, the amount of "-v" could be leveraged for even finer WARN/INFO/DEBUG levels, but I assumed the typical intent when using a single -v would be INFO. WARN and above is like omitting them, which only report problem cases.

Using multiple -v (regardless of the amount for now) enables DEBUG logs.
The AssertionError is used to log such as DEBUG log.
More could be added for actual debugging, but it is not the case currently.

Same behavior as before using the -vv arguments (can use -v -v, -v=2, --verbose=2, etc. as well).

flynt --dry-run --fail-on-change --line-length 120 --transform-concats -vv .

[...]

fstringifying /home/francis/dev/weaver/weaver/processes/ogc_api_process.py...no change
fstringifying /home/francis/dev/weaver/weaver/processes/sources.py...no change
Exception during conversion of code: Traceback (most recent call last):
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/transform.py", line 32, in transform_chunk
    converted, changed = fstringify_node(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/FstringifyTransformer.py", line 88, in fstringify_node
    result = ft.visit(node)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    result_node = joined_string(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/format_call_transforms.py", line 18, in joined_string
    assert isinstance(fmt_call.func, ast.Attribute) and isinstance(
AssertionError

Exception during conversion of code: Traceback (most recent call last):
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/transform.py", line 32, in transform_chunk
    converted, changed = fstringify_node(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/FstringifyTransformer.py", line 88, in fstringify_node
    result = ft.visit(node)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    result_node = joined_string(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/format_call_transforms.py", line 18, in joined_string
    assert isinstance(fmt_call.func, ast.Attribute) and isinstance(
AssertionError


fstringifying /home/francis/dev/weaver/weaver/wps_restapi/api.py...no change
Exception during conversion of code: Traceback (most recent call last):
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/transform.py", line 32, in transform_chunk
    converted, changed = fstringify_node(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/FstringifyTransformer.py", line 88, in fstringify_node
    result = ft.visit(node)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    result_node = joined_string(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/format_call_transforms.py", line 18, in joined_string
    assert isinstance(fmt_call.func, ast.Attribute) and isinstance(
AssertionError

Exception during conversion of code: Traceback (most recent call last):
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/transform.py", line 32, in transform_chunk
    converted, changed = fstringify_node(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/FstringifyTransformer.py", line 88, in fstringify_node
    result = ft.visit(node)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    result_node = joined_string(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/transform/format_call_transforms.py", line 18, in joined_string
    assert isinstance(fmt_call.func, ast.Attribute) and isinstance(
AssertionError

[...]

New behavior when only a single -v is provided.
We can now see actual errors more clearly!

flynt --dry-run --fail-on-change --line-length 120 --transform-concats -v .

Running flynt v.1.0.2
Using following options: Namespace(verbose=1, quiet=False, no_multiline=False, line_length=120, dry_run=True, stdout=False, string=False, transform_percent=True, transform_format=True, transform_concats=True, transform_joins=False, fail_on_change=True, aggressive=False, exclude=None, src=['.'], version=False)
Running flynt in dry-run mode. No files will be changed.
Not converting code due to: A variable 0 is used multiple times - better not to replace it.
fstringifying /home/francis/dev/weaver/setup.py...no change
fstringifying /home/francis/dev/weaver/weaver/config.py...no change
fstringifying /home/francis/dev/weaver/weaver/__meta__.py...no change
fstringifying /home/francis/dev/weaver/weaver/exceptions.py...no change
fstringifying /home/francis/dev/weaver/weaver/cli.py...no change
fstringifying /home/francis/dev/weaver/weaver/sort.py...no change
fstringifying /home/francis/dev/weaver/weaver/execute.py...no change
fstringifying /home/francis/dev/weaver/weaver/notify.py...no change
fstringifying /home/francis/dev/weaver/weaver/datatype.py...no change
fstringifying /home/francis/dev/weaver/weaver/compat.py...no change
fstringifying /home/francis/dev/weaver/weaver/__init__.py...no change
fstringifying /home/francis/dev/weaver/weaver/provenance.py...no change
fstringifying /home/francis/dev/weaver/weaver/warning.py...no change
fstringifying /home/francis/dev/weaver/weaver/xml_util.py...no change
fstringifying /home/francis/dev/weaver/weaver/utils.py...no change
fstringifying /home/francis/dev/weaver/weaver/typedefs.py...no change
Faulty result during conversion on /home/francis/dev/weaver/weaver/tweens.py - skipping.
Traceback (most recent call last):
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/flynt/api.py", line 143, in fstringify_code
    ast_after = ast.parse(new_code)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 124
    err_repr = f"{err_repr.replace('Invalid schema: [', 'Invalid schema: [\\n')[:-1]}\n]"
                                                                                         ^
SyntaxError: f-string expression part cannot include a backslash
fstringifying /home/francis/dev/weaver/weaver/tweens.py...failed

[...]

@ikamensh
Copy link
Owner

Thanks for your PR! I've approved CI run, unit tests are failing.

@fmigneault
Copy link
Author

fmigneault commented Feb 19, 2025

Should be good to go now.

I've also adjusted the way the error is passed via exc_info.
I believe most of the over-verbose output was due to tracebacks being logged twice, once by the explicit msg string and another by the internal logging call on ERROR level when an exception was involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion tracebacks too verbose
2 participants