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
Update IPython directive #4570
Update IPython directive #4570
Conversation
For this PR and also for #4549, it would be nice to hear from @matplotlib that their docs build and are highlighted correctly still. I've done some testing, but they aren't nearly as comprehensive. |
Should we re-ping matplotlib ? open an issue on their side so that they check ? |
Probably the second option, to get more attention... |
I'm not sure I follow. matplotlib's documentation does not use the |
You do seem to still have ipython_directive and #3352 and related was done based on your suggestion. So I thought you were using IPython directive if IPython is availlable. |
Sorry, folks, and thanks for the reminder. Not enough coffee yesterday. I'll look into implementing using IPython's directives if they are available and see what, if anything, breaks. |
Yes, matplotlib still includes the |
OK, great thanks, no problem for the reminder I had to dig into issues to find it myself. |
Related -- this is a PR to use IPython's |
pandas is using the IPython directive in their docs if we want someone to test it. |
So we should ping @wesm I guess. (BTW, Wes if you read this, I had to export some data for biologists, I love you for having a |
I think other people do a lot of the development on pandas now, but I'm not sure who's most relevant. Maybe @jorisvandenbossche , who updated ipython_directive a few months ago. Or maybe one of us should just grab the pandas repo, substitute in the IPython directive extension from this PR, and try building the docs. I have a checkout of pandas, I can probably give that a try later. |
I can try it later this weekend to build the pandas docs with this, but at the moment we are not using the IPython's sphinx extension itself, but an older and in the meanwhile slightly adapted version included in pandas source. See pandas-dev/pandas#5221 for some discussion about using IPython's instead our own version. For most of the docs this already works (eg not for the cython doc page, as for this the directive was adapted). So I can give it a try. |
Thanks Joris. If it's not too difficult to merge pandas' changes with the changes here and check that it still builds OK, that would be good. |
I tried it out, and I don't see more problems with this PR than with version in master :-) So for me, this PR is OK (but I didn't really look at the code and I didn't test the doctest part, as this is not used in pandas). However I have the following remark:
|
I'll take a look at pandas-dev/pandas#5221 in the next day or so. There are also a few other things I'd like to do before this is merged (holidays have distracted me). Regarding the options, I'm happy to change them to whatever is decided upon. My rationale for having the import * was only because it was in there already. I'd be just as happy setting the default to an empty list, but if we are to have a default, then I'm definitely in agreement on the starred-import: it should be discouraged. My suggestion for As for defaults, that's a good idea. I'll make the change. Also, I'll probably make a non-backend require the string 'none', and change it so that |
…xeclines. When specified as `None` in conf.py, this is treated the same as if not specified in conf.py at all.
If this and #4549 are still open on Monday, I'll do another quick sanity check on them, then take a merge-em-and-see-who-complains approach. If anyone disagrees, you've got the weekend to let me know. ;-) |
👍 to both |
👍 too |
|
||
return savefig_dir, source_dir, rgxin, rgxout, promptin, promptout | ||
if mplbackend is None: | ||
mplbackend = 'agg' |
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.
In the explanation of ipython_mplbackend
, you now state that if None, nothing is imported. Does this not contradict with this? Or do I miss something?
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.
Opps. That shouldn't be there as of now, but given @mdboom's comment, something like the above will probably stay.
I tested it, and it seems good! The issue with the |
Yeah its a strange bug. Let's punt on that for now and I'll file a bug report. |
I wonder if something is adding the spaces to line up the |
@@ -0,0 +1,108 @@ | |||
""" | |||
Module containing custom doctests. |
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.
'Module containing' is superfluous, but in what way are the doctests custom?
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.
Addressed in d9d261d
Checked the diff as of 311596d, and there's nothing obviously amiss. |
Here is a document that keeps n below 10 but still has the problem: http://docs.dit.io/en/latest/measures/total_correlation.html Here is another that lets n go above 10 but does not have the problem: http://docs.dit.io/en/latest/generalinfo.html If I take out some documents from the build process, documents which had the problem cease to have the problem. Def need a minimal example. |
@takluyver No, it was with the 10min page of the pandas docs, so prompt numbering goes even above hundred. What is special about this page, is that is the first page that is build by sphinx (that's the only thing I can think of at the moment). @chebee7i The generalinfo page which also does not have the problem, is also the first page with ipython directives in it that is built I think, is that correct? |
Ah, I bet the prompt numbering is being reset, but not the prompt justification - so if a previous page has gone to @chebee7i : do you still want to leave that for another PR, or try to fix it in this? |
Could it maybe something like this: Once the prompt number has been above 100 (for pandas docs, or above 10 for This seems a little bit logical with what I see in the results, however I totally don't know how this could be explained technically. As it just captures the shells stdout, I don't see how this could happen, but I am not really familiar with this. |
@takluyver Ah, I didn't see your new comment. But seems I was thinking in the right direction :-) |
The relevant bit of code is here: https://github.com/ipython/ipython/blob/master/IPython/core/prompts.py#L436 So I guess that, when you reset the execution count, you also need to reset |
I can confirm this does the trick! |
…aligned Out prompts
This commit jorisvandenbossche@1fbc5f6 solves the issue (@chebee7i I did sent it as a PR to your branch, I don't know exactly how it works). |
Set prompt_manager.width to zero for each new document to prevent misaligned Out prompts
Nice job on finding the fix! I merged it and also added a new option |
Thanks @chebee7i and @jorisvandenbossche . I'm going to merge this. Feel free to file more pull requests if you find problems. |
@chebee7i Are you working on some of these things? I maybe have some time to try to get the |
@jorisvandenbossche not currently working on it. So if you have the time, go for it. |
Update IPython directive
Here are a number of updates to the IPython directive:
matplotlib is now optional (but on by default). This is configurable through an extension parameter
ipython_mplbackend
. The backend is also configurable, default is'agg'
.The intent of the directive was to automatically add NumPy and pylab to the namespace. This broke recently, but has been fixed. It is also configurable now via the extension parameter
ipython_execlines
. Would it be okay to update the default to include pyplot?For @doctests within the IPython directive, it can be helpful to fuzzy compare for equality of output. Even if the calculation is performed with a known seed (in the case of stochastic dependence), if the test was written on a slightly different version of software, there could be very small differences which would cause the test to fail. The user can now do:
And this will count as a valid test. The rendered output will display:
0.30000000000000004
. A 2nd and 3rd argument specify thertol
andatol
passed tonp.allclose
(both are required if specified at all). This handles infs, nans, higher dimensional arrays, etc. in very basic scenarios---those you'd expect to run across with documentation examples.Some additional documentation is still needed, and there's another bug I've found that still needs fixing.