Skip to content

Commit 7bd1b03

Browse files
authored
chore: update the commit hooks list (#268)
2 parents 0106bd2 + 79e5f47 commit 7bd1b03

File tree

12 files changed

+161
-200
lines changed

12 files changed

+161
-200
lines changed

.pre-commit-config.yaml

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,41 @@
1-
ci:
2-
autoupdate_schedule: monthly
3-
autoupdate_commit_msg: "chore: update pre-commit hooks"
4-
51
repos:
6-
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.5.0
2+
- repo: "https://github.com/psf/black"
3+
rev: "22.3.0"
84
hooks:
9-
- id: check-case-conflict
10-
- id: check-ast
11-
- id: check-docstring-first
12-
- id: check-executables-have-shebangs
13-
- id: check-added-large-files
14-
- id: check-case-conflict
15-
- id: check-merge-conflict
16-
- id: check-json
17-
- id: check-toml
18-
- id: check-yaml
19-
- id: debug-statements
20-
- id: end-of-file-fixer
21-
- id: trailing-whitespace
5+
- id: black
226

23-
- repo: https://github.com/python-jsonschema/check-jsonschema
24-
rev: 0.27.1
7+
- repo: "https://github.com/kynan/nbstripout"
8+
rev: "0.5.0"
259
hooks:
26-
- id: check-github-workflows
10+
- id: nbstripout
2711

28-
- repo: https://github.com/executablebooks/mdformat
29-
rev: 0.7.17
12+
- repo: "https://github.com/pre-commit/mirrors-prettier"
13+
rev: "v2.7.1"
3014
hooks:
31-
- id: mdformat
15+
- id: prettier
16+
exclude: tests\/test_.+\.
3217

33-
- repo: https://github.com/pre-commit/mirrors-prettier
34-
rev: "v3.0.3"
18+
- repo: https://github.com/charliermarsh/ruff-pre-commit
19+
rev: "v0.0.215"
3520
hooks:
36-
- id: prettier
37-
types_or: [yaml, html, json]
21+
- id: ruff
3822

39-
- repo: https://github.com/codespell-project/codespell
40-
rev: "v2.2.6"
23+
- repo: https://github.com/PyCQA/doc8
24+
rev: "v1.1.1"
4125
hooks:
42-
- id: codespell
43-
args: ["-L", "sur,nd"]
26+
- id: doc8
4427

45-
- repo: https://github.com/pre-commit/pygrep-hooks
46-
rev: "v1.10.0"
28+
- repo: https://github.com/codespell-project/codespell
29+
rev: v2.2.4
4730
hooks:
48-
- id: rst-backticks
49-
- id: rst-directive-colons
50-
- id: rst-inline-touching-normal
31+
- id: codespell
32+
stages: [commit]
33+
additional_dependencies:
34+
- tomli
5135

52-
- repo: https://github.com/astral-sh/ruff-pre-commit
53-
rev: v0.1.5
36+
# Prevent committing inline conflict markers
37+
- repo: https://github.com/pre-commit/pre-commit-hooks
38+
rev: v4.3.0
5439
hooks:
55-
- id: ruff
56-
types_or: [python, jupyter]
57-
args: ["--fix", "--show-fixes"]
58-
- id: ruff-format
59-
types_or: [python, jupyter]
40+
- id: check-merge-conflict
41+
args: [--assume-in-merge]

jupyter_sphinx/__init__.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
from .execute import ExecuteJupyterCells, JupyterKernel
3030
from .thebelab import ThebeButton, ThebeButtonNode, ThebeOutputNode, ThebeSourceNode
3131

32-
REQUIRE_URL_DEFAULT = (
33-
"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"
34-
)
32+
REQUIRE_URL_DEFAULT = "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"
3533
THEBELAB_URL_DEFAULT = "https://unpkg.com/thebelab@^0.4.0"
3634

3735
logger = logging.getLogger(__name__)
@@ -93,29 +91,26 @@ def visit_thebe_source(self, node):
9391

9492
# Sphinx callback functions
9593
def builder_inited(app: Sphinx):
96-
"""
94+
"""Init the build.
95+
9796
2 cases
9897
case 1: ipywidgets 7, with require
99-
case 2: ipywidgets 7, no require
98+
case 2: ipywidgets 7, no require.
10099
"""
101100
require_url = app.config.jupyter_sphinx_require_url
102101
if require_url:
103102
app.add_js_file(require_url)
104103
embed_url = (
105-
app.config.jupyter_sphinx_embed_url
106-
or ipywidgets.embed.DEFAULT_EMBED_REQUIREJS_URL
104+
app.config.jupyter_sphinx_embed_url or ipywidgets.embed.DEFAULT_EMBED_REQUIREJS_URL
107105
)
108106
else:
109-
embed_url = (
110-
app.config.jupyter_sphinx_embed_url
111-
or ipywidgets.embed.DEFAULT_EMBED_SCRIPT_URL
112-
)
107+
embed_url = app.config.jupyter_sphinx_embed_url or ipywidgets.embed.DEFAULT_EMBED_SCRIPT_URL
113108
if embed_url:
114109
app.add_js_file(embed_url)
115110

116111

117112
def copy_file(src: Path, dst: Path):
118-
"""wrapper of copy_asset_file to handle path"""
113+
"""Wrapper of copy_asset_file to handle path."""
119114
copy_asset_file(str(src.resolve()), str(dst.resolve()))
120115

121116

jupyter_sphinx/_version.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"""
2-
store the current version info of the project.
3-
4-
"""
1+
"""store the current version info of the project."""
52
import re
63
from typing import List
74

jupyter_sphinx/ast.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Manipulating the Sphinx AST with Jupyter objects"""
1+
"""Manipulating the Sphinx AST with Jupyter objects."""
22

33
import json
44
import warnings
@@ -34,9 +34,7 @@ def load_content(cell, location, logger):
3434
env.note_dependency(rel_filename)
3535
if cell.content:
3636
logger.warning(
37-
'Ignoring inline code in Jupyter cell included from "{}"'.format(
38-
rel_filename
39-
),
37+
'Ignoring inline code in Jupyter cell included from "{}"'.format(rel_filename),
4038
location=location,
4139
)
4240
try:
@@ -60,9 +58,7 @@ def get_highlights(cell, content, location, logger):
6058
hl_lines = parselinenos(emphasize_linespec, nlines)
6159
if any(i >= nlines for i in hl_lines):
6260
logger.warning(
63-
"Line number spec is out of range(1-{}): {}".format(
64-
nlines, emphasize_linespec
65-
),
61+
"Line number spec is out of range(1-{}): {}".format(nlines, emphasize_linespec),
6662
location=location,
6763
)
6864
hl_lines = [i + 1 for i in hl_lines if i < nlines]
@@ -78,7 +74,7 @@ class JupyterCell(Directive):
7874
executed when the directive is parsed, but later during a doctree
7975
transformation.
8076
81-
Arguments
77+
Arguments:
8278
---------
8379
filename : str (optional)
8480
If provided, a path to a file containing code.
@@ -166,7 +162,7 @@ def run(self):
166162
class CellInput(Directive):
167163
"""Define a code cell to be included verbatim but not executed.
168164
169-
Arguments
165+
Arguments:
170166
---------
171167
filename : str (optional)
172168
If provided, a path to a file containing code.
@@ -237,7 +233,7 @@ def run(self):
237233
class CellOutput(Directive):
238234
"""Define an output cell to be included verbatim.
239235
240-
Arguments
236+
Arguments:
241237
---------
242238
filename : str (optional)
243239
If provided, a path to a file containing output.
@@ -323,12 +319,10 @@ def __init__(self, rawsource="", *children, **attributes):
323319
super().__init__("", *children, mimetypes=attributes["mimetypes"])
324320

325321
def render_as(self, visitor):
326-
"""Determine which node to show based on the visitor"""
322+
"""Determine which node to show based on the visitor."""
327323
try:
328324
# Or should we go to config via the node?
329-
priority = visitor.builder.env.app.config[
330-
"render_priority_" + visitor.builder.format
331-
]
325+
priority = visitor.builder.env.app.config["render_priority_" + visitor.builder.format]
332326
except (AttributeError, KeyError):
333327
# Not sure what do to, act as a container and show everything just in case.
334328
return super()
@@ -367,9 +361,7 @@ def __init__(self, rawsource="", *children, **attributes):
367361
super().__init__("", view_spec=attributes["view_spec"])
368362

369363
def html(self):
370-
return ipywidgets.embed.widget_view_template.format(
371-
view_spec=json.dumps(self["view_spec"])
372-
)
364+
return ipywidgets.embed.widget_view_template.format(view_spec=json.dumps(self["view_spec"]))
373365

374366

375367
class JupyterWidgetStateNode(docutils.nodes.Element):
@@ -414,7 +406,7 @@ def cell_output_to_nodes(outputs, write_stderr, out_dir, thebe_config, inline=Fa
414406
inline: False
415407
Whether the nodes will be placed in-line with the text.
416408
417-
Returns
409+
Returns:
418410
-------
419411
to_add : list of docutils nodes
420412
Each output, converted into a docutils node.
@@ -509,9 +501,7 @@ def output2sphinx(data, mime_type, metadata, out_dir, inline=False):
509501
math_node = math_block
510502

511503
if mime_type == "text/html":
512-
return docutils.nodes.raw(
513-
text=data, format="html", classes=["output", "text_html"]
514-
)
504+
return docutils.nodes.raw(text=data, format="html", classes=["output", "text_html"])
515505
elif mime_type == "text/plain":
516506
return literal_node(
517507
text=data,

jupyter_sphinx/css/jupyter-sphinx.css

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ After a build, this stylesheet is loaded from ./_static/jupyter-sphinx.css .
2323
2424
*/
2525

26-
2726
div.jupyter_container {
28-
padding: .4em;
29-
margin: 0 0 .4em 0;
30-
background-color: #FFFF;
31-
border: 1px solid #CCC;
32-
-moz-box-shadow: 2px 2px 4px rgba(87, 87, 87, 0.2);
33-
-webkit-box-shadow: 2px 2px 4px rgba(87, 87, 87, 0.2);
34-
box-shadow: 2px 2px 4px rgba(87, 87, 87, 0.2);
27+
padding: 0.4em;
28+
margin: 0 0 0.4em 0;
29+
background-color: #ffff;
30+
border: 1px solid #ccc;
31+
-moz-box-shadow: 2px 2px 4px rgba(87, 87, 87, 0.2);
32+
-webkit-box-shadow: 2px 2px 4px rgba(87, 87, 87, 0.2);
33+
box-shadow: 2px 2px 4px rgba(87, 87, 87, 0.2);
3534
}
3635
.jupyter_container div.code_cell {
3736
border: 1px solid #cfcfcf;
@@ -59,8 +58,8 @@ div.jupyter_container div.highlight {
5958
background-color: #f7f7f7; /* for haiku */
6059
}
6160
div.jupyter_container {
62-
padding: 0;
63-
margin: 0;
61+
padding: 0;
62+
margin: 0;
6463
}
6564

6665
/* Prevent alabaster breaking highlight alignment */
@@ -70,10 +69,10 @@ div.jupyter_container .hll {
7069
}
7170

7271
/* overrides for sphinx_rtd_theme */
73-
.rst-content .jupyter_container div[class^='highlight'],
74-
.document .jupyter_container div[class^='highlight'],
72+
.rst-content .jupyter_container div[class^="highlight"],
73+
.document .jupyter_container div[class^="highlight"],
7574
.rst-content .jupyter_container pre.literal-block {
76-
border:none;
75+
border: none;
7776
margin: 0;
7877
padding: 0;
7978
background: none;
@@ -86,21 +85,21 @@ div.jupyter_container .hll {
8685
text-align: center;
8786
}
8887
.jupyter_container .stderr {
89-
background-color: #FCC;
90-
border: none;
91-
padding: 3px;
88+
background-color: #fcc;
89+
border: none;
90+
padding: 3px;
9291
}
9392
.jupyter_container .output {
94-
border: none;
93+
border: none;
9594
}
9695
.jupyter_container div.output pre {
97-
background-color: white;
98-
background: none;
99-
padding: 4px;
100-
border: none;
101-
box-shadow: none;
102-
-webkit-box-shadow: none; /* for nature */
103-
-moz-box-shadow: none; /* for nature */
96+
background-color: white;
97+
background: none;
98+
padding: 4px;
99+
border: none;
100+
box-shadow: none;
101+
-webkit-box-shadow: none; /* for nature */
102+
-moz-box-shadow: none; /* for nature */
104103
}
105104
.jupyter_container .code_cell td.linenos {
106105
text-align: right;
@@ -114,10 +113,10 @@ div.jupyter_container .hll {
114113
/* combine sequential jupyter cells,
115114
by moving sequential ones up higher on y-axis */
116115
div.jupyter_container + div.jupyter_container {
117-
margin: -.5em 0 .4em 0;
116+
margin: -0.5em 0 0.4em 0;
118117
}
119118

120119
/* Fix for sphinx_rtd_theme spacing after jupyter_container #91 */
121120
.rst-content .jupyter_container {
122-
margin: 0 0 24px 0;
121+
margin: 0 0 24px 0;
123122
}

jupyter_sphinx/execute.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def LoggerAdapterWrapper(logger_adapter):
6565
class JupyterKernel(Directive):
6666
"""Specify a new Jupyter Kernel.
6767
68-
Arguments
68+
Arguments:
6969
---------
7070
kernel_name : str (optional)
7171
The name of the kernel in which to execute future Jupyter cells, as
@@ -166,16 +166,10 @@ def apply(self):
166166

167167
# Raise error if cells raised exceptions and were not marked as doing so
168168
for node, cell in zip(nodes, notebook.cells):
169-
errors = [
170-
output
171-
for output in cell.outputs
172-
if output["output_type"] == "error"
173-
]
169+
errors = [output for output in cell.outputs if output["output_type"] == "error"]
174170
allowed_errors = node.attributes.get("raises") or []
175171
raises_provided = node.attributes["raises"] is not None
176-
if (
177-
raises_provided and not allowed_errors
178-
): # empty 'raises': suppress all errors
172+
if raises_provided and not allowed_errors: # empty 'raises': suppress all errors
179173
pass
180174
elif errors and not any(e["ename"] in allowed_errors for e in errors):
181175
raise ExtensionError(
@@ -192,9 +186,7 @@ def apply(self):
192186
if output["output_type"] == "stream" and output["name"] == "stderr"
193187
]
194188
if stderr and not node.attributes["stderr"]:
195-
js.logger.warning(
196-
"Cell printed to stderr:\n{}".format(stderr[0]["text"])
197-
)
189+
js.logger.warning(f"Cell printed to stderr:\n{stderr[0]['text']}")
198190

199191
# Insert input/output into placeholders for non-executed cells
200192
for node, cell in zip(nodes, notebook.cells):
@@ -224,9 +216,7 @@ def apply(self):
224216
# The literal_block node with the source
225217
source = node.children[0].children[0]
226218
nlines = source.rawsource.count("\n") + 1
227-
show_numbering = (
228-
linenos_config or source["linenos"] or source["linenostart"]
229-
)
219+
show_numbering = linenos_config or source["linenos"] or source["linenostart"]
230220

231221
if show_numbering:
232222
source["linenos"] = True
@@ -251,9 +241,7 @@ def apply(self):
251241
# Write certain cell outputs (e.g. images) to separate files, and
252242
# modify the metadata of the associated cells in 'notebook' to
253243
# include the path to the output file.
254-
write_notebook_output(
255-
notebook, str(output_dir), file_name, self.env.docname
256-
)
244+
write_notebook_output(notebook, str(output_dir), file_name, self.env.docname)
257245

258246
try:
259247
cm_language = notebook.metadata.language_info.codemirror_mode.name

0 commit comments

Comments
 (0)