Skip to content

DOC: Suppress IPython output in examples and tutorials where not needed #23978

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 1 commit into from
Sep 23, 2022

Conversation

StefRe
Copy link
Contributor

@StefRe StefRe commented Sep 21, 2022

PR Summary

By default, sphinx-gallery captures the last output of each code block and shows it in the generated html in yellow boxes. Especially in tutorials with frequently interleaving code and text blocks this may appear confusing and reduces readability. In some cases, however, the output is desired (although it could always be replaced by printing).

The global configuration is now changed to "capture nothing", for one tutorial with multiple desired outputs this is overridden in the file to show the output and in other cases with just one desired output it's converted to a call to print().

(I went through all the examples and tutorials by searching the generated rst files for .. rst-class:: sphx-glr-script-out to see if we need the generated output, hopefully I didn't overlook some desired output)

This PR addresses this #21794 (comment):

I won't object if someone has a way to suppress these via configuration. However, note that some of our examples want the output to show up, so it can't be global.

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • [N/A] Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

By default, sphinx-gallery captures the last output of each code block
and shows it in the generated html in yellow boxes. Especially in
tutorials with a frequently interleaving code and text blocks this may
appear confusing and reduces readability. In some cases, however, the
output is desired (although it could always be replaced by printing).

The global configuration is now changed to "capture nothing", for one
tutorial with multiple desired outputs this is overridden in the file
to show the output and in other cases with just one desired output
it's converted to a call to print().
@tacaswell tacaswell added this to the v3.7.0 milestone Sep 21, 2022
@tacaswell
Copy link
Member

I am very surprised that we only had ~2 cases where the output was valuable and intentials.

I'm inclined to merge but not back port this so we have a while for any issues to be found in the devdocs.

@StefRe
Copy link
Contributor Author

StefRe commented Sep 21, 2022

I am very surprised that we only had ~2 cases where the output was valuable and intentials.

Me too - if I had known earlier I wouldn't have made sphinx-gallery/sphinx-gallery#891. It turned out, however, that practically in all cases, where the output is intentional, it was already produced by print (or by error messages). The remaining cases were ~95 % Line2D, Legend or Text.

@timhoffm
Copy link
Member

I'm also surprised, but this

I turned out, however, that practically in all cases, where the output is intentional, it was already produced by print (or by error messages)

makes sense.

I'm inclined to merge but not back port this so we have a while for any issues to be found in the devdocs.

Do we read the devdocs so thoroughly that we would find possible issues? While I do a lot of docs stuff, I would not claim for me that I would find a significant fraction of such issues if they existed. I therefore would be happy to backport.

@tacaswell tacaswell modified the milestones: v3.7.0, v3.6.1 Sep 22, 2022
@tacaswell tacaswell merged commit 269c0b9 into matplotlib:main Sep 23, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 23, 2022
@StefRe StefRe deleted the DOC/no-capture branch September 23, 2022 07:01
timhoffm added a commit that referenced this pull request Sep 23, 2022
…978-on-v3.6.x

Backport PR #23978 on branch v3.6.x (DOC: Suppress IPython output in examples and tutorials where not needed)
@ksunden ksunden mentioned this pull request Feb 20, 2023
6 tasks
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.

3 participants