diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index abe189c2a5..92a9022322 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,7 +50,7 @@ repos: files: "^notebook" stages: [manual] args: ["--install-types", "--non-interactive"] - additional_dependencies: ["traitlets>=5.13", "tornado", "jupyter_server>=2.9", "jupyterlab_server>=2.25", "jupyterlab>=4.0"] + additional_dependencies: ["traitlets>=5.13", "tornado", "jupyter_server>=2.10", "jupyterlab_server>=2.25", "jupyterlab>=4.0"] - repo: https://github.com/pre-commit/pygrep-hooks rev: 'v1.10.0' @@ -60,11 +60,15 @@ repos: - id: rst-inline-touching-normal - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.3 + rev: v0.1.5 hooks: - id: ruff + types_or: [ python, jupyter ] + exclude: '^docs/source/examples/Notebook/Importing Notebooks.ipynb' args: ['--fix', '--show-fixes'] - id: ruff-format + types_or: [ python, jupyter ] + exclude: '^docs/source/examples/Notebook/Importing Notebooks.ipynb' - repo: https://github.com/scientific-python/cookie rev: '2023.10.27' diff --git a/binder/example.ipynb b/binder/example.ipynb index c8d428ecd4..df3144614d 100644 --- a/binder/example.ipynb +++ b/binder/example.ipynb @@ -235,7 +235,7 @@ "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\\n", "\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n", "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n", - "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \n", + "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0\n", "\\end{eqnarray}\"\"\"\n", ")" ] @@ -277,8 +277,7 @@ "metadata": {}, "outputs": [], "source": [ - "from IPython.display import HTML\n", - "from IPython.display import display\n", + "from IPython.display import HTML, display\n", "\n", "s = \"\"\"\n", "\n", diff --git a/docs/source/examples/Notebook/Running Code.ipynb b/docs/source/examples/Notebook/Running Code.ipynb index 25879272ea..c932132601 100644 --- a/docs/source/examples/Notebook/Running Code.ipynb +++ b/docs/source/examples/Notebook/Running Code.ipynb @@ -124,7 +124,6 @@ "outputs": [], "source": [ "import sys\n", - "from ctypes import CDLL\n", "\n", "# This will crash a Linux or Mac system\n", "# equivalent calls can be made on Windows\n", @@ -225,9 +224,7 @@ } ], "source": [ - "from __future__ import print_function\n", - "\n", - "print('hi, stderr', file=sys.stderr)" + "print(\"hi, stderr\", file=sys.stderr)" ] }, { @@ -270,7 +267,8 @@ } ], "source": [ - "import time, sys\n", + "import sys\n", + "import time\n", "\n", "for i in range(8):\n", " print(i)\n", diff --git a/notebook/app.py b/notebook/app.py index 53cc86e65b..dffa397946 100644 --- a/notebook/app.py +++ b/notebook/app.py @@ -301,6 +301,8 @@ def _prepare_templates(self) -> None: def server_extension_is_enabled(self, extension: str) -> bool: """Check if server extension is enabled.""" + if self.serverapp is None: + return False try: extension_enabled = ( self.serverapp.extension_manager.extensions[extension].enabled is True @@ -311,6 +313,7 @@ def server_extension_is_enabled(self, extension: str) -> bool: def initialize_handlers(self) -> None: """Initialize handlers.""" + assert self.serverapp is not None # noqa: S101 page_config = self.serverapp.web_app.settings.setdefault("page_config_data", {}) nbclassic_enabled = self.server_extension_is_enabled("nbclassic") page_config["nbclassic_enabled"] = nbclassic_enabled diff --git a/pyproject.toml b/pyproject.toml index fb41a0e10f..e160b1fcda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -138,7 +138,10 @@ nowarn = "test -W default {args}" detached = true dependencies = ["pre-commit"] [tool.hatch.envs.lint.scripts] -build = "pre-commit run --all-files ruff" +build = [ + "pre-commit run --all-files ruff", + "pre-commit run --all-files ruff-format" +] [tool.hatch.envs.typing] dependencies = [ "pre-commit"] @@ -233,7 +236,6 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] warn_unreachable = true [tool.ruff] -target-version = "py38" line-length = 100 [tool.ruff.lint] @@ -260,6 +262,7 @@ ignore = [ "tests/*" = ["S101", "F841", "PLR2004"] # undefined name 'c' "ui-tests/test/jupyter_server_config.py" = ["F821"] +"*.ipynb" = ["E402", "B018", "E501", "T201"] [tool.interrogate] ignore-init-module=true diff --git a/ui-tests/test/notebooks/autoscroll.ipynb b/ui-tests/test/notebooks/autoscroll.ipynb index d386426b19..bcb8b23932 100644 --- a/ui-tests/test/notebooks/autoscroll.ipynb +++ b/ui-tests/test/notebooks/autoscroll.ipynb @@ -6,7 +6,9 @@ "id": "6f7028b9-4d2c-4fa2-96ee-bfa77bbee434", "metadata": {}, "outputs": [], - "source": ["print('1\\n' * 200)"] + "source": [ + "print(\"1\\n\" * 200)" + ] }, { "cell_type": "code", @@ -14,7 +16,9 @@ "id": "6f7028b9-4d2c-4fa2-96ee-bfa77bbee434", "metadata": {}, "outputs": [], - "source": ["print('1\\n' * 20)"] + "source": [ + "print(\"1\\n\" * 20)" + ] } ], "metadata": {