-
Notifications
You must be signed in to change notification settings - Fork 141
A user tool to debug visibility of objects #522
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
46a4ee9
3ac44d8
86382d9
db28216
9c8d0a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| PythonAttribute, | ||
| PythonData, | ||
| PythonException, | ||
| _trace_visibility, | ||
| ) | ||
| from .settings import OWN_PAGE_LEVELS, TEMPLATE_DIR | ||
|
|
||
|
|
@@ -43,6 +44,15 @@ def in_stdlib(module_name: str) -> bool: | |
| LOGGER = sphinx.util.logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _color_info(msg: str) -> None: | ||
| LOGGER.info( | ||
| colorize("bold", "[AutoAPI] ") | ||
| + colorize( | ||
| "darkgreen", msg | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def _expand_wildcard_placeholder(original_module, originals_map, placeholder): | ||
| """Expand a wildcard placeholder to a sequence of named placeholders. | ||
|
|
||
|
|
@@ -329,12 +339,7 @@ def find_files(patterns, dirs, ignore): | |
| for sub_dir in subdirectories.copy(): | ||
| # iterate copy as we adapt subdirectories during loop | ||
| if _path_matches_patterns(os.path.join(root, sub_dir), ignore): | ||
| LOGGER.info( | ||
| colorize("bold", "[AutoAPI] ") | ||
| + colorize( | ||
| "darkgreen", f"Ignoring directory: {root}/{sub_dir}/" | ||
| ) | ||
| ) | ||
| _color_info(f"Ignoring directory: {root}/{sub_dir}/") | ||
| # adapt original subdirectories inplace | ||
| subdirectories.remove(sub_dir) | ||
| # recurse into remaining directories | ||
|
|
@@ -348,12 +353,7 @@ def find_files(patterns, dirs, ignore): | |
|
|
||
| # Skip ignored files | ||
| if _path_matches_patterns(os.path.join(root, filename), ignore): | ||
| LOGGER.info( | ||
| colorize("bold", "[AutoAPI] ") | ||
| + colorize( | ||
| "darkgreen", f"Ignoring file: {root}/{filename}" | ||
| ) | ||
| ) | ||
| _color_info(f"Ignoring file: {root}/{filename}") | ||
| continue | ||
|
|
||
| # Make sure the path is full | ||
|
|
@@ -388,6 +388,14 @@ def output_rst(self, source_suffix): | |
| def _output_top_rst(self): | ||
| # Render Top Index | ||
| top_level_index = os.path.join(self.dir_root, "index.rst") | ||
|
|
||
| modules = [obj for obj in self.all_objects.values() | ||
| if obj.type == "module" and obj.docstring == ""] | ||
| if modules and "undoc-members" not in self.app.config.autoapi_options: | ||
| _color_info("The following modules have no top-level documentation, and so were skipped as undocumented:") | ||
| for m in modules: | ||
| _color_info(f" {m.id}") | ||
|
|
||
robtaylor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pages = [obj for obj in self.objects_to_render.values() if obj.display] | ||
| if not pages: | ||
| msg = ( | ||
|
|
@@ -499,6 +507,7 @@ def _skip_if_stdlib(self): | |
| and not obj["inherited_from"]["is_abstract"] | ||
| and module not in documented_modules | ||
| ): | ||
| _trace_visibility(self.app, f"Hiding {obj['qual_name']} as determined to be Python standard Library (found as {obj['full_name']})", verbose=2) | ||
| obj["hide"] = True | ||
|
|
||
| def _resolve_placeholders(self): | ||
|
|
@@ -518,12 +527,18 @@ def _hide_yo_kids(self): | |
| for module in self.paths.values(): | ||
| if module["all"] is not None: | ||
| all_names = set(module["all"]) | ||
| _trace_visibility(self.app, f"{module['full_name']}: Found __all__ =") | ||
| for n in all_names: | ||
| _trace_visibility(self.app, f" {n}") | ||
robtaylor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for child in module["children"]: | ||
| if child["qual_name"] not in all_names: | ||
| _trace_visibility(self.app, f"Hiding {child['full_name']}, as {child['qual_name']} not in __all__") | ||
| child["hide"] = True | ||
| elif module["type"] == "module": | ||
| _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']}") | ||
|
||
| child["hide"] = True | ||
|
|
||
| def map(self, options=None): | ||
|
|
@@ -567,13 +582,17 @@ def _render_selection(self): | |
| assert obj.type in self.own_page_types | ||
| self.objects_to_render[obj.id] = obj | ||
| else: | ||
| if obj.subpackages or obj.submodules: | ||
| _trace_visibility(self.app, f"Not rendering the following as {obj.id} set to not display:", verbose=2) | ||
| for module in itertools.chain(obj.subpackages, obj.submodules): | ||
| _trace_visibility(self.app, f" {module.obj['full_name']}", verbose=2) | ||
| module.obj["hide"] = True | ||
|
|
||
| def _inner(parent): | ||
| for child in parent.children: | ||
| self.all_objects[child.id] = child | ||
| if not parent.display: | ||
| _trace_visibility(self.app, f"Hiding {child.id} as parent {parent.id} will not be displayed", verbose=2) | ||
| child.obj["hide"] = True | ||
|
|
||
| if child.display and child.type in self.own_page_types: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,6 +261,7 @@ def setup(app): | |
| 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") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| app.add_autodocumenter(documenters.AutoapiFunctionDocumenter) | ||
| app.add_autodocumenter(documenters.AutoapiPropertyDocumenter) | ||
| app.add_autodocumenter(documenters.AutoapiDecoratorDocumenter) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.