Skip to content

Commit

Permalink
fix compatibility with Sphinx v7.2.0
Browse files Browse the repository at this point in the history
fixes #277 along with other problems found with v7.2.0 changes.
  • Loading branch information
2bndy5 committed Aug 18, 2023
1 parent 9adb3f1 commit 797b666
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Expand Up @@ -148,6 +148,7 @@ jobs:
- 'sphinx4'
- 'sphinx5'
- 'sphinx6'
- 'sphinx7'
node-version:
- '16.x'
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 3 additions & 1 deletion noxfile.py
Expand Up @@ -200,7 +200,9 @@ def docs(session: nox.Session, builder: str):

@nox.session(python=SUPPORTED_PY_VER)
@nox.parametrize(
"sphinx", [">=4.5,<5", ">=5,<6", ">=6,<7"], ids=["sphinx4", "sphinx5", "sphinx6"]
"sphinx",
[">=4.5,<5", ">=5,<6", ">=6,<7", ">=7,<8"],
ids=["sphinx4", "sphinx5", "sphinx6", "sphinx7"],
)
def tests(session: nox.Session, sphinx: str):
"""Run unit tests and collect code coverage analysis."""
Expand Down
43 changes: 34 additions & 9 deletions sphinx_immaterial/__init__.py
Expand Up @@ -15,13 +15,17 @@
import sphinx.util.matching
import sphinx.util.docutils
import sphinx.writers.html5
from sphinx import version_info

from . import html_translator_mixin
from .apidoc import apidoc_formatting
from .apidoc import fix_sphinx_issue_11147 # pylint: disable=unused-import
from . import nav_adapt
from . import sections # pylint: disable=unused-import

if version_info < (7, 2):
import sphinx.builders.html._assets

logger = sphinx.util.logging.getLogger(__name__)


Expand All @@ -44,7 +48,10 @@ def _get_html_builder(base_builder: Type[sphinx.builders.html.StandaloneHTMLBuil
"""Returns a modified HTML translator."""

class CustomHTMLBuilder(base_builder): # type: ignore
css_files: List[sphinx.builders.html.Stylesheet]
if version_info < (7, 2):
css_files: List[sphinx.builders.html.Stylesheet]
else:
_css_files: List[sphinx.builders.html._assets._CascadingStyleSheet]
theme: sphinx.theming.Theme
templates: sphinx.jinja2glue.BuiltinTemplateLoader

Expand All @@ -71,9 +78,14 @@ def init_js_files(self):
if nav_adapt.READTHEDOCS is None:
excluded_scripts.add("_static/jquery.js")
excluded_scripts.add("_static/_sphinx_javascript_frameworks_compat.js")
self.script_files: List[sphinx.builders.html.JavaScript] = [
x for x in self.script_files if x.filename not in excluded_scripts
]
if version_info < (7, 2):
self.script_files: List[sphinx.builders.html.JavaScript] = [
x for x in self.script_files if x.filename not in excluded_scripts
]
else:
self._js_files: List[sphinx.builders.html._assets._JavaScript] = [
x for x in self._js_files if x.filename not in excluded_scripts
]

def init_css_files(self):
super().init_css_files()
Expand All @@ -87,11 +99,24 @@ def init_css_files(self):
"_static/basic.css",
]
)
self.css_files = [
x
for x in cast(List[sphinx.builders.html.Stylesheet], self.css_files)
if x.filename not in excluded
]
if version_info < (7, 2):
self.css_files = [
x
for x in cast(
List[sphinx.builders.html.Stylesheet],
self._css_files,
)
if x.filename not in excluded
]
else:
self._css_files = [
x
for x in cast(
List[sphinx.builders.html._assets._CascadingStyleSheet],
self._css_files,
)
if x.filename not in excluded
]

def gen_additional_pages(self):
# Prevent the search.html page from being written since this theme provides
Expand Down
Expand Up @@ -352,9 +352,10 @@ def _monkey_patch_python_domain_to_transform_xref_titles():
def type_to_xref(
target: str,
env: sphinx.environment.BuildEnvironment,
*args,
suppress_prefix: bool = False,
) -> sphinx.addnodes.pending_xref:
node = orig_type_to_xref(target, env, suppress_prefix)
node = orig_type_to_xref(target, env, *args, suppress_prefix=suppress_prefix)
if (
not suppress_prefix
and len(node.children) == 1
Expand Down
2 changes: 1 addition & 1 deletion sphinx_immaterial/postprocess_html.py
Expand Up @@ -38,7 +38,7 @@ def create_sitemap(app: sphinx.application.Sphinx, exception):
):
return

filename = app.outdir + "/sitemap.xml"
filename = str(app.outdir) + "/sitemap.xml"
print(
"Generating sitemap for {0} pages in "
"{1}".format(len(sitemap_links), sphinx.util.console.colorize("blue", filename))
Expand Down

0 comments on commit 797b666

Please sign in to comment.