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

document/set up support tooling for editor integrations #185

Closed
RonnyPfannschmidt opened this issue Oct 4, 2018 · 10 comments
Closed

document/set up support tooling for editor integrations #185

RonnyPfannschmidt opened this issue Oct 4, 2018 · 10 comments

Comments

@RonnyPfannschmidt
Copy link

follow-up to jgirardet/sublack#31
deferred from pre-commit/pre-commit#838

as i conversed with sublack author, it became apparent that its pretty hard/tricky to integrate pre-commit/black for example with editor integrations (in order to fix exact project set-ups)

i wonder if the issue can be elevated/helped in some way

@jgirardet
Copy link

hi @asottile .
Indeed using tempfile is not a big performance issue. I tested.
The main problem. is the pre-commit running time.

@RonnyPfannschmidt asked me for using same version of black (in editor and command line) via pre-commit.
I see 2 ways of doing it keeping run time as slow as possible:

  • pre-commit could have a "skip-pre-commit" ;-) option to directly run the hook, skipping all the precommit stuf. if it accepts arguments we are ultimate.
  • expose the hook path via a "hook info" option or something like this so we could run directly the right executable from pre-commit repo.

@RonnyPfannschmidt
Copy link
Author

@jgirardet would it be sufficient to limit the pre-commit hook run to only/exactly the black hook, if the env is cached already that might be really quick

@asottile
Copy link
Member

asottile commented Oct 4, 2018

pre-commit could have a "skip-pre-commit" ;-) option to directly run the hook, skipping all the precommit stuf. if it accepts arguments we are ultimate.

I'm not sure what you mean here, that's essentially what pre-commit run <hookid> --files ... is

@jgirardet
Copy link

the idea was to run black via precommit but without the whole bunch of things that pre commit do, to save some time.

@asottile
Copy link
Member

asottile commented Oct 4, 2018

there isn't really anything that pre-commit does beyond collect the args and subprocess, last time I profiled it it essentially boiled down to:

  1. 5%: python interpreter startup
  2. 80%: import of pkg_resources module
  3. 1%: subprocess to determine git rev-parse --show-toplevel
  4. 1%: parsing yaml configurations
  5. 1%: subprocess git ls-files to cross reference --files
  6. 1% subprocess git diff to know when files change

And factoring out pkg_resources isn't easy.

@asottile
Copy link
Member

asottile commented Oct 4, 2018

some rough numbers:

$ time ~/opt/venv/bin/python -c ''

real	0m0.028s
user	0m0.020s
sys	0m0.008s

$ time ~/opt/venv/bin/python -c 'import pre_commit.main'

real	0m0.185s
user	0m0.169s
sys	0m0.017s

$ time pre-commit run echo --verbose --files setup.py
[echo] echo..............................................................Passed
hookid: echo

setup.py


real	0m0.204s
user	0m0.181s
sys	0m0.025s

@jgirardet
Copy link

thank you for your answers @asottile

@asottile
Copy link
Member

Note that pkg_resources will be factored out in the next release: pre-commit/pre-commit#840

@RonnyPfannschmidt
Copy link
Author

@asottile great job, thanks 👍

@asottile
Copy link
Member

asottile commented Jan 1, 2022

feel free to send PRs for editor integrations -- going to close this since there isn't really anything actionable at the moment

@asottile asottile closed this as completed Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants