Skip to content

Commit

Permalink
Update ruff config and typing (jupyter#7145)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Nov 10, 2023
1 parent 875e4d7 commit 29d665d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -60,11 +60,15 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
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'
Expand Down
5 changes: 2 additions & 3 deletions binder/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
")"
]
Expand Down Expand Up @@ -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 = \"\"\"<table>\n",
"<tr>\n",
Expand Down
8 changes: 3 additions & 5 deletions docs/source/examples/Notebook/Running Code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -225,9 +224,7 @@
}
],
"source": [
"from __future__ import print_function\n",
"\n",
"print('hi, stderr', file=sys.stderr)"
"print(\"hi, stderr\", file=sys.stderr)"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions notebook/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions ui-tests/test/notebooks/autoscroll.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
"id": "6f7028b9-4d2c-4fa2-96ee-bfa77bbee434",
"metadata": {},
"outputs": [],
"source": ["print('1\\n' * 200)"]
"source": [
"print(\"1\\n\" * 200)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6f7028b9-4d2c-4fa2-96ee-bfa77bbee434",
"metadata": {},
"outputs": [],
"source": ["print('1\\n' * 20)"]
"source": [
"print(\"1\\n\" * 20)"
]
}
],
"metadata": {
Expand Down

0 comments on commit 29d665d

Please sign in to comment.