Skip to content

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

Closed

Description

@NelleV

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

Activity

  1. QuLogic commented on Mar 8, 2017

    @QuLogic
    Member

    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.

  2. NelleV commented on Mar 8, 2017

    @NelleV
    MemberAuthor

    I suspected something like this… I guess it is a really good thing no one else than matplotlib uses the plot_directive.

  3. anntzer commented on Mar 8, 2017

    @anntzer
    Contributor

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

  4. anntzer commented on Mar 8, 2017

    @anntzer
    Contributor

    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)
  5. tacaswell commented on Mar 8, 2017

    @tacaswell
    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.

  6. added this to the milestone on Mar 8, 2017
  7. anntzer commented on Mar 8, 2017

    @anntzer
    Contributor

    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.
  8. tacaswell commented on Mar 8, 2017

    @tacaswell
    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).

  9. anntzer commented on Mar 8, 2017

    @anntzer
    Contributor

    plot_pre_code is exactly there to avoid the need for boilerplate.

  10. NelleV commented on Mar 11, 2017

    @NelleV
    MemberAuthor

    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.

  11. modified the milestones: , on May 3, 2017
  12. choldgraf commented on Jul 15, 2017

    @choldgraf
    Contributor

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

  13. modified the milestones: , on Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions