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

autodoc2-object and -summary outputs full path #17

Open
DatGuy1 opened this issue Mar 10, 2023 · 3 comments
Open

autodoc2-object and -summary outputs full path #17

DatGuy1 opened this issue Mar 10, 2023 · 3 comments

Comments

@DatGuy1
Copy link

DatGuy1 commented Mar 10, 2023

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.

@chrisjsewell
Copy link
Member

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:

@DatGuy1
Copy link
Author

DatGuy1 commented Mar 10, 2023

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.

@PMeira
Copy link

PMeira commented Feb 7, 2024

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.

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

3 participants