Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SystemError when trying to build a doc with Pyside6 resources #10009

Closed
Nateckert opened this issue Dec 23, 2021 · 5 comments
Closed

SystemError when trying to build a doc with Pyside6 resources #10009

Nateckert opened this issue Dec 23, 2021 · 5 comments

Comments

@Nateckert
Copy link

Describe the bug

Hi,

We have a fairly large project with the following folder structure:

  • docs
  • package
  • tests
  • ui
    • __init__.py
    • resources
      • gui.qrc
      • icons
        • icons1.png
        • icon2.png
        • ...

ui/resources is actually not a valid Python package, but before running the GUI, we use the command pyside6-rcc ui/resources/gui.qrc -o ui/resources.py

The file ui\__init__.py contains the line from . import resources

When we build the doc with sphinx , we get the exception:

  File "path\to\python\lib\inspect.py", line 614, in getdoc
    doc = object.__doc__
SystemError: null argument to internal routine

The log itself is not more useful either :

# Sphinx version: 4.3.2
# Python version: 3.9.9 (CPython)
# Docutils version: 0.16 release
# Jinja2 version: 2.11.3
# Last messages:
#   Lecture des sources... [ 43%] package.module1.submodule1
#   Lecture des sources... [ 45%] package.submodules
#   Lecture des sources... [ 47%] index
#   Lecture des sources... [ 50%] modules
#   Lecture des sources... [ 52%] tests
#   Lecture des sources... [ 54%] tests.test_module1
#   Lecture des sources... [ 56%] tests.test_module2
#   Lecture des sources... [ 58%] tests.test_module2.submodule1
#   Lecture des sources... [ 60%] tests.test_module2.submodule2
# Loaded extensions:
#   sphinx.ext.mathjax (4.3.2) from path\to\venv\lib\site-packages\sphinx\ext\mathjax.py
#   sphinxcontrib.applehelp (1.0.2) from path\to\venv\lib\site-packages\sphinxcontrib\applehelp\__init__.py
#   sphinxcontrib.devhelp (1.0.2) from path\to\venv\lib\site-packages\sphinxcontrib\devhelp\__init__.py
#   sphinxcontrib.htmlhelp (2.0.0) from path\to\venv\lib\site-packages\sphinxcontrib\htmlhelp\__init__.py
#   sphinxcontrib.serializinghtml (1.1.5) from path\to\venv\lib\site-packages\sphinxcontrib\serializinghtml\__init__.py
#   sphinxcontrib.qthelp (1.0.3) from path\to\venv\lib\site-packages\sphinxcontrib\qthelp\__init__.py
#   alabaster (0.7.12) from path\to\venv\lib\site-packages\alabaster\__init__.py
#   sphinx_rtd_theme (unknown version) from path\to\venv\lib\site-packages\sphinx_rtd_theme\__init__.py
#   sphinx.ext.autodoc.preserve_defaults (1.0) from path\to\venv\lib\site-packages\sphinx\ext\autodoc\preserve_defaults.py
#   sphinx.ext.autodoc.type_comment (4.3.2) from path\to\venv\lib\site-packages\sphinx\ext\autodoc\type_comment.py
#   sphinx.ext.autodoc (4.3.2) from path\to\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py
#   matplotlib.sphinxext.plot_directive (3.5.0) from path\to\venv\lib\site-packages\matplotlib\sphinxext\plot_directive.py
Traceback (most recent call last):
  File "path\to\venv\lib\site-packages\sphinx\cmd\build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "path\to\venv\lib\site-packages\sphinx\application.py", line 344, in build
    self.builder.build_update()
  File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 294, in build_update
    self.build(to_build,
  File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 308, in build
    updated_docnames = set(self.read())
  File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 415, in read
    self._read_serial(docnames)
  File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 436, in _read_serial
    self.read_doc(docname)
  File "path\to\venv\lib\site-packages\sphinx\builders\__init__.py", line 476, 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 189, 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 109, in read
    self.parse()
  File "path\to\venv\lib\site-packages\docutils\readers\__init__.py", line 77, in parse
    self.parser.parse(self.input, document)
  File "path\to\venv\lib\site-packages\sphinx\parsers.py", line 101, 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 241, in run
    context, next_state, result = self.check_line(
  File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 459, 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 241, in run
    context, next_state, result = self.check_line(
  File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 459, 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 241, in run
    context, next_state, result = self.check_line(
  File "path\to\venv\lib\site-packages\docutils\statemachine.py", line 459, 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\ext\autodoc\directive.py", line 162, in run
    documenter.generate(more_content=self.content)
  File "path\to\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 984, in generate
    self.document_members(all_members)
  File "path\to\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 842, in document_members
    for (mname, member, isattr) in self.filter_members(members, want_all):
  File "path\to\venv\lib\site-packages\sphinx\ext\autodoc\__init__.py", line 723, in filter_members
    doc = getdoc(member, self.get_attr, self.config.autodoc_inherit_docstrings,
  File "path\to\venv\lib\site-packages\sphinx\util\inspect.py", line 912, in getdoc
    doc = inspect.getdoc(obj)
  File "path\to\python\lib\inspect.py", line 614, in getdoc
    doc = object.__doc__
SystemError: null argument to internal routine

When we build the doc from the sources, we get this error.
When we build it after generating ui\resources.py, we get this error
When we build it after generating ui\resources.py and deleting the folder ui\resources, we get this error
When we build it after deleting the ui\resources and the file ui\resources.py, it works

How to Reproduce

I am trying to create a minimal reproducable example but my attempts failed so far

The doc itself was built running the following powershell script

cd .\docs

# Remove previously generated auto-doc and plots
Remove-Item .\source\* -Include *.rst -Exclude index.rst
.\make.bat clean

# Generate source files for documentation from docstrings
sphinx-apidoc -f -o source/ ../

# build documentation
.\make.bat html

Expected behavior

The main issue I had is not the error itself, as we are going to change how we package the pyside6 resources to the gui to fix it, but the fact that neither the error message nor the log pointed towards the issue

To find the culprit, I started to delete folders of my projet until I managed to build the doc and finally find the culprit.

Your project

Still working on a minimal reproducible example

Screenshots

No response

OS

Windows 10

Python version

3.9.9

Sphinx version

4.3.2

Sphinx extensions

sphinx_rtd_theme, sphinx.ext.autodoc, matplotlib.sphinxext.plot_directive'

Extra tools

Pyside6==6.2.2.1

Additional context

Thanks a lot for providing a great documentation tool !

@tk0miya
Copy link
Member

tk0miya commented Dec 23, 2021

Thank you for reporting. Could you try #10011 ? It will emit a warning instead of crash.

@Nateckert
Copy link
Author

Thanks for the quick reply !

I tried it and I get 203 warnings, all of the same structure:

WARNING: autodoc : impossible de déterminer si <class 'ui.moduleX.submoduleY.classZ'> est documenté; l'exception suivante a été levée :
null argument to internal routine

The rough translation being "impossible to determine if <class ...> is documented, the following error was raised: null argument to internal routine.

All the warnings are for classes, there are all the same warning, all with the "null argument to internal routine"

Among those 203 warnings, some are repeated, the number of warnings per class being correleted with the number of methods of each class.

I also checked, (for the first 5 warnings, 2 random ones in the middle and the 2 last ones), and all those classes do not have a docstring

The doc builds fine, the elements raising a warning just don't show up.

If I delete the resources folder like before, I get the exact same warnings

@tk0miya
Copy link
Member

tk0miya commented Dec 24, 2021

Is it helpful if we show the name of attribute on the error? If so, I'll change the message with pleasure.

@Nateckert
Copy link
Author

I actually managed to reproduce the bug : https://github.com/Nateckert/sphinx_bug_highlight

It seems to be linked with the inheritance to PySide6 elements.

With regards to the name of the attribute, having the warnings helped me to reproduce the bug but there is definitely a bug on the sphinx/PySide side and I don't think there is a point to improve the message as (hopefully) it will not be raised once it's fixed

Regards

@tk0miya
Copy link
Member

tk0miya commented Dec 26, 2021

Thank you for your comment. I just updated #10011 to show the attribute name. I hope it will help your work.

tk0miya added a commit that referenced this issue Dec 28, 2021
Fix #10009: autodoc: Crashes if subject raises an error on getdoc()
AA-Turner pushed a commit to AA-Turner/sphinx that referenced this issue Dec 29, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants