pre-commit icon indicating copy to clipboard operation
pre-commit copied to clipboard

Quiet mode (`pre-commit install --quiet`) which outputs less while running

Open graemedavidson opened this issue 7 years ago • 44 comments

Is it possible to have it only output on Failure, otherwise leaving it clear.

Might be a good additional option (if it does not exist already) to add at the parent level a verbosity setting in which you can get the current Passed/Skipped/Failed output at the highest. a mid level providing a single line of stats --passed=5 --skipped=2 and the above with only failures.

graemedavidson avatar Sep 05 '18 16:09 graemedavidson

That's the default behaviour unless you're using --verbose or verbose: true

asottile avatar Sep 05 '18 16:09 asottile

Away from comp now but do you mean that the output should not even show

Hook.........passed

I thought the verbose was at the hook level and hid output of the binary/script not pre-commit

On Wed, 5 Sep 2018, 17:58 Anthony Sottile, [email protected] wrote:

That's the default behaviour unless you're using --verbose or verbose: true

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pre-commit/pre-commit/issues/823#issuecomment-418804394, or mute the thread https://github.com/notifications/unsubscribe-auth/AI6nF5IvBy2b8QJ6G1Lk7L2XluAPtNBTks5uYAK6gaJpZM4WbT8s .

graemedavidson avatar Sep 05 '18 17:09 graemedavidson

no, it should always show the passed messaging

asottile avatar Sep 05 '18 17:09 asottile

Ok, so my question becomes a feature request.

On 5 Sep 2018 18:56, "Anthony Sottile" [email protected] wrote:

no, it should always show the passed messaging

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pre-commit/pre-commit/issues/823#issuecomment-418822945, or mute the thread https://github.com/notifications/unsubscribe-auth/AI6nF_H2NHeSbppLCtnv9gCXEtYnp_azks5uYBBXgaJpZM4WbT8s .

graemedavidson avatar Sep 05 '18 21:09 graemedavidson

What's the motivation? My initial lean is -0

asottile avatar Sep 05 '18 21:09 asottile

Unless you have a good reason I don't want to or plan on implementing this.

Comment back and I'll reopen though :)

asottile avatar Sep 13 '18 12:09 asottile

I was looking for an option like this (silence the passed hooks) so that there's less noise in my output to scroll through.

Right now this is causing me to not want to have too many separate hooks setup even if they would be useful.

aschokking avatar Feb 21 '19 20:02 aschokking

CC @blueyed

Even if a commandline option were added (which I'm against -- the output is almost a branding at this point), there wouldn't be a way to set it since there aren't ways to pass through arguments from git

asottile avatar Feb 28 '19 17:02 asottile

oops, meant to reopen -- should be open now. let's discuss.

asottile avatar Feb 28 '19 18:02 asottile

I would (like to) configure this in the config file.

blueyed avatar Feb 28 '19 18:02 blueyed

that would change it for all users which I wouldn't want so I don't think that's an appropriate place to change this

asottile avatar Feb 28 '19 19:02 asottile

So I assume there is no user config then? What about an environment variable?

blueyed avatar Feb 28 '19 19:02 blueyed

A git config option could be used for this.

blueyed avatar Feb 28 '19 19:02 blueyed

I guess another option would be to set it during pre-commit install I forgot about this but we already have a precedent for an option there: https://github.com/pre-commit/pre-commit/blob/518a72d7e7598b71105fb764d990438c1b6d485a/pre_commit/resources/hook-tmpl#L20

asottile avatar Feb 28 '19 19:02 asottile

@asottile Also sounds good.

I came up with the following for me:

--- .git/hooks/pre-commit       2019-10-23 00:52:29.446422989 +0200
+++ .git/hooks/pre-commit-my2   2019-10-23 00:52:25.649698502 +0200
@@ -180,8 +180,29 @@
 def main():
     retv, stdin = _run_legacy()
     try:
+        print('Running pre-commit: ', end='', flush=True)
         _validate_config()
-        return retv | _subprocess_call(_exe() + _opts(stdin))
+        p = subprocess.Popen(_exe() + _opts(stdin) + ('--color=always',),
+                             stdout=subprocess.PIPE)
+        try:
+            p.wait()
+        except KeyboardInterrupt as exc:
+            assert p.returncode == 1
+        except Exception as exc:
+            print("Unexpected exception:", exc)
+        out = p.stdout.read().decode()
+        if p.returncode == 0:
+            lines = out.splitlines()
+            for line in lines:
+                if line.endswith('Passed\x1b[0m'):
+                    print('✔', end='')
+                elif line.endswith('Skipped\x1b[0m'):
+                    print('…', end='')
+            print()
+        else:
+            print('\r', end='')
+            print(out)
+        return retv | p.returncode
     except EarlyExit:
         return retv
     except FatalError as e:

blueyed avatar Mar 02 '19 14:03 blueyed

I meant more that you'd have a QUIET option there which forwards along --quiet

asottile avatar Mar 02 '19 18:03 asottile

I'm a big fan of this, too. Most developers in my team only care about the checks that failed and not those that pass, especially if they are skipped. Can I advocate for a repo-level default for "quiet" (in .pre-commit-config.yaml) and an option (via environment variable?) to override that per user if needed?

rbu avatar Apr 26 '19 09:04 rbu

@asottile My solution above was really only a POC to get this going for me with pytest, and it is working well since then.

blueyed avatar Apr 26 '19 14:04 blueyed

Hey there! We have a big mono repository with 30 components and every component has his own hooks: mypy, black and reorder-python-imports. We need all of them, because configuration may be different (legacy code base and other causes)

So, when I've changed a one file, have made some mistakes and commit that, wonderful (it's really great tool, thank you!) tool pre-commit get me 89 lines with Skipped and only one with Failed status in the middle of this output.

