-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Add preprocessor to execute notebooks #5639
Conversation
I also shut down the kernel in |
self.km = KernelManager() | ||
# run %pylab inline, because some notebooks assume this | ||
# even though they shouldn't | ||
self.km.start_kernel(extra_arguments=['--pylab=inline'], stderr=open(os.devnull, 'w')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it definitely should not start with --pylab=inline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for making it an option; it should handle --matplotlib=inline
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it should handle neither.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, I somehow misinterpreted your comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be an option, defaulting to no arguments. As much as we might like everyone to never run the notebook with --pylab inline
, people do run it with arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issues is in 3.0, starting notebook server with --pylab=inline
will not work. So kernel started with --pylab=inline
in nbconvert will make no sens. The only thing that will make sens is chosing the kernel you want to use to run the notebook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not handle the --pylab option... I agree...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. What would be the best way to make it possible to run it with %pylab inline
or %matplotlib inline
that would work in 3.0?
Thanks @Carreau for pointing me here. @jvns feel free to test with the runipy test suite. It's small but covers basically everything that was broken in the original runipy and later fixed: https://github.com/paulgb/runipy/tree/master/tests I'm happy to see this behaviour making its way into IPython! |
hum, Travis seem unhappy because of pandoc. restarting it. |
Travis still seem to get the wrong pandoc... wondering why... restarting again. |
Hi I'm very glad to see this functionality making its way into IPython. I would just like to ask whether this design will allow me to batch run notebooks from the commandline? So far I have not found a decent way to automatically run notebooks so that display hooks are run properly and that the resulting notebook is saved back to disk (with the fresh display output). This is very important to me as a Topographica developer as that project is now making heavy use of notebooks and we need this type of automation for testing purposes. My unsatisfactory solution has been to hack my own copy of runipy (which was a very helpful starting point) to load our custom IPython profile, run a %load_ext command (with shell.execute) and then save the result on completion to a new .ipynb file. I am eager to see that this execute preprocessor can help me to avoid such hackery in IPython 3.0! Thank you |
I have to check, but IIRC not yet, there are still a few missing pieces in nbconvert. In 3.0 I would say probably. |
|
Okay, I added the tests from runipy (thanks @paulgb!), and fixed the issues @minrk pointed out (thanks!). Are there more issues blocking this? I'd like to make it possible in some way to run notebooks with |
The Travis build seems to be failing but I think that's because of pandoc. |
This should already work as long as the %matplotlib magic is called in the notebook itself. If that is not in the notebook, then the notebook shouldn't be expecting inline figures. |
The tests are failing because your test files aren't installed. I think you will need to add a glob to setupbase.find_package_data. |
what does "your test files aren't installed" mean? |
so I agree that it shouldn't be expecting inline figures, but in real life lots of people have notebooks that they've created with |
Sorry, files that don't end with '.py' in the source tree are not installed by default. You have to tell Python to install things things via a structure called 'package_data', which is populated in setupbase.find_package_data. You will need to add file globs for the new test files you have added here, in order for them to be included in an install of IPython. |
I changed |
import os | ||
import sys | ||
|
||
from Queue import Empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is queue
on Python 3.
I'm really excited to see this becoming a preprocessor! 👍 I was playing around with it a bit, and found that the prompt number actually isn't being updated in the notebook. I think rather than checking if the message type is Happy to submit a pull request to your branch @jvns if you'd like! |
yes please!
|
Set input/output cell prompt numbers
Just to say I've just tested out this PR and it largely works as I hoped. Unfortunately, I notice that sometimes the ordering of output is wrong with output appearing underneath an unrelated code cell. Otherwise, I'm looking forward to using this as soon as it is merged! |
@jvns can you rebase the PR? There are going to need to be a few changes due to recent things in the message spec, but the PR needs to be based on the latest master, first. If not, I can do the rebase. |
Sorry, that was for @jvns. |
I'm a bit swamped right now and probably won't get to this for a bit =\ |
I've rebased this and added the necessary changes for msg spec 5 in #6053. |
Merged as #6053. Thanks! |
Add execute preprocessor closes ipython#5639
This adds a preprocessor to execute all the code cells in a notebook.
I basically copied all of this code from @damianavila's gist here: https://gist.github.com/damianavila/5208296.
I don't totally understand all of the error handling. This probably wants more robust unit tests, but I'm not sure exactly what I should be testing.