Enable automatic formatting for `sphinx/ext/autosectionlabel.py`

This commit is contained in:
Adam Turner 2024-12-15 20:32:52 +00:00
parent e81c4e865e
commit e637f3ea48
2 changed files with 20 additions and 9 deletions

View File

@ -415,7 +415,6 @@ exclude = [
"sphinx/domains/python/_object.py", "sphinx/domains/python/_object.py",
"sphinx/domains/rst.py", "sphinx/domains/rst.py",
"sphinx/domains/std/__init__.py", "sphinx/domains/std/__init__.py",
"sphinx/ext/autosectionlabel.py",
"sphinx/ext/autosummary/__init__.py", "sphinx/ext/autosummary/__init__.py",
"sphinx/ext/coverage.py", "sphinx/ext/coverage.py",
"sphinx/ext/doctest.py", "sphinx/ext/doctest.py",

View File

@ -32,8 +32,10 @@ def get_node_depth(node: Node) -> int:
def register_sections_as_label(app: Sphinx, document: Node) -> None: def register_sections_as_label(app: Sphinx, document: Node) -> None:
domain = app.env.domains.standard_domain domain = app.env.domains.standard_domain
for node in document.findall(nodes.section): for node in document.findall(nodes.section):
if (app.config.autosectionlabel_maxdepth and if (
get_node_depth(node) >= app.config.autosectionlabel_maxdepth): app.config.autosectionlabel_maxdepth
and get_node_depth(node) >= app.config.autosectionlabel_maxdepth
):
continue continue
labelid = node['ids'][0] labelid = node['ids'][0]
docname = app.env.docname docname = app.env.docname
@ -45,13 +47,23 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None:
name = nodes.fully_normalize_name(ref_name) name = nodes.fully_normalize_name(ref_name)
sectname = clean_astext(title) sectname = clean_astext(title)
logger.debug(__('section "%s" gets labeled as "%s"'), logger.debug(
ref_name, name, __('section "%s" gets labeled as "%s"'),
location=node, type='autosectionlabel', subtype=docname) ref_name,
name,
location=node,
type='autosectionlabel',
subtype=docname,
)
if name in domain.labels: if name in domain.labels:
logger.warning(__('duplicate label %s, other instance in %s'), logger.warning(
name, app.env.doc2path(domain.labels[name][0]), __('duplicate label %s, other instance in %s'),
location=node, type='autosectionlabel', subtype=docname) name,
app.env.doc2path(domain.labels[name][0]),
location=node,
type='autosectionlabel',
subtype=docname,
)
domain.anonlabels[name] = docname, labelid domain.anonlabels[name] = docname, labelid
domain.labels[name] = docname, labelid, sectname domain.labels[name] = docname, labelid, sectname