Skip to content

Commit bf0c080

Browse files
authored
Adopt ruff format (#415)
1 parent b26c866 commit bf0c080

File tree

12 files changed

+67
-83
lines changed

12 files changed

+67
-83
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ci:
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.4.0
7+
rev: v4.5.0
88
hooks:
99
- id: check-case-conflict
1010
- id: check-ast
@@ -44,11 +44,6 @@ repos:
4444
- id: blacken-docs
4545
additional_dependencies: [black==23.7.0]
4646

47-
- repo: https://github.com/psf/black-pre-commit-mirror
48-
rev: 23.9.1
49-
hooks:
50-
- id: black
51-
5247
- repo: https://github.com/codespell-project/codespell
5348
rev: "v2.2.6"
5449
hooks:
@@ -63,13 +58,14 @@ repos:
6358
- id: rst-inline-touching-normal
6459

6560
- repo: https://github.com/astral-sh/ruff-pre-commit
66-
rev: v0.1.1
61+
rev: v0.1.3
6762
hooks:
6863
- id: ruff
6964
args: ["--fix", "--show-fixes"]
65+
- id: ruff-format
7066

7167
- repo: https://github.com/scientific-python/cookie
72-
rev: "2023.09.21"
68+
rev: "2023.10.27"
7369
hooks:
7470
- id: sp-repo-review
7571
additional_dependencies: ["repo-review[cli]"]

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
# Add an Edit this Page button
8383
html_theme_options = {
8484
"use_edit_page_button": True,
85+
"navigation_with_keys": False,
8586
}
8687

8788
# Output for github to be used in links

jupyterlab_server/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def initialize_settings(self) -> None:
116116
for extension_path in self.labextensions_path + self.extra_labextensions_path:
117117
extensions_url = [
118118
ujoin(self.labextensions_url, relpath(path, extension_path))
119-
for path in glob(f'{extension_path}/**/static', recursive=True)
119+
for path in glob(f"{extension_path}/**/static", recursive=True)
120120
]
121121

122122
immutable_cache.update(extensions_url)

jupyterlab_server/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def load_config(path: str) -> Any:
9898
Dictionary of json or json5 data
9999
"""
100100
with open(path, encoding="utf-8") as fid:
101-
if path.endswith('.json5'):
101+
if path.endswith(".json5"):
102102
return json5.load(fid)
103103
else:
104104
return json.load(fid)

jupyterlab_server/handlers.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ def get_page_config(self) -> dict[str, Any]:
122122
page_config.setdefault("fullMathjaxUrl", mathjax_url)
123123

124124
# Put all our config in page_config
125-
for name in config.trait_names(): # type:ignore[no-untyped-call]
125+
for name in config.trait_names():
126126
page_config[_camelCase(name)] = getattr(app, name)
127127

128128
# Add full versions of all the urls
129-
for name in config.trait_names(): # type:ignore[no-untyped-call]
129+
for name in config.trait_names():
130130
if not name.endswith("_url"):
131131
continue
132132
full_name = _camelCase("full_" + name)
@@ -169,9 +169,7 @@ def get(
169169
page_config["treePath"] = tree_path
170170

171171
# Write the template with the config.
172-
tpl = self.render_template(
173-
"index.html", page_config=page_config
174-
) # type:ignore[no-untyped-call]
172+
tpl = self.render_template("index.html", page_config=page_config) # type:ignore[no-untyped-call]
175173
self.write(tpl)
176174

177175

@@ -189,15 +187,15 @@ def get_page_config(self) -> dict[str, Any]:
189187
def add_handlers(handlers: list[Any], extension_app: LabServerApp) -> None: # noqa
190188
"""Add the appropriate handlers to the web app."""
191189
# Normalize directories.
192-
for name in LabConfig.class_trait_names(): # type:ignore[no-untyped-call]
190+
for name in LabConfig.class_trait_names():
193191
if not name.endswith("_dir"):
194192
continue
195193
value = getattr(extension_app, name)
196194
setattr(extension_app, name, value.replace(os.sep, "/"))
197195

198196
# Normalize urls
199197
# Local urls should have a leading slash but no trailing slash
200-
for name in LabConfig.class_trait_names(): # type:ignore[no-untyped-call]
198+
for name in LabConfig.class_trait_names():
201199
if not name.endswith("_url"):
202200
continue
203201
value = getattr(extension_app, name)

jupyterlab_server/settings_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get(self, schema_name: str = "") -> Any:
5252
locale = self.get_current_locale()
5353
translator.set_locale(locale)
5454

55-
ids_only = self.get_argument('ids_only', '') == 'true'
55+
ids_only = self.get_argument("ids_only", "") == "true"
5656

5757
result, warnings = get_settings(
5858
self.app_settings_dir,

jupyterlab_server/settings_utils.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ def _list_settings(
166166
rel_schema_dir, schema_base = os.path.split(rel_path)
167167
_id = schema_name = ":".join(
168168
[rel_schema_dir, schema_base[: -len(extension)]] # Remove file extension.
169-
).replace(
170-
"\\", "/"
171-
) # Normalize slashes.
169+
).replace("\\", "/") # Normalize slashes.
172170

173171
if ids_only:
174172
settings[_id] = dict(id=_id)
@@ -201,9 +199,7 @@ def _list_settings(
201199
rel_schema_dir, schema_base = os.path.split(rel_path)
202200
_id = schema_name = ":".join(
203201
[rel_schema_dir, schema_base[: -len(extension)]] # Remove file extension.
204-
).replace(
205-
"\\", "/"
206-
) # Normalize slashes.
202+
).replace("\\", "/") # Normalize slashes.
207203

208204
# bail if we've already handled the highest federated setting
209205
if _id in federated_settings:
@@ -327,9 +323,7 @@ def _get_overrides(app_settings_dir: str) -> tuple[dict[str, Any], str]:
327323
# to allow layering of defaults
328324
cm = ConfigManager(config_dir_name="labconfig")
329325

330-
for plugin_id, config in cm.get(
331-
"default_setting_overrides"
332-
).items(): # type:ignore[no-untyped-call]
326+
for plugin_id, config in cm.get("default_setting_overrides").items(): # type:ignore[no-untyped-call]
333327
recursive_update(overrides.setdefault(plugin_id, {}), config)
334328

335329
return overrides, error

jupyterlab_server/test_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(self, request: HTTPRequest, spec: Spec):
6363
@property
6464
def host_url(self) -> str:
6565
url = self.request.url
66-
return url[: url.index('/lab')]
66+
return url[: url.index("/lab")]
6767

6868
@property
6969
def path(self) -> str:
@@ -99,7 +99,7 @@ def body(self) -> str | None:
9999
if self.request.body is None:
100100
return None # type:ignore[unreachable]
101101
if not isinstance(self.request.body, bytes):
102-
msg = 'Request body is invalid' # type:ignore[unreachable]
102+
msg = "Request body is invalid" # type:ignore[unreachable]
103103
raise AssertionError(msg)
104104
return self.request.body.decode("utf-8")
105105

@@ -125,7 +125,7 @@ def __init__(self, response: HTTPResponse):
125125
@property
126126
def data(self) -> str:
127127
if not isinstance(self.response.body, bytes):
128-
msg = 'Response body is invalid' # type:ignore[unreachable]
128+
msg = "Response body is invalid" # type:ignore[unreachable]
129129
raise AssertionError(msg)
130130
return self.response.body.decode("utf-8")
131131

jupyterlab_server/themes_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _get_css(self) -> bytes:
7575
data = fid.read().decode("utf-8")
7676

7777
if not self.themes_url:
78-
return b''
78+
return b""
7979

8080
basedir = os.path.dirname(self.path).replace(os.sep, "/")
8181
basepath = ujoin(self.themes_url, basedir)

pyproject.toml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,20 @@ test = "mypy --install-types --non-interactive {args}"
115115

116116
[tool.hatch.envs.lint]
117117
dependencies = [
118-
"black[jupyter]==23.3.0",
119118
"mdformat>0.7",
120119
"mdformat-gfm>=0.3.5",
121-
"ruff==0.1.1"
120+
"ruff==0.1.3"
122121
]
123122
detached = true
124123
[tool.hatch.envs.lint.scripts]
125124
style = [
126125
"ruff {args:.}",
127-
"black --check --diff {args:.}",
126+
"ruff format {args:.}",
128127
"mdformat --check {args:docs *.md}"
129128
]
130129
fmt = [
131-
"black {args:.}",
132130
"ruff --fix {args:.}",
131+
"ruff format {args:.}",
133132
"mdformat {args:docs *.md}"
134133
]
135134

@@ -194,14 +193,11 @@ module = [
194193
]
195194
ignore_missing_imports = true
196195

197-
[tool.black]
198-
line-length = 100
199-
target-version = ["py38"]
200-
skip-string-normalization = true
201-
202196
[tool.ruff]
203197
target-version = "py38"
204198
line-length = 100
199+
200+
[tool.ruff.lint]
205201
select = [
206202
"A",
207203
"B",
@@ -213,7 +209,6 @@ select = [
213209
"FBT",
214210
"I",
215211
"ICN",
216-
"ISC",
217212
"N",
218213
"PLC",
219214
"PLE",
@@ -252,7 +247,7 @@ ignore = [
252247
"S101"
253248
]
254249

255-
[tool.ruff.per-file-ignores]
250+
[tool.ruff.lint.per-file-ignores]
256251
# S101 Use of `assert` detected
257252
# A001 Variable `id` is shadowing a python builtin
258253
# PLR2004 Magic value used in comparison

0 commit comments

Comments
 (0)