Skip to content

Commit dbe871b

Browse files
Apply ruff/pyupgrade rule UP032
UP032 Use f-string instead of `format` call
1 parent 39ce7c4 commit dbe871b

File tree

8 files changed

+31
-73
lines changed

8 files changed

+31
-73
lines changed

distributed/cli/dask_ssh.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,7 @@ def main(
189189
import distributed
190190

191191
print("\n---------------------------------------------------------------")
192-
print(
193-
" Dask.distributed v{version}\n".format(
194-
version=distributed.__version__
195-
)
196-
)
192+
print(f" Dask.distributed v{distributed.__version__}\n")
197193
print(f"Worker nodes: {len(hostnames)}")
198194
for i, host in enumerate(hostnames):
199195
print(f" {i}: {host}")

distributed/client.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,7 @@ def __init__(
11211121
security = getattr(self.cluster, "security", None)
11221122
elif address is not None and not isinstance(address, str):
11231123
raise TypeError(
1124-
"Scheduler address must be a string or a Cluster instance, got {}".format(
1125-
type(address)
1126-
)
1124+
f"Scheduler address must be a string or a Cluster instance, got {type(address)}"
11271125
)
11281126

11291127
# If connecting to an address and no explicit security is configured, attempt
@@ -1375,10 +1373,7 @@ def __repr__(self):
13751373
return text
13761374

13771375
elif self.scheduler is not None:
1378-
return "<{}: scheduler={!r}>".format(
1379-
self.__class__.__name__,
1380-
self.scheduler.address,
1381-
)
1376+
return f"<{self.__class__.__name__}: scheduler={self.scheduler.address!r}>"
13821377
else:
13831378
return f"<{self.__class__.__name__}: No scheduler connected>"
13841379

@@ -5892,8 +5887,8 @@ def count(self):
58925887
return len(self.futures) + len(self.queue.queue)
58935888

58945889
def __repr__(self):
5895-
return "<as_completed: waiting={} done={}>".format(
5896-
len(self.futures), len(self.queue.queue)
5890+
return (
5891+
f"<as_completed: waiting={len(self.futures)} done={len(self.queue.queue)}>"
58975892
)
58985893

58995894
def __iter__(self):

distributed/dashboard/components/nvml.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ def update(self):
151151
"escaped_worker": [url_escape(w) for w in worker],
152152
}
153153

154-
self.memory_figure.title.text = "GPU Memory: {} / {}".format(
155-
format_bytes(sum(memory)),
156-
format_bytes(memory_total),
154+
self.memory_figure.title.text = (
155+
f"GPU Memory: {format_bytes(sum(memory))} / {format_bytes(memory_total)}"
157156
)
158157
self.memory_figure.x_range.end = memory_max
159158

distributed/deploy/old_ssh.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,12 @@ def communicate():
208208
def start_scheduler(
209209
logdir, addr, port, ssh_username, ssh_port, ssh_private_key, remote_python=None
210210
):
211-
cmd = "{python} -m distributed.cli.dask_scheduler --port {port}".format(
212-
python=remote_python or sys.executable, port=port
213-
)
211+
cmd = f"{remote_python or sys.executable} -m distributed.cli.dask_scheduler --port {port}"
214212

215213
# Optionally re-direct stdout and stderr to a logfile
216214
if logdir is not None:
217215
cmd = f"mkdir -p {logdir} && {cmd}"
218-
cmd += "&> {logdir}/dask_scheduler_{addr}:{port}.log".format(
219-
addr=addr, port=port, logdir=logdir
220-
)
216+
cmd += f"&> {logdir}/dask_scheduler_{addr}:{port}.log"
221217

222218
# Format output labels we can prepend to each line of output, and create
223219
# a 'status' key to keep track of jobs that terminate prematurely.
@@ -297,16 +293,12 @@ def start_worker(
297293
)
298294

299295
if local_directory is not None:
300-
cmd += " --local-directory {local_directory}".format(
301-
local_directory=local_directory
302-
)
296+
cmd += f" --local-directory {local_directory}"
303297

304298
# Optionally redirect stdout and stderr to a logfile
305299
if logdir is not None:
306300
cmd = f"mkdir -p {logdir} && {cmd}"
307-
cmd += "&> {logdir}/dask_scheduler_{addr}.log".format(
308-
addr=worker_addr, logdir=logdir
309-
)
301+
cmd += f"&> {logdir}/dask_scheduler_{worker_addr}.log"
310302

311303
label = f"worker {worker_addr}"
312304

@@ -402,9 +394,7 @@ def __init__(
402394
)
403395
print(
404396
bcolors.WARNING + "Output will be redirected to logfiles "
405-
'stored locally on individual worker nodes under "{logdir}".'.format(
406-
logdir=logdir
407-
)
397+
f'stored locally on individual worker nodes under "{logdir}".'
408398
+ bcolors.ENDC
409399
)
410400
self.logdir = logdir

distributed/deploy/ssh.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,11 @@ async def start(self):
137137

138138
result = await self.connection.run("uname")
139139
if result.exit_status == 0:
140-
set_env = 'env DASK_INTERNAL_INHERIT_CONFIG="{}"'.format(
141-
dask.config.serialize(dask.config.global_config)
142-
)
140+
set_env = f'env DASK_INTERNAL_INHERIT_CONFIG="{dask.config.serialize(dask.config.global_config)}"'
143141
else:
144142
result = await self.connection.run("cmd /c ver")
145143
if result.exit_status == 0:
146-
set_env = "set DASK_INTERNAL_INHERIT_CONFIG={} &&".format(
147-
dask.config.serialize(dask.config.global_config)
148-
)
144+
set_env = f"set DASK_INTERNAL_INHERIT_CONFIG={dask.config.serialize(dask.config.global_config)} &&"
149145
else:
150146
raise Exception(
151147
"Worker failed to set DASK_INTERNAL_INHERIT_CONFIG variable "
@@ -237,15 +233,11 @@ async def start(self):
237233

238234
result = await self.connection.run("uname")
239235
if result.exit_status == 0:
240-
set_env = 'env DASK_INTERNAL_INHERIT_CONFIG="{}"'.format(
241-
dask.config.serialize(dask.config.global_config)
242-
)
236+
set_env = f'env DASK_INTERNAL_INHERIT_CONFIG="{dask.config.serialize(dask.config.global_config)}"'
243237
else:
244238
result = await self.connection.run("cmd /c ver")
245239
if result.exit_status == 0:
246-
set_env = "set DASK_INTERNAL_INHERIT_CONFIG={} &&".format(
247-
dask.config.serialize(dask.config.global_config)
248-
)
240+
set_env = f"set DASK_INTERNAL_INHERIT_CONFIG={dask.config.serialize(dask.config.global_config)} &&"
249241
else:
250242
raise Exception(
251243
"Scheduler failed to set DASK_INTERNAL_INHERIT_CONFIG variable "

distributed/http/proxy.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ def initialize(self, dask_server=None, extra=None):
9797

9898
def get(self, port, host, proxied_path):
9999
worker_url = f"{host}:{port}/{proxied_path}"
100-
msg = """
101-
<p> Try navigating to <a href=http://{}>{}</a> for your worker dashboard </p>
100+
msg = f"""
101+
<p> Try navigating to <a href=http://{worker_url}>{worker_url}</a> for your worker dashboard </p>
102102
103103
<p>
104104
Dask tried to proxy you to that page through your
@@ -116,10 +116,7 @@ def get(self, port, host, proxied_path):
116116
but less common in production clusters. Your IT administrators
117117
will know more
118118
</p>
119-
""".format(
120-
worker_url,
121-
worker_url,
122-
)
119+
"""
123120
self.write(msg)
124121

125122

distributed/scheduler.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8552,44 +8552,33 @@ def profile_to_figure(state: object) -> object:
85528552
import distributed
85538553

85548554
# HTML
8555-
html = """
8555+
html = f"""
85568556
<h1> Dask Performance Report </h1>
85578557
85588558
<i> Select different tabs on the top for additional information </i>
85598559
8560-
<h2> Duration: {time} </h2>
8560+
<h2> Duration: {format_time(stop - start)} </h2>
85618561
<h2> Tasks Information </h2>
85628562
<ul>
8563-
<li> number of tasks: {ntasks} </li>
8563+
<li> number of tasks: {total_tasks} </li>
85648564
{tasks_timings}
85658565
</ul>
85668566
85678567
<h2> Scheduler Information </h2>
85688568
<ul>
8569-
<li> Address: {address} </li>
8570-
<li> Workers: {nworkers} </li>
8571-
<li> Threads: {threads} </li>
8572-
<li> Memory: {memory} </li>
8573-
<li> Dask Version: {dask_version} </li>
8574-
<li> Dask.Distributed Version: {distributed_version} </li>
8569+
<li> Address: {self.address} </li>
8570+
<li> Workers: {len(self.workers)} </li>
8571+
<li> Threads: {sum(ws.nthreads for ws in self.workers.values())} </li>
8572+
<li> Memory: {format_bytes(sum(ws.memory_limit for ws in self.workers.values()))} </li>
8573+
<li> Dask Version: {dask.__version__} </li>
8574+
<li> Dask.Distributed Version: {distributed.__version__} </li>
85758575
</ul>
85768576
85778577
<h2> Calling Code </h2>
85788578
<pre>
85798579
{code}
85808580
</pre>
8581-
""".format(
8582-
time=format_time(stop - start),
8583-
ntasks=total_tasks,
8584-
tasks_timings=tasks_timings,
8585-
address=self.address,
8586-
nworkers=len(self.workers),
8587-
threads=sum(ws.nthreads for ws in self.workers.values()),
8588-
memory=format_bytes(sum(ws.memory_limit for ws in self.workers.values())),
8589-
code=code,
8590-
dask_version=dask.__version__,
8591-
distributed_version=distributed.__version__,
8592-
)
8581+
"""
85938582
html = Div(text=html, styles=_STYLES)
85948583

85958584
html = TabPanel(child=html, title="Summary")

distributed/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ def get_ip_interface(ifname):
246246
if ifname not in net_if_addrs:
247247
allowed_ifnames = list(net_if_addrs.keys())
248248
raise ValueError(
249-
"{!r} is not a valid network interface. "
250-
"Valid network interfaces are: {}".format(ifname, allowed_ifnames)
249+
f"{ifname!r} is not a valid network interface. "
250+
f"Valid network interfaces are: {allowed_ifnames}"
251251
)
252252

253253
for info in net_if_addrs[ifname]:

0 commit comments

Comments
 (0)