Skip to content

Commit

Permalink
Enable automatic formatting for sphinx/domains/citation.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Dec 31, 2024
1 parent 51a38d5 commit 8333f04
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
1 change: 0 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ quote-style = "single"
exclude = [
"sphinx/builders/latex/constants.py",
"sphinx/domains/changeset.py",
"sphinx/domains/citation.py",
"sphinx/domains/index.py",
"sphinx/domains/javascript.py",
"sphinx/domains/math.py",
Expand Down
70 changes: 50 additions & 20 deletions sphinx/domains/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ def note_citation(self, node: nodes.citation) -> None:
label = node[0].astext()
if label in self.citations:
path = self.env.doc2path(self.citations[label][0])
logger.warning(__('duplicate citation %s, other instance in %s'), label, path,
location=node, type='ref', subtype='citation')
logger.warning(
__('duplicate citation %s, other instance in %s'),
label,
path,
location=node,
type='ref',
subtype='citation',
)
self.citations[label] = (node['docname'], node['ids'][0], node.line) # type: ignore[assignment]

def note_citation_reference(self, node: pending_xref) -> None:
Expand All @@ -81,23 +87,42 @@ def note_citation_reference(self, node: pending_xref) -> None:
def check_consistency(self) -> None:
for name, (docname, _labelid, lineno) in self.citations.items():
if name not in self.citation_refs:
logger.warning(__('Citation [%s] is not referenced.'), name,
type='ref', subtype='citation', location=(docname, lineno))

def resolve_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
typ: str, target: str, node: pending_xref, contnode: Element,
) -> nodes.reference | None:
logger.warning(
__('Citation [%s] is not referenced.'),
name,
type='ref',
subtype='citation',
location=(docname, lineno),
)

def resolve_xref(
self,
env: BuildEnvironment,
fromdocname: str,
builder: Builder,
typ: str,
target: str,
node: pending_xref,
contnode: Element,
) -> nodes.reference | None:
docname, labelid, lineno = self.citations.get(target, ('', '', 0))
if not docname:
return None

return make_refnode(builder, fromdocname, docname,
labelid, contnode)

def resolve_any_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
target: str, node: pending_xref, contnode: Element,
) -> list[tuple[str, nodes.reference]]:
refnode = self.resolve_xref(env, fromdocname, builder, 'ref', target, node, contnode)
return make_refnode(builder, fromdocname, docname, labelid, contnode)

def resolve_any_xref(
self,
env: BuildEnvironment,
fromdocname: str,
builder: Builder,
target: str,
node: pending_xref,
contnode: Element,
) -> list[tuple[str, nodes.reference]]:
refnode = self.resolve_xref(
env, fromdocname, builder, 'ref', target, node, contnode
)
if refnode is None:
return []
else:
Expand Down Expand Up @@ -133,11 +158,16 @@ def apply(self, **kwargs: Any) -> None:
domain = self.env.domains.citation_domain
for node in self.document.findall(nodes.citation_reference):
target = node.astext()
ref = pending_xref(target, refdomain='citation', reftype='ref',
reftarget=target, refwarn=True,
support_smartquotes=False,
ids=node["ids"],
classes=node.get('classes', []))
ref = pending_xref(
target,
refdomain='citation',
reftype='ref',
reftarget=target,
refwarn=True,
support_smartquotes=False,
ids=node['ids'],
classes=node.get('classes', []),
)
ref += nodes.inline(target, '[%s]' % target)
copy_source_info(node, ref)
node.replace_self(ref)
Expand Down

0 comments on commit 8333f04

Please sign in to comment.