Skip to content

Investigate why some examples build properly in our gallery despite using numpy and not importing it explicitely. #8235

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

Closed
NelleV opened this issue Mar 8, 2017 · 10 comments
Milestone

Comments

@NelleV
Copy link
Member

NelleV commented Mar 8, 2017

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.

Here is a link on the build example (Matplotlib 2.0.0)
http://matplotlib.org/examples/mplot3d/pathpatch3d_demo.html

@QuLogic
Copy link
Member

QuLogic commented Mar 8, 2017

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.

@NelleV
Copy link
Member Author

NelleV commented 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
Copy link
Contributor

anntzer commented Mar 8, 2017

If no one uses it perhaps we should just not add that header anymore :-)

@anntzer
Copy link
Contributor

anntzer commented Mar 8, 2017

If someone fixes that file, two more easy fixes:

  • I think the meddling with _dummy_print is probably not useful as we already redirect sys.stdout.
  • the try: try: ... except: ... finally: ... can be flattened into a single try: ... except: ... finally: ... (since py2.5... pep341)

@tacaswell
Copy link
Member

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.

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Mar 8, 2017
@anntzer
Copy link
Contributor

anntzer commented Mar 8, 2017

I would rather deprecate this.

You can do something like

  • try to run without the imports
  • if it fails, try to run with the imports and raise a deprecationwarning if that works.

@tacaswell
Copy link
Member

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
Copy link
Contributor

anntzer commented Mar 8, 2017

plot_pre_code is exactly there to avoid the need for boilerplate.

@NelleV
Copy link
Member Author

NelleV commented 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.

@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017
@choldgraf
Copy link
Contributor

@NelleV can you close this? I think that this issue is resolved since sphinx-gallery is building all of the examples etc.

@QuLogic QuLogic modified the milestones: 2.1 (next point release), 2.1.1 (next bug fix release) Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants