readthedocs / sphinx-autoapi

A new approach to API documentation in Sphinx.
https://sphinx-autoapi.readthedocs.io/
MIT License
415 stars 126 forks source link

Docs build failed for multiple class having same class name #364

Closed pankajastro closed 1 year ago

pankajastro commented 1 year ago

I have two classes having same name FileType on after the recent release sphinx-autoapi-2.0.1 I'm unable to build docs and getting the below error. This is working on sphinx-autoapi-2.0.0

Warning, treated as error:
/Users/pankaj/Documents/astro_code/astro-sdk/python-sdk/docs/autoapi/astro/databases/base/index.rst:80:more than one target found for cross-reference 'FileType': astro.constants.FileType, astro.files.types.base.FileType
make: *** [html] Error 2
AWhetter commented 1 year ago

Without some code to reproduce against I can't be sure, but if the FileType class is indeed accessible in both places in your public API, then you will need to customise what gets documented by AutoAPI. This is documented here: https://sphinx-autoapi.readthedocs.io/en/latest/how_to.html#how-to-customise-what-gets-documented

DanCardin commented 1 year ago

For whatever it's worth, to future readers, I encountered what seems like the same issue.

The issue appeared to go away when I made sure that the source of the ambiguous cross reference had a valid reference to the correct object available to link to.

In the example here that might look like

# astro.constants.py
class FileType:
    pass
# astro.files.types.base.py
class FileType:
    pass

def the_issue(file_type: FileType):
    ...
.. autoapimodule:: astro.files.types.base
   :members: the_issue

will produce the above error

whereas the following will not

.. autoapimodule:: astro.files.types.base
   :members: FileType, the_issue

My real project at the version which had the issue, if at all useful also.