seddonym / import-linter

Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
https://import-linter.readthedocs.io/
BSD 2-Clause "Simplified" License
664 stars 45 forks source link

Less verbose output #204

Open tuukkamustonen opened 10 months ago

tuukkamustonen commented 10 months ago

Hi, thanks for the great library. Taking it into use in a legacy repository that we've been refactoring mercilessly! The layered mode will come to good use.

What would you think of option for less verbose output? Even with no violations, the output is quite verbose:

=============
Import Linter
=============

---------
Contracts
---------

Analyzed 653 files, 2276 dependencies.
--------------------------------------

Layers KEPT

Contracts: 1 kept, 0 broken.

I'd rather only get single line (or no line at all, if all is okay).

We run import-linter alongside other tools, via a bash script. It will output something like:

Running Black...
All done! ✨ 🍰 ✨
26 files left unchanged.
Running ruff check --fix...
Running isort...
Running autoflake...
Running docformatter...
Running ruff...
Running flake8...
Running pydocstyle...

Most tools seem to default to not print anything at all, if there are no violations (only Black is more verbose as can be seen above). Would be nice to have the same behavior for import-linter, too?

seddonym commented 10 months ago

Nice idea. Happy to consider a pull request for this if anyone is interested.

I suggest we follow the same approach as Ruff, that is we add a --quiet flag which cannot be used with --verbose. That would be backwards compatible. Open to other suggestions.

tuukkamustonen commented 10 months ago

I'm not sure, is --quiet for something else?

  -q, --quiet    Print diagnostics, but nothing else
❯ touch foobar.py                                                                   
❯ ruff foobar.py             
❯ ruff --quiet foobar.py

Prints nothing (no violations).

❯ echo "blahlbha" > foobar.py                                                                   
❯ ruff foobar.py             
foobar.py:1:1: B018 Found useless expression. Either assign it to a variable or remove it.
foobar.py:1:1: F821 Undefined name `blahlbha`
Found 2 errors.
❯ ruff --quiet foobar.py
foobar.py:1:1: B018 Found useless expression. Either assign it to a variable or remove it.
foobar.py:1:1: F821 Undefined name `blahlbha`

The --quiet seems to remove the "Found 2 errors." but it doesn't affect the violations output.

In any case, just to clarify what this ticket suggests:

seddonym commented 10 months ago

I don't understand, that seems to be what ruff is doing but I might be misunderstanding. In any case, feel free to outline here how you propose things should work in detail (maybe with some examples)?

tuukkamustonen commented 10 months ago

I mean that ruff by default acts as suggested in this ticket. The explicit ruff --quiet only removes "Found 2 errors." when there are errors but it doesn't do anything when there aren't. Ruff is kinda quiet by default. I'm not exactly sure what the --quiet in ruff would be useful for...

So import-linter doesn't need similar --quiet but yes it needs --quiet to avoid changing the default behavior, which is opposite to ruff and most tools out there. For that reason, you might consider changing the default behavior but I totally understand if you don't want to.

I hope I sketched it out better this time! If not... we'll just carry on 😄

seddonym commented 10 months ago

you might consider changing the default behavior but I totally understand if you don't want to

I don't think I'll do this unless as part of a major release. In the meantime, open to pull requests that add a --quiet flag (or some other suggested API) but don't change the default behaviour.