jbms / sphinx-immaterial

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

Python: KeyError during build #101

Closed iSOLveIT closed 2 years ago

iSOLveIT commented 2 years ago

Sphinx documentation doesn't build and it produces this error message if I use Sphinx-Immaterial as the html_theme:


Exception occurred:
  File "/home/isolveit/Documents/myCodes/Codes/useBlocks/sphinxcontrib-needs/.venv/lib/python3.9/site-packages/sphinx_immaterial/python_domain_fixes.py", line 500, in cross_link_single_parameter
    py.data["synopses"][param_symbol] = synopsis
KeyError: 'synopses'
2bndy5 commented 2 years ago

Did you also add sphinx_immaterial to the extensions list in conf.py?

iSOLveIT commented 2 years ago

Just realised I didn't add sphinx_immaterial to the extensions list in conf.py. It is building now. Thanks for the help.

jbms commented 2 years ago

I wonder if there is a way we can detect this problem and show a useful error message.

2bndy5 commented 2 years ago

Maybe we can try to catch an exception and augment the error message. Maybe create some kind of assertion from Jinja context processing.

jbms commented 2 years ago

I am actually a bit confused how this code is even running if sphinx_immaterial is not added as an extension.

@iSOLveIT What was your theme / extension config when the problem occurred?

iSOLveIT commented 2 years ago

In my conf.py file, I set the html_theme variable using this: os.getenv('THEME', 'ala baster').

The THEME environment variable was set to sphinx-immaterial in my .envrc file.

As a result, although sphinx-immaterial wasn't included in the extensions list, it was used by Sphinx.

2bndy5 commented 2 years ago

@jbms I was able to reproduce this with our own docs.

here's the full traceback ``` Traceback (most recent call last): File "path\to\venv\lib\site-packages\sphinx\cmd\build.py", line 276, in build_main app.build(args.force_all, filenames) File "path\to\venv\lib\site-packages\sphinx\application.py", line 330, in build self.builder.build_update() File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 286, in build_update self.build(to_build, File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 300, in build updated_docnames = set(self.read()) File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 407, in read self._read_serial(docnames) File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 428, in _read_serial self.read_doc(docname) File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 468, in read_doc doctree = read_doc(self.app, self.env, self.env.doc2path(docname)) File "path\to\venv\lib\site-packages\sphinx\io.py", line 181, in read_doc pub.publish() File "path\to\venv\lib\site-packages\docutils\core.py", line 217, in publish self.document = self.reader.read(self.source, self.parser, File "path\to\venv\lib\site-packages\sphinx\io.py", line 101, in read self.parse() File "path\to\venv\lib\site-packages\docutils\readers\__init__.py", line 78, in parse self.parser.parse(self.input, document) File "path\to\venv\lib\site-packages\sphinx\parsers.py", line 89, in parse self.statemachine.run(inputlines, document, inliner=self.inliner) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 170, in run results = StateMachineWS.run(self, input_lines, input_offset, File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 239, in run context, next_state, result = self.check_line( File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 451, in check_line return method(match, context, next_state) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 3008, in text self.section(title.lstrip(), source, style, lineno + 1, messages) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 327, in section self.new_subsection(title, lineno, messages) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 393, in new_subsection newabsoffset = self.nested_parse( File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 281, in nested_parse state_machine.run(block, input_offset, memo=self.memo, File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 196, in run results = StateMachineWS.run(self, input_lines, input_offset) File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 239, in run context, next_state, result = self.check_line( File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 451, in check_line return method(match, context, next_state) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2769, in underline self.section(title, source, style, lineno - 1, messages) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 327, in section self.new_subsection(title, lineno, messages) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 393, in new_subsection newabsoffset = self.nested_parse( File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 281, in nested_parse state_machine.run(block, input_offset, memo=self.memo, File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 196, in run results = StateMachineWS.run(self, input_lines, input_offset) File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 239, in run context, next_state, result = self.check_line( File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 451, in check_line return method(match, context, next_state) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2342, in explicit_markup nodelist, blank_finish = self.explicit_construct(match) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2354, in explicit_construct return method(self, expmatch) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2096, in directive return self.run_directive( File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2146, in run_directive result = directive_instance.run() File "path\to\venv\lib\site-packages\sphinx_immaterial\theme_result.py", line 44, in run self.state.nested_parse(self.content, self.content_offset, results_div) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 281, in nested_parse state_machine.run(block, input_offset, memo=self.memo, File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 196, in run results = StateMachineWS.run(self, input_lines, input_offset) File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 239, in run context, next_state, result = self.check_line( File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 451, in check_line return method(match, context, next_state) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2342, in explicit_markup nodelist, blank_finish = self.explicit_construct(match) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2354, in explicit_construct return method(self, expmatch) File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2096, in directive return self.run_directive( File "path\to\venv\lib\site-packages\docutils\parsers\rst\states.py", line 2146, in run_directive result = directive_instance.run() File "path\to\venv\lib\site-packages\sphinx\domains\__init__.py", line 281, in run return super().run() File "path\to\venv\lib\site-packages\sphinx_immaterial\apidoc_formatting.py", line 178, in run nodes = orig_run(self) File "path\to\venv\lib\site-packages\sphinx\directives\__init__.py", line 206, in run self.after_content() File "path\to\venv\lib\site-packages\sphinx_immaterial\python_domain_fixes.py", line 640, in after_content _cross_link_parameters( File "path\to\venv\lib\site-packages\sphinx_immaterial\python_domain_fixes.py", line 594, in _cross_link_parameters _add_parameter_documentation_ids( File "path\to\venv\lib\site-packages\sphinx_immaterial\python_domain_fixes.py", line 567, in _add_parameter_documentation_ids cross_link_single_parameter(param_name, term) File "path\to\venv\lib\site-packages\sphinx_immaterial\python_domain_fixes.py", line 500, in cross_link_single_parameter py.data["synopses"][param_symbol] = synopsis KeyError: 'synopses' ```