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.

Add more tests on the pre-commit hook

See original GitHub issue

@JohnPaton and @Skylion007 have developed a pre-commit hook for this repo - that was an impressive work #698!

Here is a list of small improvements that we identified during the PR and that I’d like to include in the next release:

  • Add an entry to the CHANGELOG
  • Update the documentation for the --to test to match the example that is actually tested
  • In the documentation, the emphasis should be on the hook for the pre-commit framework. We could move the documentation for the manual pre-commit hook to another section.
  • Split the tests on the pre-commit into multiple files. Again the emphasis should be on the new tests and on the use cases documented in the documentation
  • Refactor the tests to make them easier to read, using fixtures. If possible, test the error text (currently we just test SystemExit which does not contain a detailed error message)
  • Change the jupytext CLI to avoid writing files that don’t change (only update their timestamp). And make sure that this fixes the pre-commit hook when run on file types .py + .ipynb (or even tripled-paired notebooks)
  • Test and document a --sync --pipe black mode.
  • Test and document a --sync + nbstripout mode.
  • Test and document a --sync --execute mode.
  • Find a way to safely reformat long markdown cells (without breaking markdown tables…)
  • Test modifying the .py file in the --sync mode
  • Test the hook in the context of pre-commit run --all (no need to add files to the git index in that context)
  • Test moving a paired notebook

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
mwoutscommented, Feb 8, 2021

Wow! Congrats John!

Well as you see we finally were able to ship the pre-commit hook in Jupytext v1.10.0. I have made no announcement yet, in part because I wanted to finish the blog post, and also because I wanted to find the appropriate approach for the new cell ids in nbformat 5.1.1 (everything seems fine in the end if one does either --update or --sync, from Jupytext 1.7.1 on).

I hope to come back to you both soon with more updates on the article, but that might take me a few more days/weeks… Slow progresses, but this is a very nice feature, it is worth documenting it well, isn’t it?

1reaction
mwoutscommented, Jan 26, 2021

I had more fun with this tonight!

  • I moved each use case to a new test file to improve the readability of tests (not sure however how many people actually read the tests 😄 )
  • --sync and nbstripout work well together, see test_pre_commit_2_sync_nbstripout.py
  • --sync and nbstripout and black also seem to interact well, however as @JohnPaton previously noticed black needs to be present in jupytext --pipe, cf test_pre_commit_3_sync_black_nbstripout.py
  • maybe I’d like an example of a hook that does not commit the ipynb file, but I don’t see how it could work… is it possible for a hook to reset files in the index?
  • I still have to handle a side effect in test 3 - the global pairing causes a modification on the py file the second time the hook runs, see the TODOs there
  • --execute almost works. Thanks to the new --diff argument that displays the change when the file has to be rewritten, we clearly see that this is because of execution timestamps… Do you agree that in --execute --pre-commit-mode we can consider that the notebook has not changed if only the execution timestamps change?
Read more comments on GitHub >

github_iconTop Results From Across the Web

pre-commit
We built pre-commit to solve our hook issues. It is a multi-language package manager for pre-commit hooks. You specify a list of hooks...
Read more >
Pre-Commit hooks for running tests
A pre-commit/push hooks stops developers from having such a workflow. It really doesn't stop you skipping the steps anyway. When developers see that...
Read more >
PreCommit Hooks!
Often a pre-commit hook can be used to run your test before a new commit is added, just in case there is a...
Read more >
Automate Unit Tests before each commit by Git Hooks
Here is the steps to do that: · 1- Create script folder inside our project's directory. · 2- Create install-hooks.bash script: We run...
Read more >
Automating Code Checks and Tests with Git Hooks
The most common way to add checks to your codebase is to use husky and lint-staged. I have used husky many times to...
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