-
Notifications
You must be signed in to change notification settings - Fork 392
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
Add a .pre-commit-hooks.yaml to enable hooks to refer to this repo #691
Comments
Hi @JohnPaton , thank you for your recommendation. I don't have much experience with |
Hey @mwouts, sure, I can take a swing at it. I myself am not super familiar with jupytext (yet, it looks like an amazing project so looking forward to getting deeper into it), so I'll propose a few hooks to provide and we can chat about the details. |
So I've been playing around a bit, and it seems like the best option would be to have some way to both:
The reason for this is that I'm happy to help build something like this, but since it seems it will be a bit more than just a new |
Hi @JohnPaton , thank you so much for your PR! Thanks for pointing out at the need to add the files that Jupytext may create, sure you're right, it's how it should be done. Regarding testing, we have a series of tests on the (other) pre-commit mode in Also, I wanted to comment on how I see people using Jupytext:
|
Hey, thanks for thinking along! I'll check out the existing tests if you agree this is the right approach.
I think it would make sense to still have examples of how to use Jupytext as a pre-commit hook outside of the
or something like that (I didn't test this, probably wrong but you get the idea).
I think this can stay as it is in the PR, no? I'm not 100% sure what the default behaviour of Jupytext is, but I assume there's a prioritization for determining the output format like (in some order)
That would give the most flexibility to either only use the hooks, have a global settings file in VCS, or manage it per file. Is that pretty much the current situation?
I'm not sure I 100% understand the use case for For this use case, I mostly see the hook as ensuring that any changes to notebooks are reflected in the matching text files (e.g. for PR reviewability), but this is obviously tinted by the fact that that is my own use case. |
Hi @JohnPaton , thank you again for your useful comments!
Oh I just had a closer look at your PR, I like it very much. Don't bother with that, it should be easy for me to add coverage for the new
I agree! And it's almost working, only here my shell does not seem to understand
I think I am seeing a default
Oh sure! And that is related to the previous question 😄 When the user get the text files they will be tempted to modify them, and I think it is better to report that modification onto the Also I've looked into previous issues in which people were looking for such a pre-commit hook, and I've found
|
Turns out just
should work
That is correct, yeah. It felt a bit weird to have the hook not work by default. But actually if Jupytext doesn't define defaults, then the hook shouldn't either, so I will update my PR and the docs.
Ah yes, this does make sense, thanks! In light of this I think it makes even more sense to remove the defaults from the PR, and always have the user select them explicitly.
Yeah, the flexibility to do this will be really important. I think the current
Absolutely! |
Btw, just noticed that this
Is not the default behaviour - maybe we should either document (and implement) that this is the behaviour when |
I added a few tests for |
Hiya, sorry for joining this discussion lately. @mwouts Not sure if you remember but there are some old issues on how to use jupytext with pre-commit that aren't covered by this hook structure. #580, which wasn't one of the two linked so I didn't get a notification of this thread.
^ THIS 100% Why not combine the other hooks using additional dependency instead of requiring them explicitly? We should just force the user to specify it for any other pipe commands they need as it's rather easy to do so. There should definitely be a sync hook as default imo and it should --set-format behavior as default for bidirectional syncing. Otherwise, some one is going to edit one file or the other in a PR an get their changes overwritten and be annoyed later.
Use case for us is generating google colabs from python scripts and vice versa. It works really well and ensure that the two files are in sync and either the colab or the script can be edited and the changes will propogate.
💯 this. Came back here today to write a PR to do that, and found this thread. 💯 Posted a very messy custom hook below that does it, but I would like to make the official one use the How we currently use the pre-commit hook for Jupytext.
|
See the discussion from #580 . Left some comments on the PR. Sorry it took so long to cycle back to this. |
@mwouts Happy to help with out the blogpost 👍 |
I am against the githook actually modifing the git index on its own. It really should just return a non-zero exit code if it edits / modifies a file outside the git index instead, it shouldn't add the file to gitindex by itself because often that could be indicative on error. |
I essentially agree. The reason for it in this case is that pre-commit doesn't consider changes to files if they aren't in the index, so in the PR we only put them there if they are new, and then fail the hook to alert the user. I guess an alternative would just be to fail if the outputs aren't tracked with some kind of warning telling the user what's up? |
Exactly! Sorry about blasting your github message stacks today. Been thinking about implementing this pre-commit hook for a while and finally was going to do it today 😆 I am against even adding new files to the index though because new notebook files, for instance, could have 100mbs of images and could pollute the Git repo inadvertently. |
@JohnPaton Precommit hooks intentionally never touch the staging area: https://stackoverflow.com/questions/64309766/prettier-using-pre-commit-com-does-not-re-stage-changes/64309843#64309843 |
Hey, sorry for radio silence - been a busy few days. I'll go through your comments now. But you've convinced me that just failing the hook with a clear message is a better approach ✅ |
The current documentation suggests to use
repo: local
to usejupytext
as a pre-commit hook with pre-commit. However, this requires the user to havejupytext
installed in the environment they are working in when committing.To avoid version conflicts etc, pre-commit usually creates a virtualenv per repo and runs the hooks from there. To do this, relies on hook providers to have a
.pre-commit-hooks.yaml
file. Adding this here would allow users to userepo: https://github.com/mwouts/jupytext
to make a dedicatedjupytext
environment within pre-commit, instead of relying on users to have it installed in their current env. As an added bonus,jupytext
could provide a "menu" of common hooks, if desired (e.g. "always convert .ipynb to .py", "always unstage .ipynb", etc). These are configurable, but not required.The text was updated successfully, but these errors were encountered: