-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Prefer to use local command with pip dependency? #1073
Comments
I forgot to mention: This is intended as a documentation issue. Updated: Added to the list of advantages that this method can pin the black version, using for instance |
first off, you're correct in that the current docs are incorrect -- this is covered in #420 (black shouldn't suggest let's address Option 3 first, this misses the idea of the framework entirely so I'd like to address it and eliminate it first :) -- the whole idea of the framework is that you clone a repo and don't need to worry about installing N tools to deal with linting and code formatting -- the framework installs them for you (and can properly manage the versions etc.). The consistent versioning and tool availability is the selling point -- no need to futz with globally installed things, virtualenv activation, system configuration management, fiddly bash scripts, etc. etc. next let's address the other (which works, but has some pretty major downsides) the first is that the repository configuration provides reasonable and correct defaults. for instance your two local configurations both suffer from a pretty bad bug that was fixed in this repository -- they create resource starvation due to over-zealous multiprocessing. the repository inclusion received this fix and everyone received this fix automatically. Instead of sitting upon a well established and battle tested base you've got to copy paste your configuration (and you're unable to reap the benefits when improvements are made to the base!). the second is update ergonomics, with the the third is your comparison of speed and bandwidth, from my tests I'm not seeing as much of a difference (perhaps it's because I'm using a new enough version of git which can take advantage of shallow clones) -- but even then I don't think 3 seconds is really breaking the bank. Plus, in almost all situations you should be hitting a cache (pre-commit will reuse environments, and it's fairly trivial to add the fourth I'd like to discount is the "easily customizable" part -- that's already a built in feature of the current form you simply override - id: black
args: [--check] # or `entry: black --check` the last, and perhaps the most important advantage of the repository approach is that since it's git you can easily do git things like: use an unreleased version (simply point note that thanks for reading, hope this clears some things up |
thanks for the response @asottile, I tend to agree |
Hi @asottile Thanks for taking time for the thorough response. Maybe the issue of referencing tools through PyPi releases is a more fundamental upstream one (for instance pertaining Notes and analysisNoting that the issue is now closed, I wanted to clarify a few things and refine the proposal.
New proposal (mix of Option 1 and 2)So to synthesize all this, here's a final proposal: Externalize
Problems
New BenchmarkAs advised, I've benchmarked the solution only with New option (configuration stored in external repo)
Option 1 (configuration stored in main repo)
I tried installing it from a different git repo on the same system, and you are right that it's all cached. I'm not sure about how shallow clones work, but I would expect this to get worse as the repository history grows. Option 2 (local config referencing a pip dependency)
|
(updated after implementing an external test repository) |
yeah you're not really expecting right :) -- a shallow clone only downloads the contents of the revision you ask for -- the whole point is that it pulls no history. over time this path will be more and more common in pre-commit as people upgrade their OS / etc. I think maintaining two repos when one is sufficient is a lot of work to ask someone to do when it's not really saving anyone significant time or bandwidth (it's like the equivalent of loading(or not) one webpage written in react) |
So this is what I make of your response: In the future, git shallow clones will greatly reduce the data fetched from git repositories. Thus, the performance gains from installing .whl releases from PyPi are unsubstantial. |
they're already unsubstantial but will be even more so, yes |
I don't agree at all, but that can be discussed in another forum some other day :) Am a happy user of |
How we install black for pre-commit hooks
CC: @asottile
As per current README, a pre-commit hook is shown that will fetch the full
psf/black
git repository and invoke setup.py in order to install theblack
executable for the pre-commit hook.I would like to recommend that installing the .whl from PyPi is faster and requires less bandwidth.
Moreover, using a locally available
black
command saves the developer double-trouble, i.e. installing black in both the~/.cache/pre-commit
and in some other dev environments. This might not look good as the default option (mixing pre-commit environment with development/deployment environments), but it's a very nice option for people who prefer having few environments.Summary
Using PyPi to install, takes 6 CPU seconds, whereas the repo-based install takes 10 CPU seconds.
According to
nethogs
, using the repo fetches about 3.7MB of data, invoking/usr/lib/git-core/git-remote-https
. Usingpip
and a completely clean~/.cache/pip
, 309 KB is fetched (black and dependencies). With pip cache already populated, just 12 KB is fetched from the network.Some advantages of using PyPi releases with pip:
pip
also uses pip's system cache, so installing the same version of black several times won't use networkentry: black --check
.Option 1: Current repo-based configuration
Option 2: A local command with a pip dependency
Option 3: Just use black from the current environment
This requires runnning
pip install black
before executing pre-commit hooks.Benchmarks
Option 1:
Option 2:
The text was updated successfully, but these errors were encountered: