Skip to content

Commit 7a43086

Browse files
authored
🔧 Pre-commit; replace black,isort with ruff-fmt (chrisjsewell#61)
1 parent ca71405 commit 7a43086

11 files changed

+33
-49
lines changed

.pre-commit-config.yaml

+4-12
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,9 @@ repos:
1313
- id: trailing-whitespace
1414
exclude: ^tests/.*\.txt
1515

16-
- repo: https://github.com/PyCQA/isort
17-
rev: 5.12.0
18-
hooks:
19-
- id: isort
20-
21-
- repo: https://github.com/psf/black
22-
rev: 23.11.0
23-
hooks:
24-
- id: black
25-
26-
- repo: https://github.com/charliermarsh/ruff-pre-commit
27-
rev: v0.1.5
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: v0.1.6
2818
hooks:
2919
- id: ruff
20+
args: [--fix]
21+
- id: ruff-format

docs/source/conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# pytest-notebook documentation build configuration file
43
#

pyproject.toml

+5-6
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ coalesce_streams = "pytest_notebook.post_processors:coalesce_streams"
7171
blacken_code = "pytest_notebook.post_processors:blacken_code"
7272
beautifulsoup = "pytest_notebook.post_processors:beautifulsoup"
7373

74-
[tool.isort]
75-
profile = "black"
76-
force_sort_within_sections = true
77-
7874
[tool.ruff]
79-
line-length = 100
80-
extend-select = ["B0", "C4", "ICN", "ISC", "N", "RUF", "SIM"]
75+
extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "UP"]
76+
extend-ignore = ["ISC001"]
77+
78+
[tool.ruff.lint.isort]
79+
force-sort-within-sections = true