It's really hard to parse these lines, we must use mouse to scroll to Failed hook. Also when PyCharm or GitKraken is used to commit, they has a small popup, like this:

image

I just want to see the problem or "All is ok" otherwise.

How we can solve this problem? I suggest this way:

  1. MUST Add ability to pass --show: [skipped,failed,passed] to command line interface.
  2. MUST Use env variables PRE_COMMIT_SHOW="failed, passed" pre-commit run
  3. (may be, need to discussion) Add config option to .pre-commit-config.yaml.
show:
  - skipped
  - failed
  - passed

that would change it for all users which I wouldn't want so I don't think that's an appropriate place to change this

But pre-commit already has fail_fast parameter which, as for me, must not apply for all users too. But that's applied, so why not use show also in config? 4. (may be, need to discussion) Add summary information below output:

... a lot of SKIPPED hook
hookname ..... PASSED
hookname ..... FAILED
hookname ..... SKIPPED
hookname ..... SKIPPED
... a lot of SKIPPED hook

Hooks result:
Total: 13 
Passed: 0
Failed: 1
Skipped: 12

for --show=failed,passed it will be

hookname ..... PASSED
hookname ..... FAILED

Hooks result:
Total: 13 
Passed: 0
Failed: 1
Skipped: 12

pre-commit install --quiet isn't good idea, it looks like "You need uninstall\install your software to apply new config". My first reaction is "Oh really, why we could change config in place?"

@asottile If you don't mind for that implementation, I can contribute 1\2 things from my suggestion - supports cli and variables. It will be enough for me and my use case :)

allburov avatar Oct 14 '19 09:10 allburov

@asottile Or we can fully change output, copy it from pytest. @blueyed has show us PoC

pre-commit run # or git commit -m 'Done IS-111'
# . means PASSED
# s means SKIPPED
# F means FAILED
Hooks: ..........Fsssssssssss


# Show a error output only after all
flake8/ptaf-conf-mgr.....................................................Failed
hookid: flake8

services/applications.py:17:1: I100 Import statements are in the wrong order. 'from project.tenants import is_read_only_tenant' should be before 'from project.errors import OperationError'

If we will choose this way, we don't need show option at all. I would prefer this way :)

But that will be non-backward compatible, may be someone has parse pre-commit output?

allburov avatar Oct 14 '19 09:10 allburov

I do not want to drastically change the brand look, so anything like pytest is out.

The most extreme I think I'd be ok with is something like:

Running 89 hooks...........................................Passed

vs

Running 89 hooks...........................................Failed
flake8.....................................................Failed
hookid: flake8

...

but this needs a concrete proposal (configuration value, schema, output scheme, etc.)

asottile avatar Oct 14 '19 14:10 asottile

@allburov I don't think the proposed hide_skipped is workable -- it's now impossible to discern the difference between "pre-commit didn't run" and "everything was skipped"

asottile avatar Oct 15 '19 16:10 asottile

@asottile you take a words from my mouth. May be we should add collapse_skipped: True|False (or combine_skipped)? And add summary information at the bottom (with the brand look).

mypy......................................................Passed
flake8.....................................................Failed
hookid: flake8

....

97 of 98 hooks.....................................Skipped

If "everything was skipped" it will be single line:

All hooks.............................................Skipped
# or
98 of 98 hooks....................................Skipped

With pre-commit run -v output will be full.

allburov avatar Oct 16 '19 02:10 allburov

I don't think that addresses everyone's desires (and opens the door to 3-4 more similar options which I definitely don't want)

asottile avatar Oct 16 '19 02:10 asottile

Do you mean we need go back to disscussion with "universal" solution show_statuses: failed,skipped,passed?

allburov avatar Oct 16 '19 02:10 allburov

no I think we need something simpler like quiet: true, maybe something like what I've shown above where there's a single line and then failures if present?

asottile avatar Oct 16 '19 02:10 asottile

But how we could show "the progress"? We could use "dot" for show progress, but if we will have 100 hooks - it can occupy two or more lines in output, it's not the brand look.

opens the door to 3-4 more similar options which I definitely don't want

This solution does not resolved this, because someone can ask "Get me passing hooks in quite mode too!"

We should show the progress, of course https://github.com/pre-commit/pre-commit/blob/master/pre_commit/commands/run.py#L111-L112

allburov avatar Oct 16 '19 04:10 allburov

we already don't show progress, but it's planned in the future 🤷‍♂

asottile avatar Oct 16 '19 04:10 asottile

w\a to hide all skipping msg from output

0001-hide-skipped-hook-from-output.txt

cd your-project
wget https://github.com/pre-commit/pre-commit/files/3732422/0001-hide-skipped-hook-from-output.txt
# if you use venv directory or specify you path to site-packages
patch -p1 -d venv/lib/python3.7/site-packages/ < ../pre-commit/0001-hide-skipped-hook-from-output.txt

allburov avatar Oct 16 '19 04:10 allburov

we already don't show progress, but it's planned in the future

I mean pre-commit show that "Current hook is running, wait". With quite it will look like (with 90 hooks) "All hooks is running wait ... forever?"

allburov avatar Oct 16 '19 04:10 allburov