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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug logging to autosectionlabel #10881

Merged
merged 7 commits into from Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -12,6 +12,8 @@ Deprecated

Features added
--------------
* #10881: make debugging automatically generated section labels by
``sphinx.ext.autosectionlabel`` easier.

* #10840: One can cross-reference including an option value: ``:option:`--module=foobar```.
Patch by Martin Liska.
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
9 changes: 9 additions & 0 deletions doc/usage/extensions/autosectionlabel.rst
Expand Up @@ -45,3 +45,12 @@ Configuration
example, when set 1 to ``autosectionlabel_maxdepth``, labels are generated
only for top level sections, and deeper sections are not labeled. It
defaults to ``None`` (disabled).


Debugging
---------
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved

The ``WARNING: undefined label`` indicates that your reference in
:rst:role:`ref` is mis-spelled. Invoking :program:`sphinx-build` with ``-vv``
(see :option:`-v`) will print all section names and the labels that have been
generated for them. This output can help finding the right reference label.
3 changes: 3 additions & 0 deletions sphinx/ext/autosectionlabel.py
Expand Up @@ -40,6 +40,9 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None:
name = nodes.fully_normalize_name(ref_name)
sectname = clean_astext(title)

logger.debug(__('section "%s" gets labeled as "%s"'),
ref_name, name,
location=node, type='autosectionlabel', subtype=docname)
if name in domain.labels:
logger.warning(__('duplicate label %s, other instance in %s'),
name, app.env.doc2path(domain.labels[name][0]),
Expand Down