Skip to content

Conversation

@lang-m
Copy link
Contributor

@lang-m lang-m commented Nov 1, 2024

The translator setup is called unconditionally to add the HootstrapHTML5TransatorMixin. If no translators have been set explicitly this falls back to app.builder.default_translator_class, which is however not defined for the linkcheck builder (maybe others), resulting in an attribute error:

$ sphinx-build -T -b linkcheck <src> <dest>
<...>
Traceback (most recent call last):
  File "/PATH/TO/venv/lib/python3.11/site-packages/sphinx/events.py", line 404, in emit
    results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/PATH/TO/venv/lib/python3.11/site-packages/pydata_sphinx_theme/translator.py", line 88, in setup_translators
    app.builder.default_translator_class,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'CheckExternalLinksBuilder' object has no attribute 'default_translator_class'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/PATH/TO/venv/lib/python3.11/site-packages/sphinx/cmd/build.py", line 496, in build_main
    app = Sphinx(
          ^^^^^^^
  File "/PATH/TO/venv/lib/python3.11/site-packages/sphinx/application.py", line 295, in __init__
    self._init_builder()
  File "/PATH/TO/venv/lib/python3.11/site-packages/sphinx/application.py", line 369, in _init_builder
    self.events.emit('builder-inited')
  File "/PATH/TO/venv/lib/python3.11/site-packages/sphinx/events.py", line 415, in emit
    raise ExtensionError(
sphinx.errors.ExtensionError: Handler <function setup_translators at 0x7f73ec330400> for event 'builder-inited' threw an exception (exception: 'CheckExternalLinksBuilder' object has no attribute 'default_translator_class')

This PR adds a safe check for app.builder.default_translator_class and skips the translator setup if the attribute is not defined.

I have tested the modified version with linkcheck, but I am not sure where to add a unit test for these changes.

@github-actions
Copy link

github-actions bot commented Nov 4, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/pydata_sphinx_theme
  translator.py 81-83
Project Total  

This report was generated by python-coverage-comment-action

@Carreau Carreau added this to the 0.16.1 milestone Nov 4, 2024
@Carreau Carreau merged commit 2f18f2e into pydata:main Nov 12, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants