-
Notifications
You must be signed in to change notification settings - Fork 391
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
How to clean/tests notebooks? #432
Comments
@mwouts looking at the above, when u call 'jupytext notebookname.ipynb ' does it actually know to run the py version of the file? This is great! |
Yes, when you do I am interested in reviewing what can really help the users here... And learn how I can improve my own workflow, which is super basic at the moment 😄 :
Now tell me a bit more about what you are looking for:
|
In the (last paragraphs of the) TrackingJupyter Newletter #26, by Tony Hirst @psychemedia, I learn of |
Re: workflows, I'm exploring using ipynb paired to py to create py package files. The ipynb version includes lots of
The notebook runs in all its horrible glory showing fragments of working, and the output from each line of code in a cell of its own. If things break, when they break, I can rerun all the fragmentary pieces in the notebook and compare outputs, by eye, to the committed version of the notebook, so see what's different. By the by, a couple of things that would improve my workflow not strictly Jupytext related but that complicate how I use Jupytext:
|
Very cool. I'm testing this out now but so far @mwouts it's actually working well!! so what i want to do is update our CI to test things. flake8 is awesome because it catches things like unused imports. i'm really excited to implement this in our workflow! I wanted to show you the output of the above on one of my notebooks. im curious - is this a shell setting? it's different from when i just run it on the .py file from jupytext. it's more readable when i do it that way!
i have a lot of markdown text in my notebook which is why there are so many line to long errors. ruler to identify 79 line width doesn't work in markdown cells it seems. |
Hello @lwasser , thanks for your input.
|
The upcoming version 1.4.0 will slightly improve the output of
|
ahhhh @mwouts being able to lint and handle long lines has been an ongoing challenge in notebooks. I've been searching for a way to handle that. if jupytext could help with it, that would be wonderful. Would it be able to do it in a way that wouldn't impact markdown rendering? things like multi line "quotes I downloaded a ruler add on for labs last week and it didn't support version 2.0 so i couldn't play with it. but for notebook i can attest to the fact that you can not use ruler in markdown cells which makes flake8 unhappy. i'd love to be able to manage this more easily and to test for it too!! |
I've not had time to test this throughfully, but I think that
In my quick test, it was able to
Also, I see that I introduced a regression in the CLI, as the output of the piped command in Jupytext 1.4.0 is now displayed on the shell... I'll fix that soon. |
I use nbstripout pre-commit hook to clean the output of notebooks currently for habitat-sim. |
Now we can do this with the pre-commit hook. The documentation is not very verbose at the moment (we have plans to improve this), but we do have (tested) examples at e.g. https://github.com/mwouts/jupytext/blob/main/tests/test_pre_commit_5_reformat_markdown.py |
This was initially a question by @lwasser on Twitter: Is anyone using a tool that "cleans" or tests @ProjectJupyter notebooks for things like extra imports, PEP 8, etc etc?
It would be interesting to describe what we can do with
jupytext
at the command line, and also, what can be done with pre-commit hooks.Regarding the command line, Jupytext can pipe the Python representation of a notebook to another program, and either test it (e.g.
flake8
) or pipe it (e.g.black
)That works wells for the programs that read the standard input. For the others, one can use
{}
for a placeholder for a temporary file name. A good reference on what is know to work is this test file:https://github.com/mwouts/jupytext/blob/master/tests/test_black.py
I also think that one can use the pre-commit package to do this on every commit. I remember chatting about this with @phaustin at #142, where he mentioned that he was using Jupytext (through a custom Python script), together with
black
/ reorder_python_imports andflake8
.Maybe we could write a short blog post (or a
bash
notebook with examples...) to cover this?The text was updated successfully, but these errors were encountered: