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

Fix #8885: html: AttributeError for CSS/JS files on html_context #8893

Merged
merged 2 commits into from Feb 16, 2021

Conversation

tk0miya
Copy link
Member

@tk0miya tk0miya commented Feb 15, 2021

Feature or Bugfix

  • Bugfix

Purpose

ctx['script_files'].sort(key=lambda js: js.priority)
ctx['css_files'].sort(key=lambda js: js.priority)
try:
ctx['script_files'].sort(key=lambda js: js.priority)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this PR but you may consider just using something like

Suggested change
ctx['script_files'].sort(key=lambda js: js.priority)
get_priority = operator.attrgetter('priority')
ctx['script_files'].sort(key=get_priority)

in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1: I'll do it later.

@tk0miya tk0miya force-pushed the 8885_AttributeError_html_context branch from 5161d87 to 6bcc9c0 Compare February 15, 2021 16:32
@tk0miya tk0miya force-pushed the 8885_AttributeError_html_context branch from 6bcc9c0 to 4901324 Compare February 15, 2021 16:54
…ntext

Since 3.5.0, priority has been added to control CSS/JS files.  But it's
not working if projects installs custom CSS/JS files via `html_context`
instead of `html_css_files` and `html_js_files`.  This avoids the crash
to keep it "not broken".
@tk0miya tk0miya force-pushed the 8885_AttributeError_html_context branch from 4901324 to 82501a6 Compare February 15, 2021 16:55
# refs: #8885
#
# Note: priority sorting feature will not work in this case.
pass
Copy link
Member Author

Choose a reason for hiding this comment

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

Finally, I determined to keep the list as is and not emitting a warning. It means priority sort will not work. But no extensions do not use it yet.
And I'll deprecate html_context['*_files]' in another step to migrate to html_*_files.

@@ -1035,8 +1035,20 @@ def hasdoc(name: str) -> bool:
templatename = newtmpl

# sort JS/CSS before rendering HTML
ctx['script_files'].sort(key=lambda js: js.priority)
ctx['css_files'].sort(key=lambda js: js.priority)
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI Python 3 has this nice pattern for such cases:

Suggested change
try:
with contextlib.suppress(AttributeError):

@tk0miya tk0miya merged commit 66539af into sphinx-doc:3.5.x Feb 16, 2021
@tk0miya tk0miya deleted the 8885_AttributeError_html_context branch February 16, 2021 11:37
jschwab added a commit to MESAHub/mesa that referenced this pull request Feb 17, 2021
This adds a css file via the html_css_files option introduced in
Sphinx 1.8.  Our current use of html_context is broken in Sphinx
3.5.0.  It looks like they are going to fix that in
3.5.1 (sphinx-doc/sphinx#8893), but since the
modern way seems clearer, I switched to it.
jschwab added a commit to MESAHub/mesa that referenced this pull request Feb 17, 2021
This adds a css file via the html_css_files option introduced in
Sphinx 1.8.  Our current use of html_context is broken in Sphinx
3.5.0.  It looks like they are going to fix that in
3.5.1 (sphinx-doc/sphinx#8893), but since the
modern way seems clearer, I switched to it.
jschwab added a commit to MESAHub/mesa that referenced this pull request Feb 17, 2021
This adds a css file via the html_css_files option introduced in
Sphinx 1.8.  Our current use of html_context is broken in Sphinx
3.5.0.  It looks like they are going to fix that in
3.5.1 (sphinx-doc/sphinx#8893), but since the
modern way seems clearer, I switched to it.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants