From 3ab6a7b86d86636c080b62ec23d75786eb77a243 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 4 Nov 2023 22:29:57 -0500 Subject: [PATCH] Clean up lint and move tests out of source (#299) --- .github/workflows/main.yml | 18 +++++--- .pre-commit-config.yaml | 15 ++++++ docs/index.rst | 1 - docs/reference/nbclient.rst | 4 -- docs/reference/nbclient.tests.rst | 38 ---------------- nbclient/cli.py | 2 +- nbclient/client.py | 4 +- pyproject.toml | 43 +++++++----------- {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 | 3 ++ {nbclient/tests => tests}/test_util.py | 0 38 files changed, 49 insertions(+), 79 deletions(-) delete mode 100644 docs/reference/nbclient.tests.rst 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 (99%) rename {nbclient/tests => tests}/test_util.py (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bbec63ed..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 @@ -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/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.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 ---------- 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/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..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] @@ -104,40 +105,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 +134,10 @@ filterwarnings= [ "module:There is no current event loop:DeprecationWarning", "module:unclosed event loop:ResourceWarning", "module:Unclosed socket