sphinx-autodoc2 icon indicating copy to clipboard operation
sphinx-autodoc2 copied to clipboard

autodoc2-object and -summary outputs full path

Open DatGuy1 opened this issue 2 years ago • 3 comments

When using autodoc2-object and -summary, instead of outputting Baz for instance it outputs the full path, meaning Foo.Bar.Baz. This duplicates the path when trying to press to an object (hello.rst#Foo.Bar.Foo.Bar.Baz), is needlessly long, and conflicts with the behaviour of the auto-generation.

DatGuy1 avatar Mar 10 '23 20:03 DatGuy1

Thanks for the feedback.

Specifically in -summary you can prepend items by ~ to only show the last part (see https://sphinx-autodoc2.readthedocs.io/en/latest/summary.html)

I'm surprised about the hello.rst#Foo.Bar.Foo.Bar.Baz, I don't think this should be directly related to do what is displayed. Perhaps you could show the result of

.. autodoc2-object:: xxx
    :literal:

chrisjsewell avatar Mar 10 '23 20:03 chrisjsewell

Here is a screenshot. Not really the best medium but it captured everything I wanted in one. The WindowsToaster class is output from auto_mode, the center is :literal:, and the bottom is autodoc2-object.

DatGuy1 avatar Mar 10 '23 22:03 DatGuy1

I did some testing, and it seems the issue with duplicated names in the node_id only happens when using autodoc2-object with e.g. classes, while it seems to work OK with modules. In auto_mode, things work fine since it uses whole modules/packages.

I compared the literal output with the code from the auto_mode version, and the only notable difference is the absence of :py-module: (regardless if this is the issue or not, would emitting :py-currentmodule: be useful?). If I paste the literal code, prepending it with :py-module:, the node_ids are generated OK. But if I prepend the autodoc2-object with :py-module:, it doesn't seem to change anything.

I would have no idea how to fix this, but it seems that some context is being lost when using autodoc2-object with classes vs. modules/packages (for the time being, I'm monkey-patching sphinx.domains.python.PyObject.add_target_and_index to my package, that seems to be enough to generate better node_ids).

To reproduce:

  • Create amod.py in an empty folder:
class AClass:
    """AClass is a class"""

    AAttr = 123
    """Something 123"""
  • Run sphinx-quickstart
  • Append to conf.py:
extensions = [
    "autodoc2",
]
autodoc2_packages = [
    {
        "path": "./amod.py",
        "auto_mode": False
    },
]
  • Add .. autodoc2-object:: amod.AClass to index.rst.
  • Build it.

PMeira avatar Feb 07 '24 12:02 PMeira