jbms / sphinx-immaterial

Adaptation of the popular mkdocs-material material design theme to the sphinx documentation system
https://jbms.github.io/sphinx-immaterial/
Other
177 stars 28 forks source link

Extension error (sphinx_immaterial.google_fonts) #216

Closed williamjmorenor closed 1 year ago

williamjmorenor commented 1 year ago

I got this error building the docs for the first time, I did install the theme via pypi package.

Running Sphinx v6.1.3
making output directory... done
WARNING: html_static_path entry '_static' does not exist

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/now-lms-manual/envs/latest/lib/python3.10/site-packages/sphinx/events.py", line 96, in emit
    results.append(listener.handler(self.app, *args))
  File "/home/docs/checkouts/readthedocs.org/user_builds/now-lms-manual/envs/latest/lib/python3.10/site-packages/sphinx_immaterial/google_fonts.py", line 188, in _builder_inited
    font_options = app.config["html_theme_options"]["font"]
KeyError: 'font'

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

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/now-lms-manual/envs/latest/lib/python3.10/site-packages/sphinx/cmd/build.py", line 279, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "/home/docs/checkouts/readthedocs.org/user_builds/now-lms-manual/envs/latest/lib/python3.10/site-packages/sphinx/application.py", line 262, in __init__
    self._init_builder()
  File "/home/docs/checkouts/readthedocs.org/user_builds/now-lms-manual/envs/latest/lib/python3.10/site-packages/sphinx/application.py", line 335, in _init_builder
    self.events.emit('builder-inited')
  File "/home/docs/checkouts/readthedocs.org/user_builds/now-lms-manual/envs/latest/lib/python3.10/site-packages/sphinx/events.py", line 107, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function _builder_inited at 0x7f65d6776950> for event 'builder-inited' threw an exception (exception: 'font')

Extension error (sphinx_immaterial.google_fonts):
Handler <function _builder_inited at 0x7f65d6776950> for event 'builder-inited' threw an exception (exception: 'font')
2bndy5 commented 1 year ago

I'm not sure how to reproduce this. Can you provide the conf.py file used at the time of the error? Did you forget to add sphinx_immaterial theme as an extension (required)?


The default value https://github.com/jbms/sphinx-immaterial/blob/04cf514bb6c1eed333c3ccaec6bd2d2e9c558e6b/sphinx_immaterial/__init__.py#L28 is set when the conf.py file is read: https://github.com/jbms/sphinx-immaterial/blob/04cf514bb6c1eed333c3ccaec6bd2d2e9c558e6b/sphinx_immaterial/__init__.py#L240-L248 This should be automatically done before the google_fonts ext handles the builder-inited event, so I need more info...

williamjmorenor commented 1 year ago

This is the conf.py file:

https://github.com/bmosoluciones/now-lms-manual/blob/main/source/conf.py

Neojume commented 1 year ago

I get a similar error when trying to use this behind a corporate proxy. My server has no direct connection to fonts.googleapis.com so the external_resource_cache is never filled.

Is there an option to exclude external resources?

2bndy5 commented 1 year ago

Is there an option to exclude external resources?

No, but you can keep your own copy of the cache (fetched from machine without the limiting proxy) and specify its location via sphinx_immaterial_external_resource_cache_dir.

2bndy5 commented 1 year ago

Our CI artifacts also contain a copy of the cache in html/_static/fonts

williamjmorenor commented 1 year ago

For the récords i have a error in my conf,py file, the Word extension is in prural there Was a missing "s"

2bndy5 commented 1 year ago

Good to know. I was still rather stumped.

2bndy5 commented 1 year ago

I'm closing this as the original problem is resolved.

@Neojume You can open a new issue if my suggestion doesn't resolve your problem.