Jupytext plugin for the pre-commit package, compatible with black and flake8
See original GitHub issuethe pre-commit package (described in this blog) provides a framework for managing precommit hooks. It would be great if jupytext had an option that would allow it to be a pre-commit hook with that package – essentially it would just need to suppress the stdout message and return 0, adding the translated file to the index. Specifically, this script is working for me now:
import sys
import subprocess
from pathlib import Path
cmd = f"jupytext --to py:percent {sys.argv[1]}"
notebook = Path(sys.argv[1])
pyfile = str(notebook.with_suffix(".py"))
status1, output1 = subprocess.getstatusoutput(cmd)
cmd = f"git add {pyfile}"
status2, output2 = subprocess.getstatusoutput(cmd)
with open("jupytext_logfile.txt", "w") as f:
f.write(
(f"{sys.argv}\n" f"{status1}\n" f"{output1}\n" f"{status2}\n" f"{output2}\n")
)
sys.exit(0)
when I save it as pre_commit_jupytext.py and call it with a pre-commit config entry in .pre-commit-config.yaml that looks like this:
repos
- repo: local
hooks:
- id: jupytext
name: jupytext
entry: python a301/scripts/pre_commit_jupytext.py
language: system
but I think smoothing this a little with a command line option would be a nice addition.
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (19 by maintainers)
Top Results From Across the Web
Jupytext documentation
Jupytext is a plugin for Jupyter that can save Jupyter notebooks as ... package to run pre-commit scripts like black and flake8 on...
Read more >Supported hooks
cheetah-reorder-imports - This hook reorders imports in cheetah files. cheetah-flake - Lint cheetah code using flake8 and some other checks.
Read more >jupytext
On the command line. jupytext converts Jupyter notebooks to their text ... jupytext --from ipynb --pipe black --check flake8 --pre-commit ...
Read more >Stylising your Python code: An introduction to linting and ...
It should be noted that Flake8 does not, by default, look for as many PEP8 violations as Pylint (unless you install some plugins)....
Read more >Pre-Commit — Using Automation To Support Quality Assured ...
Writing pre-commit scripts can be a complicated affair, but the pre-commit Python package provides a much simpler and more powerful framework for writing...
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 FreeTop 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
Top GitHub Comments
Thank you @KwatME for your kind words. Well you may be interested in the
jupytext.read(s)/write(s)
methods. They work similarly tonbformat.read(s)/write(s)
(which you could use in place ofjson.load
andjson.dump
to open/save notebook files).Agree. I think jupytext is wonderful because it can do so much and well liked by the community. I want to see how I can start using it 😃 Thanks @mwouts