Skip to content

Commit d12a018

Browse files
committed
pre-commit runs
1 parent 3d758e4 commit d12a018

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

sphinx_proof/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ def setup(app: Sphinx) -> Dict[str, Any]:
7676
proof_node,
7777
singlehtml=(visit_proof_node, depart_proof_node),
7878
html=(visit_proof_node, depart_proof_node),
79-
latex=(visit_proof_node, depart_proof_node)
79+
latex=(visit_proof_node, depart_proof_node),
8080
)
8181
app.add_node(
8282
unenumerable_node,
8383
singlehtml=(visit_unenumerable_node, depart_unenumerable_node),
8484
html=(visit_unenumerable_node, depart_unenumerable_node),
85-
latex=(visit_unenumerable_node, depart_unenumerable_node)
85+
latex=(visit_unenumerable_node, depart_unenumerable_node),
8686
)
8787
app.add_enumerable_node(
8888
enumerable_node,
8989
"proof",
9090
None,
9191
singlehtml=(visit_enumerable_node, depart_enumerable_node),
9292
html=(visit_enumerable_node, depart_enumerable_node),
93-
latex=(visit_enumerable_node, depart_enumerable_node)
93+
latex=(visit_enumerable_node, depart_enumerable_node),
9494
)
9595

9696
return {

sphinx_proof/directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def run(self) -> List[Node]:
9797
"prio": 0,
9898
"nonumber": True if "nonumber" in self.options else False,
9999
}
100-
100+
101101
return [node]
102102

103103

