Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Optional flag to defer figure scraping to the next code block #801

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

Merged
merged 3 commits into from
Mar 21, 2021

Conversation

ayshih
Copy link
Contributor

@ayshih ayshih commented Mar 17, 2021

Closes #363

This PR adds an optional flag for a code block to defer figure scraping to the next code block. If the code-block executor sees the comment # sphinx_gallery_defer_figures, it will not run save_figures() to scrape figures, and any figures are left open for the next code block. Thus, it becomes possible to interleave text blocks between multiple code blocks of plotting commands, with no figures being shown until after the desired code block.

The flag gets stripped out along with the usual config comments (e.g., # sphinx_gallery_thumbnail_number = N).

Here's a rendered example:
defer
where the first code block is:

plt.plot([1,2,3,4,5])
plt.plot([5,4,3,2,1])
# sphinx_gallery_defer_figures

This needs documentation and tests, of course, but I wanted feedback first.

@larsoner
Copy link
Contributor

I have definitely wanted something like this before. It looks like there is a failure on Sphinx dev but this might be Sphinx's fault...

It would be good to add a test for this somewhere, though. Maybe in test_gen_rst.py?

@ayshih ayshih force-pushed the defer branch 2 times, most recently from 8d90d43 to ac3adfb Compare March 17, 2021 23:38
@ayshih
Copy link
Contributor Author

ayshih commented Mar 18, 2021

Okay, documentation and tests added, and all checks are green aside from Sphinx dev

@ayshih ayshih marked this pull request as ready for review March 18, 2021 00:40
Copy link
Contributor

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1 for merge

@lucyleeow do you want to look and merge if you're happy?

@lucyleeow
Copy link
Contributor

Will take a look this weekend, thanks @larsoner

@lucyleeow
Copy link
Contributor

Did we want to do something about the sphinx dev fail? Is it possible to mark xfail if sphinx is a certain version?

@larsoner
Copy link
Contributor

Did we want to do something about the sphinx dev fail?

Someone should probably look in a separate PR to see why it fails. For example maybe they added another class to the CSS, so we just need to update. Or they removed one and it's not backward compatible and we need to open an issue with them.

It sounds like you might be volunteering to look @lucyleeow ? :)

Copy link
Contributor

@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, very useful, thanks @ayshih ! One small nitpick about the docs, but I'm open to it staying there.

doc/advanced.rst Outdated
plt.show()

If config comments are requested to be removed from rendered output (see
:ref:`removing_config_comments`), these flag comments will be removed as well.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer this to be in the configuration.rst file (maybe above the 'image_scrapers' section) - it seems to fit with the things there and I think it would be a 'common' usage of Sphinx (rather than 'advanced' usage)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I moved the documentation (to below "Image scrapers", since that is the first mention of scraping)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

@lucyleeow
Copy link
Contributor

It sounds like you might be volunteering to look @lucyleeow ? :)

It's on my todo!

@lucyleeow lucyleeow merged commit 08efd05 into sphinx-gallery:master Mar 21, 2021
@ayshih ayshih deleted the defer branch March 17, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delay output capturing to a further code block
3 participants