Skip to content

Commit 00eb4ee

Browse files
authored
Update ruff config (#101)
1 parent 23b4434 commit 00eb4ee

File tree

9 files changed

+64
-56
lines changed

9 files changed

+64
-56
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
- id: trailing-whitespace
2222

2323
- repo: https://github.com/python-jsonschema/check-jsonschema
24-
rev: 0.27.1
24+
rev: 0.27.3
2525
hooks:
2626
- id: check-github-workflows
2727

@@ -56,7 +56,7 @@ repos:
5656
- id: rst-inline-touching-normal
5757

5858
- repo: https://github.com/pre-commit/mirrors-mypy
59-
rev: "v1.7.0"
59+
rev: "v1.7.1"
6060
hooks:
6161
- id: mypy
6262
files: "^jupyter_server_terminals"
@@ -66,7 +66,7 @@ repos:
6666
["traitlets>=5.13", "jupyter_server>=2.10.1", "terminado>=0.18"]
6767

6868
- repo: https://github.com/astral-sh/ruff-pre-commit
69-
rev: v0.1.5
69+
rev: v0.1.7
7070
hooks:
7171
- id: ruff
7272
types_or: [python, jupyter]
@@ -75,7 +75,7 @@ repos:
7575
types_or: [python, jupyter]
7676

7777
- repo: https://github.com/scientific-python/cookie
78-
rev: "2023.10.27"
78+
rev: "2023.11.17"
7979
hooks:
8080
- id: sp-repo-review
8181
additional_dependencies: ["repo-review[cli]"]

docs/source/conf.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
#
31
# Jupyter Server documentation build configuration file, created by
42
# sphinx-quickstart on Mon Apr 13 09:51:11 2015.
53
#
@@ -68,7 +66,7 @@
6866
]
6967

7068
try:
71-
import enchant # type:ignore # noqa
69+
import enchant # type:ignore[import] # noqa: F401
7270

7371
extensions += ["sphinxcontrib.spelling"]
7472
except ImportError:
@@ -92,7 +90,7 @@
9290

9391
# General information about the project.
9492
project = "Jupyter Server Terminals"
95-
copyright = "2021, Jupyter Team, https://jupyter.org" # noqa
93+
copyright = "2021, Jupyter Team, https://jupyter.org"
9694
author = "The Jupyter Server Team"
9795

9896
# ghissue config

jupyter_server_terminals/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
msg = "Jupyter Server must be installed to use this extension."
99
raise ModuleNotFoundError(msg) from None
1010

11-
if int(version_info[0]) < 2: # type:ignore[call-overload] # noqa
11+
if int(version_info[0]) < 2: # type:ignore[call-overload]
1212
msg = "Jupyter Server Terminals requires Jupyter Server 2.0+"
1313
raise RuntimeError(msg)
1414

jupyter_server_terminals/api_handlers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ def post(self) -> None:
5050
if cwd is None:
5151
server_root_dir = self.settings["server_root_dir"]
5252
self.log.debug(
53-
f"Failed to find requested terminal cwd: {data.get('cwd')}\n"
54-
f" It was not found within the server root neither: {server_root_dir}."
53+
"Failed to find requested terminal cwd: %s\n"
54+
" It was not found within the server root neither: %s.",
55+
data.get("cwd"),
56+
server_root_dir,
5557
)
5658
del data["cwd"]
5759
else:
58-
self.log.debug(f"Opening terminal in: {cwd.resolve()!s}")
60+
self.log.debug("Opening terminal in: %s", cwd.resolve())
5961
data["cwd"] = str(cwd.resolve())
6062

6163
model = self.terminal_manager.create(**data)

jupyter_server_terminals/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TerminalsExtensionApp(ExtensionApp):
3636

