Skip to content
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

[ENH] Use Sphinx HTML assets policy to decide whether include assets #127

Closed

Conversation

humitos
Copy link
Contributor

@humitos humitos commented Jul 5, 2021

Sphinx v4.1.0 will include Sphinx.registry.html_assets_policy that defines the
policy to whether include or not HTML assets in pages where the extension is not
used.

This PR makes usage of this policy to decide if sphinx-tabs assets should be
included or not in the page that's being rendered.

Reference: sphinx-doc/sphinx#9115

@welcome
Copy link

welcome bot commented Jul 5, 2021

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.

Welcome to the EBP community! 🎉

@humitos humitos force-pushed the humitos/use-assets-policy branch from 7ae1b10 to 1b303ea Compare July 5, 2021 09:05
@humitos humitos changed the title Use Sphinx HTML assets policy to decide whether include assets [ENH] Use Sphinx HTML assets policy to decide whether include assets Jul 5, 2021
@humitos humitos force-pushed the humitos/use-assets-policy branch from 1b303ea to 8f68aaf Compare July 5, 2021 09:08
…sets

Sphinx v4.1.0 will include `Sphinx.registry.html_assets_policy` that defines the
policy to whether include or not HTML assets in pages where the extension is not
used.

This PR makes usage of this policy to decide if sphinx-tabs assets should be
included or not in the page that's being rendered.

Reference: sphinx-doc/sphinx#9115
Copy link
Collaborator

@foster999 foster999 left a comment

Choose a reason for hiding this comment

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

Thanks for the addition, this looks good to me.

Please could you run it through pre-commit and address the broken test? Then we can get it merged 👍🏻

sphinx.version_info[:2] >= (4, 1), reason="Test uses Sphinx 4.1 config"
)
def test_conditional_assets(app, docname, check_asset_links):
check_asset_links(app, filename=docname + ".html")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Test is currently failing - I think it should use the new sphinx API?

Suggested change
check_asset_links(app, filename=docname + ".html")
app.registry.html_assets_policy == "always"
check_asset_links(app, filename=docname + ".html")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I updated this test.

However, it kept failing because it seems the output is firstly generated by test_conditional_assets test (without app.set_html_assets_policy("always")) and the result is cached.

What should I do here? Create a new testroot= equal to conditionalassets?

NOTE: in an extension that I'm a maintainer, I'm cleaning the output's path after the test is ran to avoid this problem, see https://github.com/readthedocs/sphinx-hoverxref/blob/master/tests/conftest.py#L9 --maybe something like that is a good approach here as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, that looks spot on.

It looks like this is passing the CI tests now. I'm surprised though, given the issue that you describe using the same testroot. Is this failing locally for you?

If yes, please do create a separate root folder for this test. I like your fixture for cleaning up after tests, but do find the test outputs useful for debugging when the tests have failed (locally).

pre-commit is picking up on a couple of minor formatting issues below

@codecov
Copy link

codecov bot commented Jul 26, 2021

Codecov Report

Merging #127 (33e8075) into master (d921af3) will decrease coverage by 0.32%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #127      +/-   ##
==========================================
- Coverage   92.55%   92.23%   -0.33%     
==========================================
  Files           2        2              
  Lines         215      219       +4     
==========================================
+ Hits          199      202       +3     
- Misses         16       17       +1     
Flag Coverage Δ
pytests 92.23% <80.00%> (-0.33%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
sphinx_tabs/tabs.py 92.16% <80.00%> (-0.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d921af3...33e8075. Read the comment docs.

@foster999
Copy link
Collaborator

Thank @humitos, shall get the next version released including this change 😄

@foster999 foster999 closed this Aug 4, 2021
@humitos
Copy link
Contributor Author

humitos commented Aug 10, 2021

Thanks, @foster999 for continuing this work, and I'm sorry I wasn't able to make the latest required changes. I was on vacation 😃

@foster999
Copy link
Collaborator

No problem at all, hope you had a nice break! 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants