sphinx-contrib / matlabdomain

A Sphinx extension for documenting Matlab code
http://sphinxcontrib-matlabdomain.readthedocs.io/
Other
69 stars 45 forks source link

Unexpected sphinx error: KeyError: 'default'` #198

Closed AntoineDps closed 1 year ago

AntoineDps commented 1 year ago

I have been using sphinx and in particular the sphinx-contrib for matlab domain wihtout any issue until the html compilation doesn't build successfully (see the Traceback below) for now apparent reasons since I have made any change since the last successful compilation. The following error is given:

Exception occurred:
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinxcontrib\mat_types.py", line 1459, in __init__
    self.default = attrs["default"]
KeyError: 'default'
The full traceback has been saved in C:\Users\antdu953\AppData\Local\Temp\sphinx-err-i91nc48s.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!

Without really understanding neither the meaning or the reason of the error, I have opened the 'mat_types.py' file and commented the concerned line (line 1459).

After this my documentation compiles without error and apparently without any unexpected impact on the documentation itself. So all good except that I don't like to understand the reasons why got this error in the first place.

Any comment or thought on this issue would be highly appreciated !

And here's the Traceback information I am getting:

Platform:         win32; (Windows-10-10.0.19045-SP0)
Sphinx version:   7.0.1
Python version:   3.9.12 (CPython)
Docutils version: 0.18.1
Jinja2 version:   3.1.2
Pygments version: 2.15.1

Last messages:
[autosummary] generating autosummary for: application.rst, buoy.rst, classes.rst, development.rst, index.rst, projection.rst, reference.rst, run.rst, theory.rst, txtinput.rst, update.rst, usage.rst
building [mo]: targets for 0 po files that are out of date
writing output...

building [html]: targets for 12 source files that are out of date
updating environment:
[new config]
12 added, 0 changed, 0 removed
reading sources... [  8%] application
reading sources... [ 16%] buoy

Loaded extensions:
sphinx.ext.mathjax (7.0.1)
alabaster (0.7.13)
sphinxcontrib.applehelp (1.0.4)
sphinxcontrib.devhelp (1.0.2)
sphinxcontrib.htmlhelp (2.0.1)
sphinxcontrib.serializinghtml (1.1.5)
sphinxcontrib.qthelp (1.0.3)
sphinxcontrib.matlab (unknown version)
sphinx.ext.autodoc.preserve_defaults (7.0.1)
sphinx.ext.autodoc.type_comment (7.0.1)
sphinx.ext.autodoc.typehints (7.0.1)
sphinx.ext.autodoc (7.0.1)
sphinx.ext.napoleon (7.0.1)
sphinx.ext.todo (7.0.1)
sphinx.ext.autosummary (7.0.1)
sphinxcontrib.jquery (4.1)
sphinx_rtd_theme (unknown version)

Traceback:

Traceback (most recent call last):
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\cmd\build.py", line 285, in build_main
    app.build(args.force_all, args.filenames)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\application.py", line 351, in build
    self.builder.build_update()
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\builders\__init__.py", line 294, in build_update
    self.build(to_build,
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\builders\__init__.py", line 311, in build
    updated_docnames = set(self.read())
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\builders\__init__.py", line 418, in read
    self._read_serial(docnames)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\builders\__init__.py", line 439, in _read_serial
    self.read_doc(docname)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\builders\__init__.py", line 495, in read_doc
    publisher.publish()
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\core.py", line 217, in publish
    self.document = self.reader.read(self.source, self.parser,
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\io.py", line 104, in read
    self.parse()
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\readers\__init__.py", line 78, in parse
    self.parser.parse(self.input, document)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\parsers.py", line 80, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 170, in run
    results = StateMachineWS.run(self, input_lines, input_offset,
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\statemachine.py", line 240, in run
    context, next_state, result = self.check_line(
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\statemachine.py", line 452, in check_line
    return method(match, context, next_state)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 2779, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 393, in new_subsection
    newabsoffset = self.nested_parse(
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 281, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 196, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\statemachine.py", line 240, in run
    context, next_state, result = self.check_line(
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\statemachine.py", line 452, in check_line
    return method(match, context, next_state)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 2352, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 2364, in explicit_construct
    return method(self, expmatch)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 2101, in directive
    return self.run_directive(
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\docutils\parsers\rst\states.py", line 2151, in run_directive
    result = directive_instance.run()
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinx\domains\__init__.py", line 286, in run
    return super().run()
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinxcontrib\mat_directives.py", line 69, in run
    documenter.generate(more_content=self.content)
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinxcontrib\mat_documenters.py", line 547, in generate
    self.analyzer.find_attr_docs()
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinxcontrib\mat_types.py", line 1659, in find_attr_docs
    for mk, mv in v.getter("__dict__").items():
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinxcontrib\mat_types.py", line 1447, in getter
    objdict = dict([(pn, self.getter(pn)) for pn in self.properties.keys()])
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinxcontrib\mat_types.py", line 1447, in <listcomp>
    objdict = dict([(pn, self.getter(pn)) for pn in self.properties.keys()])
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinxcontrib\mat_types.py", line 1443, in getter
    return MatProperty(name, self, self.properties[name])
  File "C:\Users\antdu953\AppData\Roaming\Python\Python39\site-packages\sphinxcontrib\mat_types.py", line 1459, in __init__
    self.default = attrs["default"]
KeyError: 'default' 
joeced commented 1 year ago

Thanks for the detailed report. Your can try to run with sphinx-build -vvv =m html . -b _build/html > sphinx.log this will run in verbose mode. We can then identify which file us causing the parsing error

AntoineDps commented 1 year ago

Hi Joeced !

Thanks for the answer. I would like to run the way you suggested but it seems that another error showed up. Here again it is quite confusing since I haven't done much change, if if I did it is only in my .m files, nothing related to the configuration of the compilation itself or else. Here is the error I got this merning when trying to compile:

Running Sphinx v7.0.1
loading pickled environment... done
WARNING: [sphinxcontrib-matlabdomain] Parsing failed in WEClibrary.None. Expected '='.

Extension error (sphinxcontrib.matlab):
Handler <function analyze at 0x000001BF5D9B6790> for event 'builder-inited' threw an exception (exception: 'NoneType' object has no attribute 'startswith')

An idea about that ?

joeced commented 1 year ago

Look like a parsing error. I'm away from a computer at the moment, so I can't help much the moment. Is there a Matlab file called None?

AntoineDps commented 1 year ago

Indeed. Absolutely not.. that is why I have been very confused... I have only 6 matlab file, non of them is called None.m

AntoineDps commented 1 year ago

Hi again joeced !

An update: I have played around and uninstalled/reinstalled the matlab extension. Nothing changed.

However I have spent some time try to troubleshoot the error. Seems like there was something in my matlab file that the sphinx matlab extension didn't like, some empty method or similar... But I confirm that I didn't have any None.m file.

I guess this how it handled this case, but I was surprised that a error in my matlab file itself (no commentary but the code itself) could lead to this type of error diagnostic. Good to know !

Moreover, the initial error that is at the origin of my post disappeared as well... I think this was an error due to the same reason: a bug in the matlab code itself !

Thanks for your support !

joeced commented 1 year ago

Hi

Glad that it worked out for you. Did it produce a sphinx.log file you can share? I would like to get rid of these kinds of errors. We are using the pygments library to parse the matlab files and are some what sensitive to syntaxes errors.

AntoineDps commented 1 year ago

Hi joeced,

The sphinx.log file I have in my docs file is empty right now. I'd like to help so let me know what I should do ! But I guess you want the .log corresponding to the case when I had errors ?

joeced commented 1 year ago

I'll close this now. If you stumble on such an error again, please make an issue.