sphinx_proof/domain.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
:copyright: Copyright 2020 by the QuantEcon team, see AUTHORS
88
:licences: see LICENSE for details
99
"""
10-
from typing import Any, Dict, Tuple, List
10+
from typing import Any, Dict, Tuple, List, Callable
1111
from docutils.nodes import Element, Node, document, system_message
1212
from sphinx.environment import BuildEnvironment
1313
from sphinx.addnodes import pending_xref
@@ -41,7 +41,7 @@ def generate(self, docnames=None) -> Tuple[Dict[str, Any], bool]:
4141
# import pdb;
4242
# pdb.set_trace()
4343
proofs = self.domain.env.proof_list
44-
# {'theorem-0': {'docname': 'start/overview', 'type': 'theorem', 'ids': ['theorem-0'], 'label': 'theorem-0', 'prio': 0, 'nonumber': False}}
44+
# {'theorem-0': {'docname': 'start/overview', 'type': 'theorem', 'ids': ['theorem-0'], 'label': 'theorem-0', 'prio': 0, 'nonumber': False}} # noqa: E501
4545

4646
# name, subtype, docname, typ, anchor, extra, qualifier, description
4747
for anchor, values in proofs.items():
@@ -75,19 +75,21 @@ class ProofDomain(Domain):
7575
name = "prf"
7676
label = "Proof Domain"
7777

78-
roles = {"ref": ProofXRefRole()} # role name -> role callable
78+
roles = {"ref": ProofXRefRole()} # role name -> role callable
7979

80-
indices = {ProofIndex} # a list of index subclasses
80+
indices = {ProofIndex} # a list of index subclasses
8181

82-
directives = {**{"proof": ProofDirective}, **PROOF_TYPES} # list of directives
82+
directives = {**{"proof": ProofDirective}, **PROOF_TYPES} # list of directives
8383

84-
enumerable_nodes = {} # type: Dict[Type[Node], Tuple[str, Callable]]
84+
enumerable_nodes = {} # type: Dict[[Node], Tuple[str, Callable]]
8585

8686
def __init__(self, env: "BuildEnvironment") -> None:
8787
super().__init__(env)
8888

8989
# set up enumerable nodes
90-
self.enumerable_nodes = copy(self.enumerable_nodes) # create a copy for this instance
90+
self.enumerable_nodes = copy(
91+
self.enumerable_nodes
92+
) # create a copy for this instance
9193
for node, settings in env.app.registry.enumerable_nodes.items():
9294
self.enumerable_nodes[node] = settings
9395

@@ -102,11 +104,12 @@ def resolve_xref(
102104
contnode: Element,
103105
) -> Element:
104106
"""
105-
Resolve the pending_xref node with the given typ and target. This method should return a new node,
106-
to replace the xref node, containing the contnode which is the markup content of the cross-reference.
107-
If no resolution can be found, None can be returned; the xref node will then given to the missing-reference event,
108-
and if that yields no resolution, replaced by contnode.The method can also raise sphinx.environment.NoUri
109-
to suppress the missing-reference event being emitted.
107+
Resolve the pending_xref node with the given typ and target. This method should
108+
return a new node, to replace the xref node, containing the contnode which is
109+
the markup content of the cross-reference. If no resolution can be found, None
110+
can be returned; the xref node will then given to the missing-reference event,
111+
and if that yields no resolution, replaced by contnode.The method can also raise
112+
sphinx.environment.NoUri to suppress the missing-reference event being emitted.
110113
"""
111114
try:
112115
match = env.proof_list[target]

sphinx_proof/nodes.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from docutils.nodes import Node
1313
from sphinx.writers.latex import LaTeXTranslator
1414

15-
CR = '\n'
16-
latex_admonition_start = CR + '\\begin{sphinxadmonition}{note}'
17-
latex_admonition_end = '\\end{sphinxadmonition}' + CR
15+
CR = "\n"
16+
latex_admonition_start = CR + "\\begin{sphinxadmonition}{note}"
17+
latex_admonition_end = "\\end{sphinxadmonition}" + CR
18+
1819

1920
class proof_node(nodes.Admonition, nodes.Element):
2021
pass
@@ -30,7 +31,7 @@ class unenumerable_node(nodes.Admonition, nodes.Element):
3031

3132
def visit_enumerable_node(self, node: Node) -> None:
3233
if isinstance(self, LaTeXTranslator):
33-
self.body.append(latex_admonition)
34+
self.body.append(latex_admonition_start)
3435
else:
3536
self.body.append(self.starttag(node, "div", CLASS="admonition"))
3637

@@ -39,7 +40,7 @@ def depart_enumerable_node(self, node: Node) -> None:
3940
typ = node.attributes.get("type", "")
4041
if isinstance(self, LaTeXTranslator):
4142
number = get_node_number_latex(self, node)
42-
idx = list_rindex(self.body,latex_admonition) + 2
43+
idx = list_rindex(self.body, latex_admonition_start) + 2
4344
self.body.insert(idx, f"{typ.title()} {number}")
4445
self.body.append(latex_admonition_end)
4546
else:
@@ -52,7 +53,7 @@ def depart_enumerable_node(self, node: Node) -> None:
5253

5354
def visit_unenumerable_node(self, node: Node) -> None:
5455
if isinstance(self, LaTeXTranslator):
55-
self.body.append(latex_admonition)
56+
self.body.append(latex_admonition_start)
5657
else:
5758
self.body.append(self.starttag(node, "div", CLASS="admonition"))
5859

@@ -61,14 +62,14 @@ def depart_unenumerable_node(self, node: Node) -> None:
6162
typ = node.attributes.get("type", "")
6263
title = node.attributes.get("title", "")
6364
if isinstance(self, LaTeXTranslator):
64-
idx = list_rindex(self.body,latex_admonition) + 2
65+
idx = list_rindex(self.body, latex_admonition_start) + 2
6566
self.body.insert(idx, f"{typ.title()}")
6667
self.body.append(latex_admonition_end)
6768
else:
6869
if title == "":
69-
idx = list_rindex(self.body,'<p class="admonition-title">') + 1
70+
idx = list_rindex(self.body, '<p class="admonition-title">') + 1
7071
else:
71-
idx = list_rindex(self.body,title)
72+
idx = list_rindex(self.body, title)
7273
element = f"<span>{typ.title()} </span>"
7374
self.body.insert(idx, element)
7475
self.body.append("</div>")
@@ -81,7 +82,8 @@ def visit_proof_node(self, node: Node) -> None:
8182
def depart_proof_node(self, node: Node) -> None:
8283
pass
8384

84-
def find_parent(env, node , parent_tag):
85+
86+
def find_parent(env, node, parent_tag):
8587
"""Find the nearest parent node with the given tagname."""
8688
while True:
8789
node = node.parent
@@ -93,32 +95,37 @@ def find_parent(env, node , parent_tag):
9395
and env.titles[node.attributes["docname"]].astext().lower()
9496
in node.attributes["names"]
9597
):
96-
return node.attributes['docname']
98+
return node.attributes["docname"]
9799

98100
if node.tagname == parent_tag:
99-
return node.attributes['docname']
101+
return node.attributes["docname"]
100102

101103
return None
102104

105+
103106
def get_node_number(self: HTMLTranslator, node: Node) -> str:
104107
"""Get the number for the directive node for HTML."""
105108
key = "proof"
106109
ids = node.attributes.get("ids", [])[0]
107110
number = self.builder.fignumbers.get(key, {}).get(ids, ())
108111
return ".".join(map(str, number))
109112

113+
110114
def get_node_number_latex(self: LaTeXTranslator, node: Node) -> str:
111115
"""Get the number for the directive node for LaTeX."""
112116
key = "proof"
113117
docname = find_parent(self.builder.env, node, "section")
114118
ids = node.attributes.get("ids", [])[0]
115-
fignumbers = self.builder.env.toc_fignumbers.get(docname, {}) # Latex does not have builder.fignumbers
119+
fignumbers = self.builder.env.toc_fignumbers.get(
120+
docname, {}
121+
) # Latex does not have builder.fignumbers
116122
number = fignumbers.get(key, {}).get(ids, ())
117123
return ".".join(map(str, number))
118124

125+
119126
def list_rindex(li, x) -> int:
120127
"""Getting the last occurence of an item in a list."""
121128
for i in reversed(range(len(li))):
122129
if li[i] == x:
123130
return i
124-
raise ValueError("{} is not in list".format(x))
131+
raise ValueError("{} is not in list".format(x))

0 commit comments

Comments
 (0)