pytest_notebook/ipy_magic.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def parse_cell_content(
3939
if in_config:
4040
in_config = False
4141
elif config_content:
42-
raise IOError(f"Line {i}: found second config file section")
42+
raise OSError(f"Line {i}: found second config file section")
4343
else:
4444
in_config = True
4545
elif in_config:
@@ -48,7 +48,7 @@ def parse_cell_content(
4848
if in_literals:
4949
in_literals = False
5050
elif literals_content:
51-
raise IOError(f"Line {i}: found second literals section")
51+
raise OSError(f"Line {i}: found second literals section")
5252
else:
5353
in_literals = True
5454
elif in_literals:
@@ -57,9 +57,9 @@ def parse_cell_content(
5757
test_content.append(line)
5858

5959
if in_config:
60-
raise IOError("found start of config section, but not end")
60+
raise OSError("found start of config section, but not end")
6161
if in_literals:
62-
raise IOError("found start of literals section, but not end")
62+
raise OSError("found start of literals section, but not end")
6363

6464
return test_content, config_content, literals_content
6565

pytest_notebook/nb_regression.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _validate_exec_cwd(self, attribute, value):
136136
if not isinstance(value, str):
137137
raise TypeError("exec_cwd must be None or a string")
138138
if not os.path.isdir(value):
139-
raise IOError("exec_cwd='{}' is not an existing directory".format(value))
139+
raise OSError(f"exec_cwd='{value}' is not an existing directory")
140140

141141
exec_allow_errors: bool = attr.ib(
142142
False, instance_of(bool), metadata={"help": HELP_EXEC_ALLOW_ERRORS}
@@ -248,7 +248,7 @@ def __setattr__(self, key, value):
248248
if x_attr.validator:
249249
x_attr.validator(self, x_attr, value)
250250

251-
super(NBRegressionFixture, self).__setattr__(key, value)
251+
super().__setattr__(key, value)
252252

253253
def check(
254254
self, path: Union[TextIO, str], raise_errors: bool = True

pytest_notebook/notebook.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,18 @@ def gather_json_paths(
7575
if isinstance(obj, dict):
7676
for k, v in obj.items():
7777
gather_json_paths(
78-
v, paths, types, curr_path=tuple(list(curr_path) + [k]) # noqa: RUF005
78+
v,
79+
paths,
80+
types,
81+
curr_path=tuple(list(curr_path) + [k]), # noqa: RUF005
7982
)
8083
elif isinstance(obj, list):
8184
for i, v in enumerate(obj):
8285
gather_json_paths(
83-
v, paths, types, curr_path=tuple(list(curr_path) + [i]) # noqa: RUF005
86+
v,
87+
paths,
88+
types,
89+
curr_path=tuple(list(curr_path) + [i]), # noqa: RUF005
8490
)
8591
elif types is None or isinstance(obj, types):
8692
paths.append(curr_path)
@@ -149,7 +155,7 @@ def validate_regex_replace(args, index):
149155
raise TypeError(f"diff_replace[{index}] replacement '{args[2]}' must a string")
150156

151157

152-
@lru_cache()
158+
@lru_cache
153159
def _load_validator():
154160
schema = json.loads(
155161
files(resources).joinpath("nb_metadata.schema.json").read_text(encoding="utf-8")

pytest_notebook/plugin.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""pytest plugin configuration.
32
43
For more information on writing pytest plugins see:

pytest_notebook/post_processors.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
ENTRY_POINT_NAME = "nbreg.post_proc"
2424

2525

26-
@functools.lru_cache()
26+
@functools.lru_cache
2727
def list_processor_names():
2828
"""List entry point names for post-processors."""
2929
return [ep.name for ep in entry_points().select(group=ENTRY_POINT_NAME)]
3030

3131

32-
@functools.lru_cache()
32+
@functools.lru_cache
3333
def load_processor(name: str):
3434
"""Get a post-processors for an entry point name."""
3535
try:
3636
(entry_point,) = entry_points().select(group=ENTRY_POINT_NAME, name=name)
3737
except ValueError:
3838
raise ValueError(
39-
"entry point '{}' for group '{}' not found".format(name, ENTRY_POINT_NAME)
39+
f"entry point '{name}' for group '{ENTRY_POINT_NAME}' not found"
4040
)
4141
return entry_point.load()
4242

pytest_notebook/utils.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,12 @@ def param_doc(field):
136136
return title + "\n" + description
137137

138138
if attr.fields(attrs_class):
139-
params_section = (
140-
textwrap.dedent(
141-
"""\
139+
params_section = textwrap.dedent(
140+
"""\
142141
Parameters
143142
----------
144143
"""
145-
)
146-
+ "\n\n".join(param_doc(field) for field in attr.fields(attrs_class))
147-
)
144+
) + "\n\n".join(param_doc(field) for field in attr.fields(attrs_class))
148145
else:
149146
params_section = ""
150147

tests/test_plugin_collector.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Test the plugin collection and direct invocation of notebooks."""
32
import os
43

tests/test_plugin_fixture.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Test the ``nb_regression`` plugin fixture."""
32
import os
43

@@ -105,9 +104,7 @@ def test_nb_regression_ini_setting_init(testdir):
105104
nb_post_processors =
106105
nb_diff_replace =
107106
/cells/*/outputs/*/traceback \<ipython\-input\-[\-0-9a-zA-Z]*\> "< >"
108-
""".format(
109-
path=os.path.join(PATH, "raw_files")
110-
)
107+
""".format(path=os.path.join(PATH, "raw_files"))
111108
)
112109

113110
testdir.makepyfile(
@@ -167,9 +164,7 @@ def test_nb_regression_fixture_check_fail(testdir):
167164
"""
168165
def test_nb(nb_regression):
169166
nb_regression.check("{path}")
170-
""".format(
171-
path=os.path.join(PATH, "raw_files", "simple-diff-output.ipynb")
172-
)
167+
""".format(path=os.path.join(PATH, "raw_files", "simple-diff-output.ipynb"))
173168
)
174169

175170
# run pytest with the following cmd args
@@ -198,9 +193,7 @@ def test_nb(nb_regression):
198193
"/cells/9/outputs/0/metadata/application/json"
199194
)
200195
nb_regression.check("{path}")
201-
""".format(
202-
path=os.path.join(PATH, "raw_files", "different_outputs.ipynb")
203-
)
196+
""".format(path=os.path.join(PATH, "raw_files", "different_outputs.ipynb"))
204197
)
205198

206199
# run pytest with the following cmd args

0 commit comments

Comments
 (0)