Skip to content

FIX: Avoid copying source script when plot_html_show_source_link is False in plot directive #20814

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 7 commits into from
Aug 19, 2021

Conversation

harupy
Copy link
Contributor

@harupy harupy commented Aug 9, 2021

PR Summary

In the plot directive, if plot_html_show_source_link is False, it's not necessary to copy the source scripts (sorry if I'm missing something). This change slightly decreases disk usage.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@harupy harupy closed this Aug 9, 2021
@harupy harupy reopened this Aug 9, 2021
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@tacaswell
Copy link
Member

This seems reasonable and correct to me.

Could you possibly add a few more asserts to https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/tests/test_sphinxext.py to make sure the source is and is not copied in the relevant cases?

The rst we are running against is https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/tests/tinypages/some_plots.rst

@tacaswell
Copy link
Member

Thank you for working on this and welcome 😄 (sorry should have lead with that!).

@harupy
Copy link
Contributor Author

harupy commented Aug 11, 2021

@tacaswell Added a few asserts. Could you take another look?

Comment on lines 103 to 104
# `plot_html_show_source_link=0` is equivalent to
# `plot_html_show_source_link=False`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

# `plot_html_show_source_link=False`
build_sphinx_html(source_dir, doctree_dir, html_dir,
extra_args=["-D", "plot_html_show_source_link=0"])
assert "some_plots-1.py" not in [p.name for p in html_dir.iterdir()]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I make this more strict?

@tacaswell
Copy link
Member

This seems reasonable, however I have a concern that this is going to add time to the test process as tinypages was already the slowest test:

On a recent default-branch run:

https://github.com/matplotlib/matplotlib/runs/3301881275?check_suite_focus=true#step:12:149

29.61s call     lib/matplotlib/tests/test_sphinxext.py::test_tinypages

and on this PR https://github.com/matplotlib/matplotlib/pull/20814/checks?check_run_id=3301939622#step:12:149

36.72s call     lib/matplotlib/tests/test_sphinxext.py::test_tinypages

I assume we are hitting some caching in sphinx so the second run does not double the run time, but are still adding 5s (I'm a bit torn how much to trust these times though as CI runtime is notoriously variable).

I think it would be better to add another plot to the example file?

@harupy
Copy link
Contributor Author

harupy commented Aug 12, 2021

I think it would be better to add another plot to the example file?

plot_html_show_source_link is a global configuration, not a directive-level configuration, so I don't think we can do something like:

.. plot::
     :show_source_link: False
     
     # code

Can we create a directory containing an RST file, perform sphinx-build against this directory with plot_html_show_source_link =True, and then assert a source script has not been created?

Signed-off-by: harupy <hkawamura0130@gmail.com>
@tacaswell
Copy link
Member

plot_html_show_source_link is a global configuration, not a directive-level configuration,

🐑 Sorry for being wrong about that and pushing you to test something impossible!

harupy and others added 2 commits August 13, 2021 09:51
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@harupy harupy requested a review from QuLogic August 13, 2021 22:37
@harupy
Copy link
Contributor Author

harupy commented Aug 19, 2021

@QuLogic Could you take another review?

@QuLogic QuLogic merged commit 64619e5 into matplotlib:master Aug 19, 2021
@QuLogic QuLogic added this to the v3.5.0 milestone Aug 19, 2021
@QuLogic
Copy link
Member

QuLogic commented Aug 19, 2021

Thanks @harupy! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

@harupy harupy deleted the save-script-if-necessary branch August 19, 2021 07:13
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