question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pre commit hook workflow

See original GitHub issue

I’m trying to set up a pre-commit hook workflow following the docs but having some issues with what I have in mind. The workflow I’m immagining right now is as follows:

  1. Make changes to notebook
  2. add notebook to staging area
  3. commit => before committing the pre-commit hook runs converts the notebook to .py adds it to the commit and then proceeds to committing

From reading the issue where support for the pre-commit framework was added, it looks like that the problem is in the last point: the pre-commit hook is supposed to generate the .py file but not add it to the staging area.

My issue with this behaviour is that this way I always have to make tha same commit twice, once for the notebook, once for the .py. Indeed, if I’m working on the notebook file and not touching the .py, from one commit to the next the .py is going to be the same so git won’t event let me add it to the staging area. Then, when committing the first time around, the jupytext pre-commit hook fails telling me that the git index is outdated and asking me to add the .py to the staging area; then running the commit a second time adding the generated .py everything works fine.

My question is, is this the intended behaviour or am I missing something?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JohnPatoncommented, May 27, 2022

Only if there are also conflicts on the py files (in the case of code changes), in which case they need to be resolved anyway, or in case people commit different outputs. If you’re worried about that you could use something like kynan/nbstripout to additionally remove the outputs, and then there can only be conflicts in both files or neither, since the content will be essentially the same.

1reaction
JohnPatoncommented, Oct 20, 2021

This is correct and the intended behaviour. pre-commit themselves promise to never modify the staging area - the user needs to take responsibility for any code changes that are being committed, essentially. See for example this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Git Hooks - Git SCM
The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to...
Read more >
Supported hooks - pre-commit
reorder-python-imports - This hook reorders imports in python files. ... check-github-workflows - Validate GitHub Workflows against the schema provided by ...
Read more >
Git Hooks | Atlassian Git Tutorial
The pre-commit script is executed every time you run git commit before Git asks the developer for a commit message or generates a...
Read more >
Automating Python Workflows with pre-commit Hooks
As the name suggests, pre-commit hooks are certain actions that are triggered the moment before a commit is created. Pre-commit hooks are ...
Read more >
How To Ease Your Team's Development Workflow With Git ...
Git hooks are scripts that are triggered when specific actions or events are performed in a git repository. These actions are about parts...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found