You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incompatible with sphinx>4 (submodules of submodules) #130
Not sure what is happening but we need to make sure it is not a bug here before reporting it upstream to sphinx. This is blocking astropy/astropy#11763 .
I think this is a real issue. I'm getting this same error in photutils. It appears to be due to submodules of submodules:
mod1
__init__.py (from mod2 import *)
mod2
__init__.py (from a import *)
a.py (defines myfunc, and __all__ = ['myfunc'])
In this case, Sphinx is now defining duplicate references as: package.mod1.myfunc and package.mod1.mod2.myfunc and raising the
"duplicate object descriptions".
This started with Sphinx 4 release. Not sure if this was an unintended bug there or if something needs to be fixed in astropy-sphinx for compatiblity with Sphinx 4.
To clarify, this patch was released in v4.0.0b2, and it's present in all versions since then. @pllim I misled you into thinking that our bug #130 would be fixed by this, but it's the opposite: it's caused by it.
In the case of photutils, these are the affected classes: photutils.psf.matching.windows.CosineBellWindow, photutils.psf.matching.windows.HanningWindow, photutils.psf.matching.windows.SplitCosineBellWindow, photutils.psf.matching.windows.TopHatWindow, photutils.psf.matching.windows.TukeyWindow.
It's interesting that photutils.psf.matching.fourier functions do not seem to be affected. I added a photutils.psf.matching.fourier.TESTCLASS class, and this also triggered a warning. Not sure why classes and functions work differently on this.
This needs to go into the output of sphinx-automodapi somehow, which in turn seems to rely on sphinx-autodoc. Which doesn't seem to forward options to the class directive.
E.g. in ctapipe/docs/api I have three files for the same class cause it is imported in two __init__.py:
See sphinx-doc/sphinx#10348 (comment) for a very helpful and detailed description of the problem and the different options. Maybe we could add an option in automodapi to add :noindex: when necessary ?
Reading the comment, I think a good solution (however I don't know how easy it would be) would be 2):
Enable sphinx_automodapi to add the :noindex: option sometimes. This way, you can still use the extension but the newly documented objects are not added to the index, thus not exactly cross-referenceable and would not trigger any warning.
What do you think about the feasibility of adding a :no-index: option to .. automod-api that is a list of objects for which :no-index should be added?
Activity
astrojuanlu commentedon May 22, 2021
I'll have a look at this the coming week ✋🏼
pllim commentedon May 22, 2021
🙏 Thank you! 🙏
astrojuanlu commentedon May 24, 2021
xref: sphinx-doc/sphinx#9121 and sphinx-doc/sphinx#9128
pllim commentedon May 24, 2021
astrojuanlu commentedon May 24, 2021
In the case of photutils, these are the affected classes:
photutils.psf.matching.windows.CosineBellWindow,photutils.psf.matching.windows.HanningWindow,photutils.psf.matching.windows.SplitCosineBellWindow,photutils.psf.matching.windows.TopHatWindow,photutils.psf.matching.windows.TukeyWindow.It's interesting that
photutils.psf.matching.fourierfunctions do not seem to be affected. I added aphotutils.psf.matching.fourier.TESTCLASSclass, and this also triggered a warning. Not sure why classes and functions work differently on this.Will add more information soon.
pllim commentedon Jul 26, 2021
@astrojuanlu , any update from the Sphinx side? If not, we might implement a workaround so we can remove the pin.
astrojuanlu commentedon Jul 27, 2021
Sorry I didn't have time to have a deeper look at this. I can do the week of August 9th, feel free to proceed with a workaround if you're in a hurry.
pllim commentedon Jul 28, 2021
No hurry (yet). Thanks for the update!
astrojuanlu commentedon Sep 7, 2021
See some analysis here astropy/photutils#1238
[-]Incompatible with sphinx>4?[/-][+]Incompatible with sphinx>4 (submodules of submodules)[/+]maxnoe commentedon Mar 29, 2022
I have a minimal sphinx project producing the issue here:
https://github.com/maxnoe/sphinx-automodapi-duplicated-warning
pllim commentedon Mar 29, 2022
@eteq said he was gonna look at this... any update, Erik? Thanks!
If nothing is happening here, see astropy/photutils#1306 for downstream fix.
Related astropy PRs: astropy/astropy#12270 and astropy/astropy#13015
saimn commentedon Apr 5, 2022
So it seems we should somehow generate the autodoc templates using
:canonical:for the classes etc. that are duplicated:https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#directive-option-py-class-canonical
(But I have no idea how to do that)
maxnoe commentedon Apr 5, 2022
This needs to go into the output of
sphinx-automodapisomehow, which in turn seems to rely on sphinx-autodoc. Which doesn't seem to forward options to theclassdirective.E.g. in
ctapipe/docs/apiI have three files for the same class cause it is imported in two__init__.py:These are the files autogenerated by automod-api and contain rst instructions using sphinx.ext.autodoc: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoclass:
So probably we should make try to get
autodocto include the:canonical:path of the class when it's run?maxnoe commentedon Apr 5, 2022
autodochas apparently a way to include that:https://github.com/sphinx-doc/sphinx/blob/b4276edd848d112b4e981011c334d27cbcb20018/sphinx/ext/autodoc/__init__.py#L1674-L1676
Not sure how to trigger it though...
Commit adding this:
sphinx-doc/sphinx@acf66bc
saimn commentedon Apr 11, 2022
The method you pointed @maxnoe (
get_canonical_fullname) is correctly executed. But then it goes throughhttps://github.com/sphinx-doc/sphinx/blob/b4276edd848d112b4e981011c334d27cbcb20018/sphinx/domains/python.py#L1218-L1237
which triggers the warning.
If I take your reproduction project (very useful btw !), the generated docs seems correct. First we have a duplicate for
duplicated.Foo:And then another one for
duplicated.foo.Foo(which is the ones triggering the warning):In the method I pointed above there is a dict with the duplicates:
So I'm thinking that this may actually be a bug in Sphinx which correctly handles the case of one duplicate but not when there are more than one ?
saimn commentedon Apr 19, 2022
See sphinx-doc/sphinx#10348 (comment) for a very helpful and detailed description of the problem and the different options. Maybe we could add an option in automodapi to add
:noindex:when necessary ?Add option to set :noindex:
maxnoe commentedon Jun 13, 2022
Reading the comment, I think a good solution (however I don't know how easy it would be) would be 2):
What do you think about the feasibility of adding a
:no-index:option to.. automod-apithat is a list of objects for which:no-indexshould be added?E.g. for the minimal example you'd put:
?
Add option to set :noindex: (#150)