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

Sphinx Viewcode and autoapi conflict: IndexError list index out of range if child class file (.py) is smaller than parent class file. #422

Closed
hansonmcoombs opened this issue Mar 3, 2024 · 2 comments

Comments

@hansonmcoombs
Copy link

This is a port of an issue from Sphinx (sphinx-doc/sphinx#12026)

The original issue:

Describe the bug

building sphinx the build fails if the child class is smaller than the parent class file.

Error message

../sphinx/ext/viewcode.py", line 289, in collect_pages
    + lines[start])
      ~~~~~^^^^^^^
IndexError: list index out of range

Adding blank lines to the child class (at the end of the file) resolves the problem....

It seems like it must be a rather minimal problem, but it took some time to find the issue

How to Reproduce

The easiest way to reproduce the error is to clone the demo repo I have created: It has full environment information (conda) as well. https://github.com/hansonmcoombs/sphinx_bug_test

Environment Information

Platform:              linux; (Linux-5.15.0-94-generic-x86_64-with-glibc2.35)
Python version:        3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.20.1
Jinja2 version:        3.1.3
Pygments version:      2.17.2

Sphinx extensions

['sphinx.ext.todo', # since found irrelevant  to the issue
 'sphinx.ext.autodoc', # since found irrelevant  to the issue
'sphinx.ext.viewcode',
 'sphinx.ext.autosummary']

Additional learning:

I have slimmed down the example repo:

It appears to be a conflict
between autoapi and viewcode extensions, with the following settings:

  • autoapi_options = ['inherited-members']
  • autoapi_python_use_implicit_namespaces = True
  • autoapi_python_class_content = 'both'

I have pushed a commit with the slimmed down example.

@aborecki
Copy link

aborecki commented Jun 8, 2024

Changing order of extensions helped in my case:
I got error when:
extensions = [
"sphinx.ext.viewcode",
"autoapi.extension",

When viewcode is after autoapi, everything works fine:
extensions = [
"autoapi.extension",
"sphinx.ext.viewcode",

@hansonmcoombs
Copy link
Author

Even more strangely I just re-ran my original example (with the same env) and I was un able to replicate the error. Obviously something changed (I rebuilt my machine with ubuntu 24.04), but search me... Closing the issue.

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

No branches or pull requests

2 participants