3737
def initialize_settings(self) -> None:
3838
"""Initialize settings."""
39-
if not self.serverapp.terminals_enabled:
39+
if not self.serverapp or not self.serverapp.terminals_enabled:
4040
return
4141
self.initialize_configurables()
4242
self.settings.update(
@@ -73,7 +73,7 @@ def initialize_configurables(self) -> None:
7373

7474
def initialize_handlers(self) -> None:
7575
"""Initialize handlers."""
76-
if not self.serverapp.terminals_enabled:
76+
if not self.serverapp or not self.serverapp.terminals_enabled:
7777
# Checking self.terminals_available instead breaks enabling terminals
7878
return
7979
self.handlers.append(
@@ -112,7 +112,7 @@ async def cleanup_terminals(self) -> None:
112112
terminal_msg = trans.ngettext(
113113
"Shutting down %d terminal", "Shutting down %d terminals", n_terminals
114114
)
115-
self.log.info(terminal_msg % n_terminals)
115+
self.log.info("%s %% %s", terminal_msg, n_terminals)
116116
await ensure_async(terminal_manager.terminate_all()) # type:ignore[arg-type]
117117

118118
async def stop_extension(self) -> None:

jupyter_server_terminals/terminalmanager.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ def create(self, **kwargs: t.Any) -> MODEL:
6262

6363
def get(self, name: str) -> MODEL:
6464
"""Get terminal 'name'."""
65-
model = self.get_terminal_model(name)
66-
return model
65+
return self.get_terminal_model(name)
6766

68-
def list(self) -> list[MODEL]: # noqa
67+
def list(self) -> list[MODEL]:
6968
"""Get a list of all running terminals."""
7069
models = [self.get_terminal_model(name) for name in self.terminals]
7170

@@ -94,11 +93,10 @@ def get_terminal_model(self, name: str) -> MODEL:
9493
"""
9594
self._check_terminal(name)
9695
term = self.terminals[name]
97-
model = {
96+
return {
9897
"name": name,
9998
"last_activity": isoformat(term.last_activity), # type:ignore[attr-defined]
10099
}
101-
return model
102100

103101
def _check_terminal(self, name: str) -> None:
104102
"""Check a that terminal 'name' exists and raise 404 if not."""
@@ -109,7 +107,7 @@ def _initialize_culler(self) -> None:
109107
"""Start culler if 'cull_inactive_timeout' is greater than zero.
110108
Regardless of that value, set flag that we've been here.
111109
"""
112-
if not self._initialized_culler and self.cull_inactive_timeout > 0: # noqa
110+
if not self._initialized_culler and self.cull_inactive_timeout > 0: # noqa: SIM102
113111
if self._culler_callback is None:
114112
_ = IOLoop.current()
115113
if self.cull_interval <= 0: # handle case where user set invalid value
@@ -144,7 +142,9 @@ async def _cull_terminals(self) -> None:
144142
except Exception as e:
145143
self.log.exception(
146144
"The following exception was encountered while checking the "
147-
f"activity of terminal {name}: {e}"
145+
"activity of terminal %s: %s",
146+
name,
147+
e,
148148
)
149149

150150
async def _cull_inactive_terminal(self, name: str) -> None:

pyproject.toml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ source = ["jupyter_server_terminals"]
125125
files = "jupyter_server_terminals"
126126
python_version = "3.8"
127127
strict = true
128-
show_error_codes = true
129128
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
130129
warn_unreachable = true
131130

@@ -134,26 +133,34 @@ warn_unreachable = true
134133
line-length = 100
135134

136135
[tool.ruff.lint]
137-
select = [
138-
"A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "N",
139-
"PLC", "PLE", "PLR", "PLW", "Q", "RUF", "S", "SIM", "T", "TID", "UP",
140-
"W", "YTT",
136+
extend-select = [
137+
"B", # flake8-bugbear
138+
"I", # isort
139+
"C4", # flake8-comprehensions
140+
"EM", # flake8-errmsg
141+
"ICN", # flake8-import-conventions
142+
"G", # flake8-logging-format
143+
"PGH", # pygrep-hooks
144+
"PIE", # flake8-pie
145+
"PL", # pylint
146+
"PTH", # flake8-use-pathlib
147+
"PT", # flake8-pytest-style
148+
"RET", # flake8-return
149+
"RUF", # Ruff-specific
150+
"SIM", # flake8-simplify
151+
"T20", # flake8-print
152+
"UP", # pyupgrade
153+
"YTT", # flake8-2020
154+
"EXE", # flake8-executable
155+
"PYI", # flake8-pyi
156+
"S", # flake8-bandit
141157
]
142158
ignore = [
143-
# Q000 Single quotes found but double quotes preferred
144-
"Q000",
145-
# FBT001 Boolean positional arg in function definition
146-
"FBT001", "FBT002", "FBT003",
147-
# E501 Line too long (158 > 100 characters)
148-
"E501",
149-
# SIM105 Use `contextlib.suppress(...)`
150-
"SIM105",
151-
# T201 `print` found
152-
"T201",
153-
# N802 Function name `CreateWellKnownSid` should be lowercase
154-
"N802", "N803",
155-
# S101 Use of `assert` detected
156-
"S101",
159+
"PLR", # Design related pylint codes
160+
"E501", # Line too long (158 > 100 characters)
161+
"SIM105", # Use `contextlib.suppress(...)`
162+
"T201", # `print` found
163+
"S101", # Use of `assert` detected
157164
]
158165
unfixable = [
159166
# Don't touch print statements
@@ -166,8 +173,8 @@ unfixable = [
166173
# B011: Do not call assert False since python -O removes these calls
167174
# F841 local variable 'foo' is assigned to but never used
168175
# S101 Use of `assert` detected
169-
# PLR2004 Magic value used in comparison
170-
"tests/*" = ["B011", "F841", "S101", "PLR2004"]
176+
"tests/*" = ["B011", "F841"]
177+
"docs/*" = ["PTH"]
171178

172179
[tool.interrogate]
173180
ignore-init-module=true
@@ -180,4 +187,4 @@ fail-under=100
180187
exclude = ["tests", "docs"]
181188

182189
[tool.repo-review]
183-
ignore = ["PY007", "GH102"]
190+
ignore = ["GH102"]

tests/test_auth.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AuthorizerforTesting(Authorizer):
1414
# Set these class attributes from within a test
1515
# to verify that they match the arguments passed
1616
# by the REST API.
17-
permissions: Dict[str, str] = {} # noqa
17+
permissions: Dict[str, str] = {} # noqa: RUF012
1818

1919
def normalize_url(self, path):
2020
"""Drop the base URL and make sure path leads with a /"""
@@ -50,7 +50,7 @@ def is_authorized(self, handler, user, action, resource):
5050
)
5151

5252

53-
@pytest.fixture
53+
@pytest.fixture()
5454
def jp_server_config():
5555
return Config(
5656
{
@@ -62,7 +62,7 @@ def jp_server_config():
6262
)
6363

6464

65-
@pytest.fixture
65+
@pytest.fixture()
6666
def send_request(jp_fetch, jp_ws_fetch):
6767
"""Send to Jupyter Server and return response code."""
6868

@@ -109,9 +109,9 @@ async def _(url, **fetch_kwargs):
109109
# -------- Test scenarios -----------
110110

111111

112-
@pytest.mark.parametrize("method, url, body", HTTP_REQUESTS_PARAMETRIZED)
113-
@pytest.mark.parametrize("allowed", (True, False))
114-
async def test_authorized_requests( # noqa
112+
@pytest.mark.parametrize("method, url, body", HTTP_REQUESTS_PARAMETRIZED) # noqa: PT006
113+
@pytest.mark.parametrize("allowed", (True, False)) # noqa: PT007
114+
async def test_authorized_requests(
115115
request,
116116
io_loop,
117117
send_request,

tests/test_terminal.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import os
44
import shutil
55
import sys
6+
from pathlib import Path
67

78
import pytest
89
from tornado.httpclient import HTTPClientError
910
from traitlets.config.loader import Config
1011

1112

12-
@pytest.fixture
13+
@pytest.fixture()
1314
def terminal_path(tmp_path):
1415
subdir = tmp_path.joinpath("terminal_path")
1516
subdir.mkdir()
@@ -19,7 +20,7 @@ def terminal_path(tmp_path):
1920
shutil.rmtree(str(subdir), ignore_errors=True)
2021

2122

22-
@pytest.fixture
23+
@pytest.fixture()
2324
def terminal_root_dir(jp_root_dir):
2425
subdir = jp_root_dir.joinpath("terminal_path")
2526
subdir.mkdir()
@@ -33,7 +34,7 @@ def terminal_root_dir(jp_root_dir):
3334
CULL_INTERVAL = 3
3435

3536

36-
@pytest.fixture
37+
@pytest.fixture()
3738
def jp_server_config():
3839
return Config(
3940
{
@@ -148,7 +149,7 @@ async def test_terminal_create_with_cwd(jp_fetch, jp_ws_fetch, terminal_path):
148149

149150
ws.close()
150151

151-
assert os.path.basename(terminal_path) in message_stdout
152+
assert Path(terminal_path).name in message_stdout
152153

153154

154155
async def test_terminal_create_with_relative_cwd(
@@ -195,7 +196,7 @@ async def test_terminal_create_with_relative_cwd(
195196

196197

197198
async def test_terminal_create_with_bad_cwd(jp_fetch, jp_ws_fetch):
198-
non_existing_path = "/tmp/path/to/nowhere" # noqa
199+
non_existing_path = "/tmp/path/to/nowhere" # noqa: S108
199200
resp = await jp_fetch(
200201
"api",
201202
"terminals",
@@ -268,7 +269,7 @@ async def test_culling(jp_fetch):
268269
allow_nonstandard_methods=True,
269270
)
270271
except HTTPClientError as e:
271-
assert e.code == 404
272+
assert e.code == 404 # noqa: PT017
272273
culled = True
273274
break
274275
else:

0 commit comments

Comments
 (0)