You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate why some examples build properly in our gallery despite using numpy and not importing it explicitely. #8235
A recent pull request fixed an import problem in one of our pull request. The example was missing numpy, despite using it. After investigating, the example did generate the plot properly, suggesting some kind of hidden import somewhere.
The plot_directive Sphinx extension imports both NumPy and Matplotlib, by default. Great for inline code examples, maybe not so great for auto-generated-from-standalone examples.
I am 👎 on deprecating this. The plot directive is very useful for in-line plots where reducing boiler plate is generally good and changing this is going to cause a bunch of work for down-stream users.
If we were writing it now no default imports would be reasonable, but it has been this way from 2010 (6f2860f) and I don't see the payoff being worth the down-stream cost.
If we want to be strict in our docs, add a 'strict' flag that disables the imports (or just pass an empty string into plot_pre_code in the templates we use to generate the gallery).
If we finish the migration to sphinx-gallery, I don't think this function will be necessary anymore.
Anyhow, we know why we have some examples that run inside our galleries and outside, so I suggest closing this ticket.
Activity
QuLogic commentedon Mar 8, 2017
The
plot_directiveSphinx extension imports both NumPy and Matplotlib, by default. Great for inline code examples, maybe not so great for auto-generated-from-standalone examples.NelleV commentedon Mar 8, 2017
I suspected something like this… I guess it is a really good thing no one else than matplotlib uses the plot_directive.
anntzer commentedon Mar 8, 2017
If no one uses it perhaps we should just not add that header anymore :-)
anntzer commentedon Mar 8, 2017
If someone fixes that file, two more easy fixes:
_dummy_printis probably not useful as we already redirectsys.stdout.try: try: ... except: ... finally: ...can be flattened into a singletry: ... except: ... finally: ...(since py2.5... pep341)tacaswell commentedon Mar 8, 2017
I use the plot directive quite a bit in my day-job docs and it is in both the numpy and scipy docs.
Suspect the fix here is to make sure this file is run by the backend-driver test.
anntzer commentedon Mar 8, 2017
I would rather deprecate this.
You can do something like
tacaswell commentedon Mar 8, 2017
I am 👎 on deprecating this. The plot directive is very useful for in-line plots where reducing boiler plate is generally good and changing this is going to cause a bunch of work for down-stream users.
If we were writing it now no default imports would be reasonable, but it has been this way from 2010 (6f2860f) and I don't see the payoff being worth the down-stream cost.
If we want to be strict in our docs, add a 'strict' flag that disables the imports (or just pass an empty string into plot_pre_code in the templates we use to generate the gallery).
anntzer commentedon Mar 8, 2017
plot_pre_code is exactly there to avoid the need for boilerplate.
NelleV commentedon Mar 11, 2017
If we finish the migration to sphinx-gallery, I don't think this function will be necessary anymore.
Anyhow, we know why we have some examples that run inside our galleries and outside, so I suggest closing this ticket.
choldgraf commentedon Jul 15, 2017
@NelleV can you close this? I think that this issue is resolved since sphinx-gallery is building all of the examples etc.