brightway-lca / brightway2-data

Tools for the management of inventory databases and impact assessment methods. Part of the Brightway LCA framework.
https://docs.brightway.dev/
BSD 3-Clause "New" or "Revised" License
11 stars 24 forks source link

`parameters.py` Absolute Imports break Sphinx Build #186

Closed michaelweinold closed 2 months ago

michaelweinold commented 2 months ago

The recent move to absolute imports:

broke the inheritance-diagram functionality of the autoapi Sphinx extension:

A quick workaround would be to simply disable the generation of inheritance diagrams in conf.py like so:

autoapi_options = [
    'members',
    'undoc-members',
    'private-members',
    'show-inheritance',
    'show-module-summary',
    # 'show-inheritance-diagram' # commented out for debugging
]

Passing -v -v -v to the sphinx-build command, as documented allowed me to narrow the issue down the bw2data/parameters.py file:

(...)
[app] emitting event: 'source-read'('api/bw2data/parameters/index', ['bw2data.parameters\n==================\n\n.. py:module:: bw2data.
[app] emitting event: 'build-finished'(SphinxParallelError("AttributeError: 'AssignName' object has no attribute 'getattr'", 'Traceback (m
[AutoAPI] Cleaning generated .rst files

(Error in parallel process)
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/sphinx_documentation/lib/python3.12/site-packages/sphinx/util/parallel.py", line 76, in _process
    ret = func(arg)
(...)

Manually removing this file will result in a successful Sphinx build.

I will need to leave the remainder of this investigation to the gentlemen who broke the build in the first place (@cmutel et al.) 😬

I created a debugging repository that should make this fairly easy: https://github.com/michaelweinold/sphinx-autoapi-debugging

michaelweinold commented 2 months ago

@cmutel, I painstakingly narrowed the issue down to the file/class structure now replicated here:

__init__.py:

from test_library.test_module import banana

test_module.py:

class highest:
    def __init__(self):
        self.a = 'a'

class middle(highest):
    def __init__(self):
        self.a = 'a'

class lowest:
    def __init__(self):
        self.db = "middle"

test_module = lowest()

It is all a little peculiar. If the instance of the lowest() class is named something other than the name of the module, such as banana = lowest(), no error is thrown. But even if the instance of the lowest() class is named test_module, the error can be avoided by not making the class middle() inherit from another class.

Maybe you can pick this up...

cmutel commented 2 months ago

No idea how you even thought to debug in that direction... what about just moving parameters = ParameterManager() to __init__.py? This shouldn't break too much... the other option would be to change the filename parameters.py.

michaelweinold commented 2 months ago

No idea how you even thought to debug in that direction...

images

what about just moving parameters = ParameterManager() to __init__.py? This shouldn't break too much...

It still does - sorry. You can quickly check my debugging repo: https://github.com/michaelweinold/sphinx-autoapi-debugging

the other option would be to change the filename parameters.py

From what I can see, this should work.

michaelweinold commented 2 months ago

I have posted the MWE from above in the related issue: