-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Using pre-commit framework #3212
base: main
Are you sure you want to change the base?
Conversation
I still do not know how to make this work
Is the goal of this to run the checks locally before a commit is created? I have tried that and found that it makes it terribly slow to get anything done (especially as someone who tries to make many small commits), so I wonder if there's a different way to make those checks less of an unpleasant surprise for contributors? (If I'm misunderstanding what this would do please let me know as well!) |
Hello all!
I understand
We could start with just a very fast check (e.g., black), and only on push (rather than over every commit). I would certainly welcome it, since I'm always forgetting to run black on migration files!
In this first stage, we could also mention in the contributing guide that the use is optional? (To clarify: this is the default, since nothing will run on developer machines unless they explicitly run @ccamara Would this make sense to you as an initial step? P.S.: I haven't had time to check, but perhaps curlylint/stylelint/eslint are equally fast and could be included (plus, as far as I know they would only run if the push touches relevant files, i.e. non-python). From this PR, |
Thank you for confirming! Even running black is too slow for me on a commit-by-commit basis, but pre-push sounds like a good compromise. And like you say, if it's opt-in, then it's a non-issue for people like me who have spent their lives on geriatric laptops where running simple commands is a get-up-and-make-tea level time commitment. With the exception of black and eslint, I haven't used the other linters to actually fix code issues, and I'm not sure if they'd all be a good fit? But having Black by itself would be a big help, since it's practically impossible (at least for me) to write code exactly how it wants it :) |
Hello all! Thanks for your input, and apologies for my late reply (life happens). I need to make a disclaimer: this is the first time I've ever used pre-commit framework, and I'm now speaking from memory after not haven't used it for some months, so my responses may not be 100% correct. @dato what you've described makes sense, but I'm afraid that's not how pre-commit works and I'm not even sure that it could be achieved using it (it seems to me that to do that, we'd need to use regular git hooks, which are a different approach -albeit with some overlaps). What pre-commit does is basically run some "hooks" (not regular git hooks, hence the confusion) that are listed in a yaml file called
I recognise that not being able to create commits, or even seen some automated changes, might be frustrating for some, but IMHO, it has some advantages (besides what I described at #3213):
I honestly haven't experienced any slowdown because of pre-commit. This could be because my laptop is fast, but I believe it is mainly because tests are only run for a subset of the modified files (based on the configuration on the yaml file, which lists the file extensions for the files to be checked for every hook, independently). Of course, it could be both, or that I'm wrong (not trying to gaslight you, @mouse-reeve !) I hope this clarifies your questions/concerns (or at least some) to inform a decision. |
Hi @ccamara
Ah, but the pre-commit software uses plain git hooks under the hood. :) By default, the ‘pre-commit’ Git hook is used (hence the name of the “pre-commit” software); but it can be configured to use other hooks (which pre-commit calls “hook types”). For example, to use black before push we can set
|
Furthermore, we’re only discussing the default for the repo. If you or any other contributor prefers the default ‘pre-commit’ behavior, you still can install the hook manually:
|
I see. Thanks for that. There's so much I didn't know about pre-commit! |
When I installed this pre-commit, I kept getting:
I changed the version number in the .pre-commit file to |
I've learnt the hard way that bookwyrm follows a style guide and has some tests that need to be passed before merging a PR.
This PR is an attempt to install the Pre-commit framework, which should implement those tests BEFORE creating a commit. While it may seem redundant, they are not:
IMHO, having something like pre-commit would speed up the contributing process, as contributors (even new ones like me who would forget about manually running the tests) would immediately know if their code adheres to the style guide.
This is a draft. I can see, at least, the following items that should be addressed before merging:
requirements.txt
but I'm not sure how the environment setup works in this project, as I'm not familiar with docker -also, not sure if we should be usingrequirements-dev.txt
-feel free to suggest solutions)Disclaimer: I've never used pre-commit before. Input is welcome.
This would fix #3213