Skip to content

Commit

Permalink
Enable automatic formatting for sphinx/domains/
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Dec 29, 2024
1 parent 22562d4 commit 5e5a3bf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
1 change: 0 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ preview = true
quote-style = "single"
exclude = [
"sphinx/builders/latex/constants.py",
"sphinx/domains/__init__.py",
"sphinx/domains/c/_parser.py",
"sphinx/domains/c/_ids.py",
"sphinx/domains/c/__init__.py",
Expand Down
62 changes: 43 additions & 19 deletions sphinx/domains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def setup(self) -> None:
std = self.env.domains.standard_domain
for index in self.indices:
if index.name and index.localname:
docname = f"{self.name}-{index.name}"
docname = f'{self.name}-{index.name}'
std.note_hyperlink_target(docname, docname, '', index.localname)

def add_object_type(self, name: str, objtype: ObjType) -> None:
Expand All @@ -165,12 +165,19 @@ def role(self, name: str) -> RoleFunction | None:
return None
fullname = f'{self.name}:{name}'

def role_adapter(typ: str, rawtext: str, text: str, lineno: int,
inliner: Inliner, options: dict | None = None,
content: Sequence[str] = (),
) -> tuple[list[Node], list[nodes.system_message]]:
return self.roles[name](fullname, rawtext, text, lineno,
inliner, options or {}, content)
def role_adapter(
typ: str,
rawtext: str,
text: str,
lineno: int,
inliner: Inliner,
options: dict | None = None,
content: Sequence[str] = (),
) -> tuple[list[Node], list[nodes.system_message]]:
return self.roles[name](
fullname, rawtext, text, lineno, inliner, options or {}, content
)

self._role_cache[name] = role_adapter
return role_adapter

Expand All @@ -189,6 +196,7 @@ class DirectiveAdapter(BaseDirective): # type: ignore[valid-type,misc]
def run(self) -> list[Node]:
self.name = fullname
return super().run()

self._directive_cache[name] = DirectiveAdapter
return DirectiveAdapter

Expand All @@ -202,12 +210,15 @@ def merge_domaindata(self, docnames: Set[str], otherdata: dict[str, Any]) -> Non
"""Merge in data regarding *docnames* from a different domaindata
inventory (coming from a subprocess in parallel builds).
"""
raise NotImplementedError('merge_domaindata must be implemented in %s '
'to be able to do parallel builds!' %
self.__class__)

def process_doc(self, env: BuildEnvironment, docname: str,
document: nodes.document) -> None:
msg = (
f'merge_domaindata must be implemented in {self.__class__} '
'to be able to do parallel builds!'
)
raise NotImplementedError(msg)

def process_doc(
self, env: BuildEnvironment, docname: str, document: nodes.document
) -> None:
"""Process a document after it is read by the environment."""
pass

Expand All @@ -221,9 +232,16 @@ def process_field_xref(self, pnode: pending_xref) -> None:
"""
pass

def resolve_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
typ: str, target: str, node: pending_xref, contnode: Element,
) -> nodes.reference | None:
def resolve_xref(
self,
env: BuildEnvironment,
fromdocname: str,
builder: Builder,
typ: str,
target: str,
node: pending_xref,
contnode: Element,
) -> nodes.reference | None:
"""Resolve the pending_xref *node* with the given *typ* and *target*.
This method should return a new node, to replace the xref node,
Expand All @@ -239,9 +257,15 @@ def resolve_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder
"""
pass

def resolve_any_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
target: str, node: pending_xref, contnode: Element,
) -> list[tuple[str, nodes.reference]]:
def resolve_any_xref(
self,
env: BuildEnvironment,
fromdocname: str,
builder: Builder,
target: str,
node: pending_xref,
contnode: Element,
) -> list[tuple[str, nodes.reference]]:
"""Resolve the pending_xref *node* with the given *target*.
The reference comes from an "any" or similar role, which means that we
Expand Down

0 comments on commit 5e5a3bf

Please sign in to comment.