Skip to content

Commit 6e4ca76

Browse files
authored
Migrate from black to ruff format (#9295)
1 parent f2c923a commit 6e4ca76

27 files changed

Lines changed: 92 additions & 84 deletions

.pre-commit-config.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.15.2
3+
rev: v0.15.16
44
hooks:
55
- id: ruff-check
66
# args: [--fix]
7-
- repo: https://github.com/psf/black-pre-commit-mirror
8-
rev: 26.3.1
9-
hooks:
10-
- id: black
7+
- id: ruff-format
118
- repo: https://github.com/codespell-project/codespell
129
rev: v2.4.2
1310
hooks:

continuous_integration/scripts/test_report.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ def download_and_parse_artifacts(
394394
# the same workflow run can be aligned according to the same trigger
395395
# time.
396396
html_url = jobs_df[jobs_df["suite_name"] == a["name"]].html_url.unique()
397-
assert (
398-
len(html_url) == 1
399-
), f"Artifact suite name {a['name']} did not match any jobs dataframe:\n{jobs_df['suite_name'].unique()}"
397+
assert len(html_url) == 1, (
398+
f"Artifact suite name {a['name']} did not match any jobs dataframe:\n{jobs_df['suite_name'].unique()}"
399+
)
400400
html_url = html_url[0]
401401
assert html_url is not None
402402
df2 = df.assign(

distributed/cli/dask_worker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ def del_pid_file():
381381
and dask.config.get("scheduler-address", None) is None
382382
):
383383
raise ValueError(
384-
"Need to provide scheduler address like\n"
385-
"dask worker SCHEDULER_ADDRESS:8786"
384+
"Need to provide scheduler address like "
385+
"`dask worker SCHEDULER_ADDRESS:8786`"
386386
)
387387

388388
with suppress(TypeError, ValueError):

distributed/cli/tests/test_dask_worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
@pytest.mark.parametrize(
3131
# args: (worker_port, nanny_port, n_workers, nanny)
32-
# Passing *args tuple instead of single args is to improve readability with black
32+
# Passing *args tuple instead of single args is to improve readability
33+
# with ruff format
3334
"args,expect",
3435
[
3536
# Single worker

distributed/client.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,8 +1542,7 @@ async def _reconnect(self):
15421542

15431543
else:
15441544
logger.error(
1545-
"Failed to reconnect to scheduler after %.2f "
1546-
"seconds, closing client",
1545+
"Failed to reconnect to scheduler after %.2f seconds, closing client",
15471546
self._timeout,
15481547
)
15491548
await self._close()
@@ -3137,8 +3136,7 @@ async def _run(
31373136
results[key] = exc
31383137
elif on_error != "ignore":
31393138
raise ValueError(
3140-
"on_error must be 'raise', 'return', or 'ignore'; "
3141-
f"got {on_error!r}"
3139+
f"on_error must be 'raise', 'return', or 'ignore'; got {on_error!r}"
31423140
)
31433141

31443142
if wait:
@@ -3922,13 +3920,13 @@ async def _restart_workers(
39223920
name_to_addr = {meta["name"]: addr for addr, meta in info["workers"].items()}
39233921
worker_addrs = [name_to_addr.get(w, w) for w in workers]
39243922

3925-
out: dict[str, Literal["OK", "removed", "timed out"]] = (
3926-
await self.scheduler.restart_workers(
3927-
workers=worker_addrs,
3928-
timeout=timeout,
3929-
on_error="raise" if raise_for_error else "return",
3930-
stimulus_id=f"client-restart-workers-{time()}",
3931-
)
3923+
out: dict[
3924+
str, Literal["OK", "removed", "timed out"]
3925+
] = await self.scheduler.restart_workers(
3926+
workers=worker_addrs,
3927+
timeout=timeout,
3928+
on_error="raise" if raise_for_error else "return",
3929+
stimulus_id=f"client-restart-workers-{time()}",
39323930
)
39333931
# Map keys back to original `workers` input names/addresses
39343932
out = {w: out[w_addr] for w, w_addr in zip(workers, worker_addrs)}

distributed/comm/addressing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ def uri_from_host_port(
200200
# Note `port = 0` means "choose a random port"
201201
if port != 0 and port_arg and port != int(port_arg):
202202
raise ValueError(
203-
"port number given twice in options: "
204-
f"host {host_arg} and port {port_arg}"
203+
f"port number given twice in options: host {host_arg} and port {port_arg}"
205204
)
206205

207206
loc = unparse_host_port(host, port)

distributed/dashboard/tests/test_scheduler_bokeh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,9 @@ async def test_proxy_to_workers(s, a, b):
11391139
proxy_url = f"http://localhost:{dashboard_port}/proxy/1234/{unsafe_host}/status"
11401140
response = await http_client.fetch(proxy_url, raise_error=False)
11411141
assert response.code == 400
1142-
assert (
1143-
unsafe_host not in response.body.decode()
1144-
), "Unsafe characters should be escaped"
1142+
assert unsafe_host not in response.body.decode(), (
1143+
"Unsafe characters should be escaped"
1144+
)
11451145

11461146

11471147
@gen_cluster(

distributed/deploy/tests/test_local.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,7 @@ async def test_adapt_then_manual():
770770

771771
def wait_workers(n):
772772
return async_poll_for(
773-
lambda: len(cluster.scheduler.workers) == n
774-
and len(cluster.workers) == n
773+
lambda: len(cluster.scheduler.workers) == len(cluster.workers) == n
775774
)
776775

777776
await wait_workers(8)

distributed/diagnostics/memray.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def _fetch_memray_profile(
5858
if not report_args[0] == "memray":
5959
report_args = ["memray"] + list(report_args)
6060
assert "-f" not in report_args, "Cannot provide filename for report generation"
61-
assert (
62-
"-o" not in report_args
63-
), "Cannot provide output filename for report generation"
61+
assert "-o" not in report_args, (
62+
"Cannot provide output filename for report generation"
63+
)
6464
report_args = list(report_args) + ["-f", str(path), "-o", str(report_filename)]
6565
subprocess.run(report_args)
6666
with open(report_filename, "rb") as fd:

distributed/diagnostics/progressbar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ def _draw_bar(self, remaining, all, status, **kwargs):
417417
)
418418
self.bars[k].value = ndone / ntasks if ntasks else 1.0
419419
self.bar_texts[k].value = (
420-
f'<div style="padding: 0px 10px 0px 10px; text-align: right">{ndone} / {ntasks}</div>'
420+
f'<div style="padding: 0px 10px 0px 10px; text-align: right">'
421+
f"{ndone} / {ntasks}</div>"
421422
)
422423

423424

0 commit comments

Comments
 (0)