Skip to content

A user tool to debug visibility of objects - #522

Open
robtaylor wants to merge 7 commits into
readthedocs:mainfrom
robtaylor:debug-visibility
Open

A user tool to debug visibility of objects#522
robtaylor wants to merge 7 commits into
readthedocs:mainfrom
robtaylor:debug-visibility

Conversation

@robtaylor

Copy link
Copy Markdown

It seems users can get quite disoriented when switching off "undoc-members" - whole modules will stop rendering even though there may be documented objects within.

This PR adds a config that helps users to debug why items may not be rendering, and also adds an info log for the common case of the module itself missing top level documentation in init.py

Interested in your thoughts!

@robtaylor
robtaylor force-pushed the debug-visibility branch from 75f2024 to 3ac44d8 Compare May 7, 2025 10:06

@AWhetter AWhetter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea! Thanks for making the change. I've left some comments for improvements.

Comment thread autoapi/_mapper.py Outdated
Comment thread autoapi/_mapper.py Outdated
Comment thread autoapi/extension.py
app.add_config_value("autoapi_generate_api_docs", True, "html")
app.add_config_value("autoapi_prepare_jinja_env", None, "html")
app.add_config_value("autoapi_own_page_level", "module", "html")
app.add_config_value("autoapi_verbose_visibility", 0, "html")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we utilise logging levels instead of needing to invent our own way of configuring verbosity?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I was just worrying about not changing the current logging behaviour too much!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at this again, it adds way too much output to debug mode. I think it makes sense to have this separate for debugging visibility. Also I split the visibility debugging into two verbosity levels as usually level 1 will suffice, but allowing for deeper debugging,.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case please can you add some documentation for this new config option to docs/reference/config.rst. You could also add a small section about debugging to docs/how_to.rst, possibly as a subsection to "How to Customise What Gets Documented", or linking to your new section from there.

Comment thread autoapi/_objects.py Outdated
Comment thread autoapi/_mapper.py
Comment thread autoapi/_mapper.py Outdated
_trace_visibility(self.app, f"Testing if any children of {module['full_name']} have already been documented")
for child in module["children"]:
if "original_path" in child:
_trace_visibility(self.app, f"Hiding {child['full_name']} as documented at {child['original_path']}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These items are hidden not because they're documented elsewhere (in fact they may not be documented anywhere) because we don't consider objects imported from the local package into a module to be part of the public API. Usually those imports are used in the implementation of a class or function in that module instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, makes sense. I think this caught me out because i use import to populate init, and i wasn't getting documentation because the module had no top level documentation - i.e. the fix was to add a docstring at the top of init. Is this something that should be added to the docs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread autoapi/_objects.py Outdated
@robtaylor

Copy link
Copy Markdown
Author

This is a great idea! Thanks for making the change. I've left some comments for improvements.

Thank you, glad this is appreciated!

One question I have - with the 'hide reason' enum idea, we could use this in autoapi-skip-member interface. Do you think it would make sense to add this to that api?

@robtaylor

Copy link
Copy Markdown
Author

I'm having some odd issues running the tests in tox - they're working when i run manually for 3.9 and 3.13, but failing under the tox runs. Any guidance appreciated!

@AWhetter

AWhetter commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

One question I have - with the 'hide reason' enum idea, we could use this in autoapi-skip-member interface. Do you think it would make sense to add this to that api?

Good point. If we use an enum then someone can't extend that enum easily to add their own reasons for something being skipped. Perhaps letting autoapi-skip-member return a string (with the return type bool | str | None) would be best. What do you think?

@robtaylor

robtaylor commented Jun 6, 2025 via email

Copy link
Copy Markdown
Author

robtaylor added 2 commits May 28, 2026 00:41
Fix the display property to use the cached hide_reason instead of
recomputing it, and only trace on cache-hit when the object is
actually hidden. Add documentation for autoapi_verbose_visibility
in config.rst and a debugging guide in how_to.rst.

Co-developed-by: Claude Code v2.1.131 (claude-opus-4-7)
Add a note under the autoapi_options section explaining that
packages without a module-level docstring in __init__.py are
excluded when undoc-members is not enabled.

Co-developed-by: Claude Code v2.1.131 (claude-opus-4-7)
@robtaylor

Copy link
Copy Markdown
Author

Hi @AWhetter, I've pushed two new commits addressing your feedback:

1. Fixed the display cache logic (5f3c462)

  • The else branch now only traces when the object is actually hidden (not when _display_cache is NOT_HIDDEN)
  • Uses self._display_cache instead of recomputing self.hide_reason on every access

2. Added documentation (5f3c462)

  • Added autoapi_verbose_visibility config option docs to docs/reference/config.rst (under Advanced Options)
  • Added a "How to Debug Visibility of Objects" subsection to docs/how_to.rst, under "How to Customise What Gets Documented"

3. Documented the __init__.py docstring gotcha (17d7091)

  • Added a note under "Configure autoapi_options" explaining that packages without a module-level docstring in __init__.py are excluded when undoc-members is not enabled
  • This covers the case I mentioned earlier about imports into __init__ not being documented — the existing how_to section didn't mention this, so I think the note is a useful addition

Re your question about autoapi-skip-member returning bool | str | None — agreed, exposing as a string makes most sense since the enum is already a string enum. Happy to add that in a follow-up if you'd like.

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

Successfully merging this pull request may close these issues.

2 participants