From 6094f1546fe3aa272004be12ed7fccc29193f38e Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 4 Nov 2023 21:50:07 -0500 Subject: [PATCH 1/8] clean up lint and move tests out --- .github/workflows/main.yml | 16 ++++--- .pre-commit-config.yaml | 15 +++++++ nbclient/cli.py | 2 +- nbclient/client.py | 4 +- pyproject.toml | 39 +++++++----------- {nbclient/tests => tests}/__init__.py | 0 {nbclient/tests => tests}/base.py | 0 {nbclient/tests => tests}/conftest.py | 0 .../tests => tests}/fake_kernelmanager.py | 0 .../tests => tests}/files/Autokill.ipynb | 0 .../files/Check History in Memory.ipynb | 0 .../tests => tests}/files/Clear Output.ipynb | 0 .../tests => tests}/files/Disable Stdin.ipynb | 0 .../tests => tests}/files/Empty Cell.ipynb | 0 {nbclient/tests => tests}/files/Error.ipynb | 0 .../tests => tests}/files/Factorials.ipynb | 0 .../tests => tests}/files/HelloWorld.ipynb | 0 .../tests => tests}/files/Inline Image.ipynb | 0 .../tests => tests}/files/Interrupt.ipynb | 0 .../files/JupyterWidgets.ipynb | 0 .../tests => tests}/files/Other Comms.ipynb | 0 {nbclient/tests => tests}/files/Output.ipynb | 0 .../files/Parallel Execute A.ipynb | 0 .../files/Parallel Execute B.ipynb | 0 {nbclient/tests => tests}/files/SVG.ipynb | 0 .../Skip Exceptions with Cell Tags.ipynb | 0 .../files/Skip Exceptions.ipynb | 0 .../files/Skip Execution with Cell Tag.ipynb | 0 {nbclient/tests => tests}/files/Sleep1s.ipynb | 0 {nbclient/tests => tests}/files/Unicode.ipynb | 0 .../tests => tests}/files/UnicodePy3.ipynb | 0 {nbclient/tests => tests}/files/python.png | Bin .../files/update-display-id.ipynb | 0 {nbclient/tests => tests}/test_client.py | 0 {nbclient/tests => tests}/test_util.py | 0 35 files changed, 42 insertions(+), 34 deletions(-) rename {nbclient/tests => tests}/__init__.py (100%) rename {nbclient/tests => tests}/base.py (100%) rename {nbclient/tests => tests}/conftest.py (100%) rename {nbclient/tests => tests}/fake_kernelmanager.py (100%) rename {nbclient/tests => tests}/files/Autokill.ipynb (100%) rename {nbclient/tests => tests}/files/Check History in Memory.ipynb (100%) rename {nbclient/tests => tests}/files/Clear Output.ipynb (100%) rename {nbclient/tests => tests}/files/Disable Stdin.ipynb (100%) rename {nbclient/tests => tests}/files/Empty Cell.ipynb (100%) rename {nbclient/tests => tests}/files/Error.ipynb (100%) rename {nbclient/tests => tests}/files/Factorials.ipynb (100%) rename {nbclient/tests => tests}/files/HelloWorld.ipynb (100%) rename {nbclient/tests => tests}/files/Inline Image.ipynb (100%) rename {nbclient/tests => tests}/files/Interrupt.ipynb (100%) rename {nbclient/tests => tests}/files/JupyterWidgets.ipynb (100%) rename {nbclient/tests => tests}/files/Other Comms.ipynb (100%) rename {nbclient/tests => tests}/files/Output.ipynb (100%) rename {nbclient/tests => tests}/files/Parallel Execute A.ipynb (100%) rename {nbclient/tests => tests}/files/Parallel Execute B.ipynb (100%) rename {nbclient/tests => tests}/files/SVG.ipynb (100%) rename {nbclient/tests => tests}/files/Skip Exceptions with Cell Tags.ipynb (100%) rename {nbclient/tests => tests}/files/Skip Exceptions.ipynb (100%) rename {nbclient/tests => tests}/files/Skip Execution with Cell Tag.ipynb (100%) rename {nbclient/tests => tests}/files/Sleep1s.ipynb (100%) rename {nbclient/tests => tests}/files/Unicode.ipynb (100%) rename {nbclient/tests => tests}/files/UnicodePy3.ipynb (100%) rename {nbclient/tests => tests}/files/python.png (100%) rename {nbclient/tests => tests}/files/update-display-id.ipynb (100%) rename {nbclient/tests => tests}/test_client.py (100%) rename {nbclient/tests => tests}/test_util.py (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bbec63ed..68c81ae4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,13 +41,17 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.8", "3.9", "3.10", "3.11"] - exclude: + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + python-version: ["3.8", "3.11"] + include: - os: windows-latest - python-version: 3.8 - - os: windows-latest - python-version: 3.9 + python-version: "3.9" + - os: ubuntu-latest + python-version: "pypy-3.8" + - os: ubuntu-latest + python-version: "3.12" + - os: macos-latest + python-version: "3.10" steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 12f2648f..379f2cba 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,6 +57,21 @@ repos: - id: rst-directive-colons - id: rst-inline-touching-normal + - repo: https://github.com/pre-commit/mirrors-mypy + rev: "v1.6.1" + hooks: + - id: mypy + files: "^nbclient" + stages: [manual] + args: ["--install-types", "--non-interactive"] + additional_dependencies: + [ + "traitlets>=5.13", + "jupyter_core>=5.3.2", + "jupyter_client", + "nbformat", + ] + - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.3 hooks: diff --git a/nbclient/cli.py b/nbclient/cli.py index afe587fa..2151095f 100644 --- a/nbclient/cli.py +++ b/nbclient/cli.py @@ -47,7 +47,7 @@ class NbClientApp(JupyterApp): flags = nbclient_flags description = "An application used to execute notebook files (*.ipynb)" - notebooks = List([], help="Path of notebooks to convert").tag(config=True) + notebooks = List(Unicode(), help="Path of notebooks to convert").tag(config=True) timeout = Integer( None, allow_none=True, diff --git a/nbclient/client.py b/nbclient/client.py index 0b42dc2b..794f630c 100644 --- a/nbclient/client.py +++ b/nbclient/client.py @@ -494,9 +494,9 @@ def create_kernel_manager(self) -> KernelManager: self.kernel_name = kn if not self.kernel_name: - self.km = self.kernel_manager_class(config=self.config) # type:ignore[operator] + self.km = self.kernel_manager_class(config=self.config) else: - self.km = self.kernel_manager_class(kernel_name=self.kernel_name, config=self.config) # type:ignore[operator] + self.km = self.kernel_manager_class(kernel_name=self.kernel_name, config=self.config) assert self.km is not None return self.km diff --git a/pyproject.toml b/pyproject.toml index 4e973f57..abf17402 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,40 +104,27 @@ dependencies = ["coverage[toml]", "pytest-cov"] test = "python -m pytest -vv --cov nbclient --cov-branch --cov-report term-missing:skip-covered {args}" nowarn = "test -W default {args}" -[tool.hatch.envs.typing] -features = ["test"] -dependencies = ["mypy~=1.6", "traitlets>=5.11.2", "jupyter_core>=5.3.2"] -[tool.hatch.envs.typing.scripts] -test = "mypy --install-types --non-interactive {args}" - [tool.hatch.envs.lint] -dependencies = [ - "mdformat>0.7", - "mdformat-gfm>=0.3.5", - "ruff==0.1.3" -] detached = true +dependencies = ["pre-commit"] [tool.hatch.envs.lint.scripts] -style = [ - "ruff {args:.}", - "ruff format {args:.}", - "mdformat --check {args:docs *.md}" -] -fmt = [ - "ruff --fix {args:.}", - "ruff format {args:.}", - "mdformat {args:docs *.md}" -] +build = "pre-commit run --all-files ruff" + +[tool.hatch.envs.typing] +dependencies = [ "pre-commit"] +detached = true +[tool.hatch.envs.typing.scripts] +test = "pre-commit run --all-files --hook-stage manual mypy" [tool.pytest.ini_options] minversion = "6.0" xfail_strict = true log_cli_level = "info" addopts = [ - "-raXs", "--durations=10", "--color=yes", "--doctest-modules", + "-ra", "--durations=10", "--color=yes", "--doctest-modules", "--showlocals", "--strict-markers", "--strict-config" ] -testpaths = ["nbclient/tests"] +testpaths = ["tests"] filterwarnings= [ # Fail on warnings "error", @@ -146,7 +133,9 @@ filterwarnings= [ "module:There is no current event loop:DeprecationWarning", "module:unclosed event loop:ResourceWarning", "module:Unclosed socket Date: Sat, 4 Nov 2023 22:01:10 -0500 Subject: [PATCH 2/8] fixups --- .github/workflows/main.yml | 2 +- docs/index.rst | 1 - docs/reference/nbclient.tests.rst | 38 ------------------------------- pyproject.toml | 1 + 4 files changed, 2 insertions(+), 40 deletions(-) delete mode 100644 docs/reference/nbclient.tests.rst diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 68c81ae4..1663b379 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: - name: Run Linters run: | hatch run typing:test - hatch run lint:style + hatch run lint:build pipx run interrogate -v . pipx run doc8 --max-line-length=200 diff --git a/docs/index.rst b/docs/index.rst index e7992871..adab3887 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -64,7 +64,6 @@ this documentation section will help you. :caption: Table of Contents reference/index.rst - reference/nbclient.tests.rst Indices and tables ------------------ diff --git a/docs/reference/nbclient.tests.rst b/docs/reference/nbclient.tests.rst deleted file mode 100644 index 8ede97f1..00000000 --- a/docs/reference/nbclient.tests.rst +++ /dev/null @@ -1,38 +0,0 @@ -nbclient.tests package -====================== - -Submodules ----------- - -nbclient.tests.base module --------------------------- - -.. automodule:: nbclient.tests.base - :members: - :undoc-members: - :show-inheritance: - -nbclient.tests.fake\_kernelmanager module ------------------------------------------ - -.. automodule:: nbclient.tests.fake_kernelmanager - :members: - :undoc-members: - :show-inheritance: - -nbclient.tests.test\_client module ----------------------------------- - -.. automodule:: nbclient.tests.test_client - :members: - :undoc-members: - :show-inheritance: - - -Module contents ---------------- - -.. automodule:: nbclient.tests - :members: - :undoc-members: - :show-inheritance: diff --git a/pyproject.toml b/pyproject.toml index abf17402..a1a2260d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -136,6 +136,7 @@ filterwarnings= [ "module:zmq.eventloop.ioloop is deprecated:DeprecationWarning", "module:subprocess .* is still running:ResourceWarning", "module:Unclosed context Date: Sat, 4 Nov 2023 22:03:19 -0500 Subject: [PATCH 3/8] fixup --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a1a2260d..90ffa3b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -205,7 +205,7 @@ ignore-property-decorators=true ignore-nested-functions=true ignore-nested-classes=true fail-under=100 -exclude = ["nbclient/tests", "docs"] +exclude = ["tests", "docs"] [tool.repo-review] ignore = ["PY005", "PY007", "GH102"] From b460cf3435cc50c611caf43419b325a8c1557370 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 4 Nov 2023 22:05:51 -0500 Subject: [PATCH 4/8] include tests in sdist --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 90ffa3b4..d53e5f38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,7 @@ path = "nbclient/_version.py" [tool.hatch.build.targets.sdist] include = [ "/nbclient", + "/tests" ] [tool.hatch.envs.docs] From 5a84d54cbf0941f4cc14bab33ef976d373f41194 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 4 Nov 2023 22:06:43 -0500 Subject: [PATCH 5/8] fix docs --- docs/reference/nbclient.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/reference/nbclient.rst b/docs/reference/nbclient.rst index 636e7e60..e5744087 100644 --- a/docs/reference/nbclient.rst +++ b/docs/reference/nbclient.rst @@ -4,10 +4,6 @@ nbclient package Subpackages ----------- -.. toctree:: - - nbclient.tests - Submodules ---------- From c4e8846fba3b41d3d9bc75f208a792b2bdd8ea5b Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 4 Nov 2023 22:12:04 -0500 Subject: [PATCH 6/8] mark test as flaky --- tests/test_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_client.py b/tests/test_client.py index 54197df7..021ad84b 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -377,6 +377,7 @@ def test_parallel_notebooks(capfd, tmpdir): assert filter_messages_on_error_output(captured.err) == "" +@flaky @pytest.mark.skipif(os.name == "nt", reason="warns about event loop on Windows") def test_many_parallel_notebooks(capfd): """Ensure that when many IPython kernels are run in parallel, nothing awful happens. From 5d83a106770c8c82b50a9c86b890b0c10b804a66 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 4 Nov 2023 22:16:52 -0500 Subject: [PATCH 7/8] mark test as flaky --- tests/test_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_client.py b/tests/test_client.py index 021ad84b..cb8c3a08 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -405,6 +405,7 @@ def test_many_parallel_notebooks(capfd): assert filter_messages_on_error_output(captured.err) == "" +@flaky def test_async_parallel_notebooks(capfd, tmpdir): """Two notebooks should be able to be run simultaneously without problems. From bf9d7be0f1d96e351eb3bd1c7a709e73e774d8a0 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 4 Nov 2023 22:22:23 -0500 Subject: [PATCH 8/8] add another flaky --- tests/test_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_client.py b/tests/test_client.py index cb8c3a08..bca96981 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -352,6 +352,7 @@ def test_run_all_notebooks(input_name, opts): assert_notebooks_equal(input_nb, output_nb) +@flaky def test_parallel_notebooks(capfd, tmpdir): """Two notebooks should be able to be run simultaneously without problems.