diff --git a/poetry.lock b/poetry.lock index 12b7d48..13dacc7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "appnope" @@ -1282,6 +1282,33 @@ files = [ {file = "rpds_py-0.18.0.tar.gz", hash = "sha256:42821446ee7a76f5d9f71f9e33a4fb2ffd724bb3e7f93386150b61a43115788d"}, ] +[[package]] +name = "ruff" +version = "0.8.4" +description = "An extremely fast Python linter and code formatter, written in Rust." +optional = false +python-versions = ">=3.7" +files = [ + {file = "ruff-0.8.4-py3-none-linux_armv6l.whl", hash = "sha256:58072f0c06080276804c6a4e21a9045a706584a958e644353603d36ca1eb8a60"}, + {file = "ruff-0.8.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:ffb60904651c00a1e0b8df594591770018a0f04587f7deeb3838344fe3adabac"}, + {file = "ruff-0.8.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:6ddf5d654ac0d44389f6bf05cee4caeefc3132a64b58ea46738111d687352296"}, + {file = "ruff-0.8.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e248b1f0fa2749edd3350a2a342b67b43a2627434c059a063418e3d375cfe643"}, + {file = "ruff-0.8.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:bf197b98ed86e417412ee3b6c893f44c8864f816451441483253d5ff22c0e81e"}, + {file = "ruff-0.8.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c41319b85faa3aadd4d30cb1cffdd9ac6b89704ff79f7664b853785b48eccdf3"}, + {file = "ruff-0.8.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:9f8402b7c4f96463f135e936d9ab77b65711fcd5d72e5d67597b543bbb43cf3f"}, + {file = "ruff-0.8.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e4e56b3baa9c23d324ead112a4fdf20db9a3f8f29eeabff1355114dd96014604"}, + {file = "ruff-0.8.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:736272574e97157f7edbbb43b1d046125fce9e7d8d583d5d65d0c9bf2c15addf"}, + {file = "ruff-0.8.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e5fe710ab6061592521f902fca7ebcb9fabd27bc7c57c764298b1c1f15fff720"}, + {file = "ruff-0.8.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:13e9ec6d6b55f6da412d59953d65d66e760d583dd3c1c72bf1f26435b5bfdbae"}, + {file = "ruff-0.8.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:97d9aefef725348ad77d6db98b726cfdb075a40b936c7984088804dfd38268a7"}, + {file = "ruff-0.8.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:ab78e33325a6f5374e04c2ab924a3367d69a0da36f8c9cb6b894a62017506111"}, + {file = "ruff-0.8.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:8ef06f66f4a05c3ddbc9121a8b0cecccd92c5bf3dd43b5472ffe40b8ca10f0f8"}, + {file = "ruff-0.8.4-py3-none-win32.whl", hash = "sha256:552fb6d861320958ca5e15f28b20a3d071aa83b93caee33a87b471f99a6c0835"}, + {file = "ruff-0.8.4-py3-none-win_amd64.whl", hash = "sha256:f21a1143776f8656d7f364bd264a9d60f01b7f52243fbe90e7670c0dfe0cf65d"}, + {file = "ruff-0.8.4-py3-none-win_arm64.whl", hash = "sha256:9183dd615d8df50defa8b1d9a074053891ba39025cf5ae88e8bcb52edcc4bf08"}, + {file = "ruff-0.8.4.tar.gz", hash = "sha256:0d5f89f254836799af1615798caa5f80b7f935d7a670fad66c5007928e57ace8"}, +] + [[package]] name = "setuptools" version = "69.1.1" @@ -1445,4 +1472,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.0" -content-hash = "3ad5eae646b0ce353f529ffb770d29214a995385d9867d0d6d1a694cb21ebfb4" +content-hash = "e84589842f710507fb1ef7b51bef9274687213e6e7e040b0b1c14c6c4bb80280" diff --git a/pyproject.toml b/pyproject.toml index 9c334ac..049589f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,9 @@ virtualenv = "^20.1.0" setuptools = ">65.0.0" typing-extensions = "^4.7.1" +[tool.poetry.group.dev.dependencies] +ruff = "^0.8.4" + [build-system] build-backend = "poetry.core.masonry.api" requires = ["setuptools", "poetry-core>=1.0.0"] diff --git a/ruff.toml b/ruff.toml index 1e915bc..3f0489a 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,3 +1,5 @@ +[lint] + # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. select = ["E", "F", "I"] ignore = [] @@ -6,14 +8,8 @@ ignore = [] fixable = ["A", "B", "C", "D", "E", "F", "I"] unfixable = [] -# Same as Black. -line-length = 88 - # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -# Assume Python 3.8 -target-version = "py38" - -[isort] +[lint.isort] known-first-party = ["nbmake"] diff --git a/src/nbmake/nb_run.py b/src/nbmake/nb_run.py index b741ef6..6822c41 100644 --- a/src/nbmake/nb_run.py +++ b/src/nbmake/nb_run.py @@ -125,7 +125,7 @@ async def apply_mocks( except Exception as err: # if at top causes https://github.com/jupyter/nbclient/issues/128 # from jupyter_client.kernelspec import KernelSpecManager, NoSuchKernel - # trace=f"{summary}\n\nInstalled Kernels: {str(KernelSpecManager().find_kernel_specs())}", + # trace=f"{summary}\n\nInstalled Kernels: {str(KernelSpecManager().find_kernel_specs())}", # noqa # https://github.com/treebeardtech/nbmake/runs/1536896858?check_suite_focus=true if str(type(err)) != "": raise err diff --git a/src/nbmake/pytest_items.py b/src/nbmake/pytest_items.py index 1ea5ffc..bbbcc00 100644 --- a/src/nbmake/pytest_items.py +++ b/src/nbmake/pytest_items.py @@ -56,7 +56,7 @@ def runtest(self): if option.overwrite: nbformat.write(res.nb, str(source)) - if res.error != None: + if res.error is not None: raise NotebookFailedException(res) def repr_failure(self, excinfo: Any, style: Optional[Any] = None) -> TerminalRepr: diff --git a/src/nbmake/pytest_plugin.py b/src/nbmake/pytest_plugin.py index ae2f2ac..eb0836a 100644 --- a/src/nbmake/pytest_plugin.py +++ b/src/nbmake/pytest_plugin.py @@ -79,11 +79,11 @@ def pytest_terminal_summary(terminalreporter: Any, exitstatus: int, config: Any) if os.environ.get("GITHUB_ACTIONS", False): if exitstatus == ExitCode.TESTS_FAILED: print( - f"\n* nbmake: Automate reading GitHub Actions logs with our bot: https://github.com/marketplace/treebeard-build\n" + "\n* nbmake: Automate reading GitHub Actions logs with our bot: https://github.com/marketplace/treebeard-build\n" ) else: print( - f"\nLearn more about nbmake at https://github.com/treebeardtech/nbmake\n" + "\nLearn more about nbmake at https://github.com/treebeardtech/nbmake\n" ) - except: + except: # noqa pass diff --git a/tests/helper.py b/tests/helper.py index 1f9e9c8..919e5ee 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -45,4 +45,4 @@ def write_nb( def testdir2(pytester: Pytester): os.environ[ "HOME" - ] = HOME # ensures jupyter client can start the ipykernel subprocess without module location issues + ] = HOME # ensures jupyter client can start the ipykernel subprocess without module location issues # noqa diff --git a/tests/resources/ignore_tag.ipynb b/tests/resources/ignore_tag.ipynb index 8d561a8..f9200d3 100644 --- a/tests/resources/ignore_tag.ipynb +++ b/tests/resources/ignore_tag.ipynb @@ -10,8 +10,8 @@ }, "outputs": [], "source": [ - "print('will fail')\n", - "1/0" + "print(\"will fail\")\n", + "1 / 0" ] }, { diff --git a/tests/resources/import_errs.ipynb b/tests/resources/import_errs.ipynb index ef7b904..e16bf09 100644 --- a/tests/resources/import_errs.ipynb +++ b/tests/resources/import_errs.ipynb @@ -6,9 +6,7 @@ "metadata": {}, "outputs": [], "source": [ - "import itertools\n", - "\n", - "1/0" + "1 / 0" ] }, { @@ -18,6 +16,7 @@ "outputs": [], "source": [ "import time\n", + "\n", "time.sleep(600)" ] }, @@ -26,18 +25,14 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "import lkjlkj" - ] + "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "import pickle" - ] + "source": [] } ], "metadata": { diff --git a/tests/resources/mock.ipynb b/tests/resources/mock.ipynb index 0f03ecf..81b1084 100644 --- a/tests/resources/mock.ipynb +++ b/tests/resources/mock.ipynb @@ -17,7 +17,7 @@ "outputs": [], "source": [ "x = 5\n", - "y = 'y'" + "y = \"y\"" ] }, { @@ -28,7 +28,7 @@ "source": [ "assert x == 2\n", "assert y == \"fish\"\n", - "assert z == { \"x\": 42 }" + "assert z == {\"x\": 42} # noqa" ] } ], diff --git a/tests/resources/raises_tag.ipynb b/tests/resources/raises_tag.ipynb index 9b28194..5791251 100644 --- a/tests/resources/raises_tag.ipynb +++ b/tests/resources/raises_tag.ipynb @@ -10,8 +10,8 @@ }, "outputs": [], "source": [ - "print('will fail')\n", - "1/0" + "print(\"will fail\")\n", + "1 / 0" ] }, { diff --git a/tests/test_nb_run.py b/tests/test_nb_run.py index ca14e3f..e263030 100644 --- a/tests/test_nb_run.py +++ b/tests/test_nb_run.py @@ -3,14 +3,12 @@ import pytest from nbformat import write from nbformat.v4 import new_code_cell, new_notebook, new_output -from pytest import Pytester from typing_extensions import Never -NB_VERSION = 4 from nbmake.nb_result import NotebookResult from nbmake.nb_run import NotebookRun -from .helper import failing_nb, passing_nb, testdir2, write_nb +from .helper import failing_nb, passing_nb, write_nb pytest_plugins = "pytester" @@ -24,7 +22,7 @@ def test_when_passing_then_no_failing_cell(self, testdir2: Never): run = NotebookRun(filename, 300) res: NotebookResult = run.execute() - assert res.error == None + assert res.error is None def test_when_runs_then_cwd_is_nb_location(self, testdir2: Never): subdir = Path("subdir") @@ -36,7 +34,7 @@ def test_when_runs_then_cwd_is_nb_location(self, testdir2: Never): run = NotebookRun(subdir / filename, 300) res: NotebookResult = run.execute() - assert res.error == None + assert res.error is None def test_failing(self, testdir2: Never): write_nb(failing_nb, filename) @@ -108,25 +106,25 @@ def test_when_cell_ignored_then_does_not_run(self, testdir2: Never): nb = Path(__file__).parent / "resources" / "ignore_tag.ipynb" run = NotebookRun(nb, 300) res: NotebookResult = run.execute() - assert res.error == None + assert res.error is None def test_when_raises_exc_tag_then_succeeds(self, testdir2: Never): nb = Path(__file__).parent / "resources" / "raises_tag.ipynb" run = NotebookRun(nb, 300) res: NotebookResult = run.execute() - assert res.error == None + assert res.error is None def test_when_mock_then_succeeds(self, testdir2: Never): nb = Path(__file__).parent / "resources" / "mock.ipynb" run = NotebookRun(nb, 300) res: NotebookResult = run.execute() - assert res.error == None + assert res.error is None def test_when_post_cell_execute_then_succeeds(self, testdir2: Never): nb = Path(__file__).parent / "resources" / "post_cell_execute.ipynb" run = NotebookRun(nb, 300) res: NotebookResult = run.execute() - assert res.error == None + assert res.error is None def test_when_post_cell_execute_then_command_fails(self, testdir2: Never): nb = Path(__file__).parent / "resources" / "post_cell_execute_error.ipynb" @@ -134,7 +132,7 @@ def test_when_post_cell_execute_then_command_fails(self, testdir2: Never): with pytest.raises(Exception) as exc_info: run.execute() - assert exc_info != None + assert exc_info is not None assert "boom!" in exc_info.value.args[0] def test_when_post_cell_execute_then_cell_fails(self, testdir2: Never): @@ -146,14 +144,14 @@ def test_when_post_cell_execute_then_cell_fails(self, testdir2: Never): # make sure the cell exception (bang!) is raised and not masked # by the post cell execution exception (boom!) - assert res.error != None + assert res.error is not None assert "bang!" in res.error.summary def test_when_magic_error_then_fails(self, testdir2: Never): nb = Path(__file__).parent / "resources" / "magic_error.ipynb" run = NotebookRun(nb, 300) res: NotebookResult = run.execute() - assert res.error != None + assert res.error is not None def test_when_empty_then_succeeds(self, testdir2: Never): nb = Path(__file__).parent / "resources" / "empty.ipynb" diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py index b7384f7..232b7ff 100644 --- a/tests/test_pytest_plugin.py +++ b/tests/test_pytest_plugin.py @@ -1,15 +1,14 @@ from __future__ import print_function import os -from importlib import import_module, invalidate_caches, reload +from importlib import import_module, reload from pathlib import Path -from unittest.mock import patch from nbformat import read from pytest import ExitCode, Pytester from typing_extensions import Never -from .helper import failing_nb, passing_nb, testdir2, write_nb +from .helper import failing_nb, passing_nb, write_nb pytest_plugins = "pytester" NB_VERSION = 4 @@ -172,7 +171,7 @@ def test_when_explicit_metadata_then_ignore_timeout( def test_when_kernel_passed_then_override(pytester: Pytester, testdir2: Never): write_nb( passing_nb, - Path(f"x.ipynb"), + Path("x.ipynb"), metadata={ "kernelspec": { "display_name": "Python 3", @@ -199,7 +198,6 @@ def test_when_no_import_errs_then_pass(pytester: Pytester, testdir2: Never): def test_when_not_json_then_correct_err_msg(pytester: Pytester, testdir2: Never): - (Path(pytester.path) / "a.ipynb").write_text("invalid json") hook_recorder = pytester.inline_run("--nbmake")