Skip to content

Commit

Permalink
Restore hidden pass-through calls when adding asset files
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Aug 17, 2023
1 parent ab71cc5 commit 0c22d9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Bugs fixed
* Restored the the :py:class:`str` interface of the asset classes
(``_CascadingStyleSheet`` and ``_JavaScript``), which several extensions relied upon.
This will be removed in Sphinx 9.
* Restored calls to ``Builder.add_{css,js}_file()``,
which several extensions relied upon.

Testing
-------
Expand Down
9 changes: 9 additions & 0 deletions sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations

import contextlib
import os
import pickle
import sys
Expand Down Expand Up @@ -1033,6 +1034,10 @@ def add_js_file(self, filename: str | None, priority: int = 500,
kwargs['defer'] = 'defer'

self.registry.add_js_file(filename, priority=priority, **kwargs)
with contextlib.suppress(AttributeError):
self.builder.add_js_file( # type: ignore[attr-defined]
filename, priority=priority, **kwargs,
)

def add_css_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None:
"""Register a stylesheet to include in the HTML output.
Expand Down Expand Up @@ -1093,6 +1098,10 @@ def add_css_file(self, filename: str, priority: int = 500, **kwargs: Any) -> Non
"""
logger.debug('[app] adding stylesheet: %r', filename)
self.registry.add_css_files(filename, priority=priority, **kwargs)
with contextlib.suppress(AttributeError):
self.builder.add_css_file( # type: ignore[attr-defined]
filename, priority=priority, **kwargs,
)

def add_latex_package(self, packagename: str, options: str | None = None,
after_hyperref: bool = False) -> None:
Expand Down
6 changes: 4 additions & 2 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ def add_css_file(self, filename: str, **kwargs: Any) -> None:
if '://' not in filename:
filename = posixpath.join('_static', filename)

self._css_files.append(_CascadingStyleSheet(filename, **kwargs))
if (asset := _CascadingStyleSheet(filename, **kwargs)) not in self._css_files:
self._css_files.append(asset)

@property
def script_files(self) -> list[_JavaScript]:
Expand Down Expand Up @@ -348,7 +349,8 @@ def add_js_file(self, filename: str, **kwargs: Any) -> None:
if filename and '://' not in filename:
filename = posixpath.join('_static', filename)

self._js_files.append(_JavaScript(filename, **kwargs))
if (asset := _JavaScript(filename, **kwargs)) not in self._js_files:
self._js_files.append(asset)

@property
def math_renderer_name(self) -> str | None:
Expand Down

0 comments on commit 0c22d9c

Please sign in to comment.