Skip to content

Commit c452182

Browse files
author
MarcoGorelli
committed
dont run on invalid notebooks
1 parent 4841697 commit c452182

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

docs/history.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
=========
44

5+
1.5.2 (2022-09-28)
6+
~~~~~~~~~~~~~~~~~~
7+
Fixed bug in which, when running ``nbqa`` on a directory,
8+
it wasn't ignoring invalid files (thanks @francesco-ballarin for the report!)
9+
510
1.5.1 (2022-09-20)
611
~~~~~~~~~~~~~~~~~~
712
Built-in hooks now have ``types_or: [jupyter, markdown]``, so that

nbqa/__main__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ def _get_notebooks(root_dir: str) -> Iterator[Path]:
120120
jupytext_installed = False
121121
else:
122122
jupytext_installed = True
123-
124123
if os.path.isfile(root_dir):
125124
_, ext = os.path.splitext(root_dir)
126125
if (jupytext_installed and ext in (".ipynb", ".md")) or (
@@ -306,7 +305,6 @@ def _run_command(
306305
else:
307306
python_module = COMMAND_TO_PYTHON_MODULE.get(main_command, main_command)
308307
cmd = [sys.executable, "-m", python_module, *sub_commands]
309-
310308
output = subprocess.run(
311309
[*cmd, *args, *cmd_args],
312310
capture_output=True,
@@ -660,7 +658,11 @@ def _main(cli_args: CLIArgs, configs: Configs) -> int:
660658
[
661659
i.file
662660
for key, i in nb_to_tmp_mapping.items()
663-
if key not in saved_sources.failed_notebooks
661+
if key
662+
not in (
663+
*saved_sources.failed_notebooks,
664+
*saved_sources.non_python_notebooks,
665+
)
664666
],
665667
shell=configs["shell"],
666668
)

tests/test_jupytext.py

+26
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,29 @@ def test_invalid_config_file(tmpdir: "LocalPath") -> None:
275275
match=r"Passing unrecognized arguments to super\(JupytextConfiguration\)",
276276
):
277277
main(["black", os.path.join(tmpdir, "foo.md")])
278+
279+
280+
def test_jupytext_on_folder(capsys: "CaptureFixture") -> None:
281+
"""Check invalid files aren't checked."""
282+
path = os.path.join("tests", "invalid_data")
283+
main(
284+
[
285+
"pydocstyle",
286+
path,
287+
]
288+
)
289+
out, _ = capsys.readouterr()
290+
expected = (
291+
f'{os.path.join(path, "invalid_syntax.ipynb")}:cell_1:0:1: D100 Missing docstring in public module\n'
292+
f'{os.path.join(path, "assignment_to_literal.ipynb")}:cell_1:0:1: D100 Missing docstring in public module\n'
293+
f'{os.path.join(path, "automagic.ipynb")}:cell_1:0:1: D100 Missing docstring in public module\n'
294+
)
295+
expected = (
296+
f'{os.path.join(path, "invalid_syntax.ipynb")}:cell_1:0 at module level:\n'
297+
" D100: Missing docstring in public module\n"
298+
f'{os.path.join(path, "assignment_to_literal.ipynb")}:cell_1:0 at module level:\n'
299+
" D100: Missing docstring in public module\n"
300+
f'{os.path.join(path, "automagic.ipynb")}:cell_1:0 at module level:\n'
301+
" D100: Missing docstring in public module\n"
302+
)
303+
assert out == expected

0 commit comments

Comments
 (0)