-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix #8885: html: AttributeError for CSS/JS files on html_context #8893
Conversation
892fcf3
to
3ae9483
Compare
sphinx/builders/html/__init__.py
Outdated
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) |
There was a problem hiding this comment.
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
ctx['script_files'].sort(key=lambda js: js.priority) | |
get_priority = operator.attrgetter('priority') | |
ctx['script_files'].sort(key=get_priority) |
in the future.
There was a problem hiding this comment.
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.
5161d87
to
6bcc9c0
Compare
6bcc9c0
to
4901324
Compare
…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".
4901324
to
82501a6
Compare
# refs: #8885 | ||
# | ||
# Note: priority sorting feature will not work in this case. | ||
pass |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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:
try: | |
with contextlib.suppress(AttributeError): |
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.
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.
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.
Feature or Bugfix
Purpose
not working if projects installs custom CSS/JS files via
html_context
instead of
html_css_files
andhtml_js_files
. This avoids the crashto keep it "not broken".
AttributeError: 'str' object has no attribute 'priority'
in Sphinx 3.5.0 #8885