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
Some fixes in IPython Sphinx directive #3298
Conversation
:meth:`IpythonDirective.setup` method was using a temporary file, such as :file:`/tmp/seen_docRANDOM`, for storing visited source document filenames. For a document that is not visited (name not in the temporary file), it restarts counting line numbers. Temporary file names are selected randomly and they were not deleted from the disk upon completion of a build. Since :meth:`.setup` picks a temp file arbitrarily to visited status of a file is determined incorrectly. Using a class variable resolves this problem. Changed the directive setup function to use a class files for keeping track of documents.
:meth:`EmbeddedSphinxShell.process_pure_python` could not process block of code with indentation correctly. For example, the following .. ipython:: python for i in range(10): if i < 5: continue else: pass would result in two IPython lines: In [19]: for i in range(10): ....: if i < 5: ....: continue ....: In [20]: else: ....: pass ....: This would raise various types of error, indentation/snytax, etc. To resolve this problem, added a simple check for indentation in the next line which normally start a new IPython line.
I don't really know anything about this code, @fperez could you have a look? |
Reviving this. I don't have much experience in sphinx. Someone else ? |
I'm happy to test this. But first -- Which project has ownership of this extension? Is it matplotlib or ipython? It would be nice for there to be only one place to post issues and submit fixes.
Even without this patch there are overlapping fixes. This is an important fix if it works. It's annoying to have to make sure that one's code only has at most one level. |
It belongs in IPython (and should move to library code). ref.#3352 |
In that case there probably should be two separate fixes -- one for the indentation issue (this one seems to include some fixes for other stuff too) and then another to add the fixes already in the matplotlib version AND move it to a place to it can be imported. Right now if you have matplotlib installed you can (sensibly) import "matplotlib.sphinxext.ipython_directive" in your conf.py. It seems like it would be useful to be able to do the same with ipython -- i.e., be able to import "IPython.sphinxext.ipython_directive" |
Yes, probably. Just answering your question about where ipython_directive should live.
Yes, that's what #3352 describes - the matplotlib ipython_directive will be removed, and IPython should move its version into |
I just tested the indentation fix. It works! Thanks @abakan. This has been bugging me for some time. The other changes appear to duplicate some fixes present in matplotlib's current version. Also -- as this patch contains a number of fixes, could it perhaps also include all the Python 3 fixes as well that are present in matplotlib? Or perhaps that should be a third issue? |
Sorry @abakan, I see what you've done with the class variable (vs. the tempfiles). Ignore what I said about duplicating code. It would be nice if it were Python 3 compatible. Maybe this could be tested by dropping it in as a replacement for matplotlib.sphinxext.ipython_directive and seeing if it builds? (Does anyone care about IPython docs building under Python 3?) |
@ariddell does 2to3 handle the Python 3 fixes? Because if so, there shouldn't need to be anything done (yet), because using this from IPython.sphinxext should work on Python 3 as well. If that's okay, then I think this can be merged as-is. |
It's definitely working fine for Python 2.7.3 and 3.3.0 (after running 2to3). Just tested again... Once this is committed I'm willing to work on the renaming patch. |
Thanks, merging. |
Some fixes in IPython Sphinx directive Made two fixes in plot_directive module: - a problem with interpreting pure python code with multiple levels of indentation - a problem with keeping track of visited files when restarting ipython line numbers
Some fixes in IPython Sphinx directive Made two fixes in plot_directive module: - a problem with interpreting pure python code with multiple levels of indentation - a problem with keeping track of visited files when restarting ipython line numbers
Made two fixes in plot_directive module: