From 82052838239187b0ec0e2b2b8911e5f6263491cf Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 16 Feb 2021 01:30:45 +0900 Subject: [PATCH 1/2] refactor: html: Fix typo --- sphinx/builders/html/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 1dbde6e371e..6a069c3cad1 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -1036,7 +1036,7 @@ def hasdoc(name: str) -> bool: # sort JS/CSS before rendering HTML ctx['script_files'].sort(key=lambda js: js.priority) - ctx['css_files'].sort(key=lambda js: js.priority) + ctx['css_files'].sort(key=lambda css: css.priority) try: output = self.templates.render(templatename, ctx) From 82501a6f6ff1e037d6f8fed12b257e8cdb9c34a7 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 15 Feb 2021 23:46:18 +0900 Subject: [PATCH 2/2] Fix #8885: html: AttributeError for CSS/JS files on html_context 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". --- CHANGES | 2 ++ sphinx/builders/html/__init__.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index bcad80274be..f666a5b16a9 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,8 @@ Bugs fixed ---------- * #8884: html: minified js stemmers not included in the distributed package +* #8885: html: AttributeError is raised if CSS/JS files are installed via + :confval:`html_context` * #8880: viewcode: ExtensionError is raised on incremental build after unparsable python module found diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 6a069c3cad1..c799b017671 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -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 css: css.priority) + try: + # Convert script_files to list to support non-list script_files (refs: #8889) + ctx['script_files'] = sorted(list(ctx['script_files']), key=lambda js: js.priority) + except AttributeError: + # Skip sorting if users modifies script_files directly (maybe via `html_context`). + # refs: #8885 + # + # Note: priority sorting feature will not work in this case. + pass + + try: + ctx['css_files'] = sorted(list(ctx['css_files']), key=lambda css: css.priority) + except AttributeError: + pass try: output = self.templates.render(templatename, ctx)