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:
- Created 3 years ago
- Comments:15 (15 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?
I had more fun with this tonight!
--sync
andnbstripout
work well together, see test_pre_commit_2_sync_nbstripout.py--sync
andnbstripout
andblack
also seem to interact well, however as @JohnPaton previously noticedblack
needs to be present injupytext --pipe
, cf test_pre_commit_3_sync_black_nbstripout.pyipynb
file, but I don’t see how it could work… is it possible for a hook to reset files in the index?--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?