Skip to content

Commit 8ac13da

Browse files
[pre-commit.ci] pre-commit autoupdate (#454)
<!--pre-commit.ci start--> updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.1 → v0.4.2](astral-sh/ruff-pre-commit@v0.4.1...v0.4.2) <!--pre-commit.ci end--> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
1 parent bc084dc commit 8ac13da

File tree

8 files changed

+23
-26
lines changed

8 files changed

+23
-26
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
# Python
1919
- repo: https://github.com/astral-sh/ruff-pre-commit
2020
# Ruff version.
21-
rev: v0.4.1
21+
rev: v0.4.2
2222
hooks:
2323
- id: ruff
2424
args: ["--fix"]

dpdispatcher/contexts/hdfs_context.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def download(
138138
shutil.rmtree(gz_dir, ignore_errors=True)
139139
os.mkdir(os.path.join(self.local_root, "tmp"))
140140
rfile_tgz = f"{self.remote_root}/{submission.submission_hash}_*_download.tar.gz"
141-
lfile_tgz = "%s/tmp/" % (self.local_root)
141+
lfile_tgz = f"{self.local_root}/tmp/"
142142
HDFS.copy_to_local(rfile_tgz, lfile_tgz)
143143

144144
tgz_file_list = glob(os.path.join(self.local_root, "tmp/*_download.tar.gz"))
@@ -164,7 +164,7 @@ def download(
164164
os.path.join(
165165
self.local_root,
166166
task.task_work_path,
167-
"tag_failure_download_%s" % jj,
167+
f"tag_failure_download_{jj}",
168168
),
169169
"w",
170170
) as fp:
@@ -198,9 +198,7 @@ def download(
198198
if check_exists:
199199
if mark_failure:
200200
with open(
201-
os.path.join(
202-
self.local_root, "tag_failure_download_%s" % jj
203-
),
201+
os.path.join(self.local_root, f"tag_failure_download_{jj}"),
204202
"w",
205203
) as fp:
206204
pass

dpdispatcher/contexts/local_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def download(
153153
tag_file_path = os.path.join(
154154
self.local_root,
155155
ii.task_work_path,
156-
"tag_failure_download_%s" % kk,
156+
f"tag_failure_download_{kk}",
157157
)
158158
with open(tag_file_path, "w") as fp:
159159
pass
@@ -181,7 +181,7 @@ def download(
181181
tag_file_path = os.path.join(
182182
self.local_root,
183183
ii.task_work_path,
184-
"tag_failure_download_%s" % jj,
184+
f"tag_failure_download_{jj}",
185185
)
186186
with open(tag_file_path, "w") as fp:
187187
pass
@@ -227,7 +227,7 @@ def download(
227227
if check_exists:
228228
if mark_failure:
229229
tag_file_path = os.path.join(
230-
self.local_root, "tag_failure_download_%s" % kk
230+
self.local_root, f"tag_failure_download_{kk}"
231231
)
232232
with open(tag_file_path, "w") as fp:
233233
pass
@@ -252,7 +252,7 @@ def download(
252252
if mark_failure:
253253
with open(
254254
os.path.join(
255-
self.local_root, "tag_failure_download_%s" % jj
255+
self.local_root, f"tag_failure_download_{jj}"
256256
),
257257
"w",
258258
) as fp:

dpdispatcher/contexts/ssh_context.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def exec_command(self, cmd):
300300
# retry for up to 3 times
301301
# ensure alive
302302
self.ensure_alive()
303-
raise RetrySignal("SSH session not active in calling %s" % cmd) from e
303+
raise RetrySignal(f"SSH session not active in calling {cmd}") from e
304304

305305
@property
306306
def sftp(self):
@@ -628,8 +628,7 @@ def upload(
628628
# check sha256
629629
# `:` means pass: https://stackoverflow.com/a/2421592/9567349
630630
_, stdout, _ = self.block_checkcall(
631-
"sha256sum -c %s --quiet >.sha256sum_stdout 2>/dev/null || :"
632-
% shlex.quote(sha256_file)
631+
f"sha256sum -c {shlex.quote(sha256_file)} --quiet >.sha256sum_stdout 2>/dev/null || :"
633632
)
634633
self.sftp.remove(sha256_file)
635634
# regenerate file list
@@ -708,7 +707,7 @@ def download(
708707
os.path.join(
709708
self.local_root,
710709
ii.task_work_path,
711-
"tag_failure_download_%s" % jj,
710+
f"tag_failure_download_{jj}",
712711
),
713712
"w",
714713
) as fp:
@@ -758,9 +757,9 @@ def block_checkcall(self, cmd, asynchronously=False, stderr_whitelist=None):
758757
assert self.remote_root is not None
759758
self.ssh_session.ensure_alive()
760759
if asynchronously:
761-
cmd = "nohup %s >/dev/null &" % cmd
760+
cmd = f"nohup {cmd} >/dev/null &"
762761
stdin, stdout, stderr = self.ssh_session.exec_command(
763-
("cd %s ;" % shlex.quote(self.remote_root)) + cmd
762+
(f"cd {shlex.quote(self.remote_root)} ;") + cmd
764763
)
765764
exit_status = stdout.channel.recv_exit_status()
766765
if exit_status != 0:
@@ -779,7 +778,7 @@ def block_call(self, cmd):
779778
assert self.remote_root is not None
780779
self.ssh_session.ensure_alive()
781780
stdin, stdout, stderr = self.ssh_session.exec_command(
782-
("cd %s ;" % shlex.quote(self.remote_root)) + cmd
781+
(f"cd {shlex.quote(self.remote_root)} ;") + cmd
783782
)
784783
exit_status = stdout.channel.recv_exit_status()
785784
return exit_status, stdin, stdout, stderr
@@ -846,12 +845,12 @@ def _rmtree(self, remotepath, verbose=False):
846845
# Thus, it's better to use system's `rm` to remove a directory, which may
847846
# save a lot of time.
848847
if verbose:
849-
dlog.info("removing %s" % remotepath)
848+
dlog.info(f"removing {remotepath}")
850849
# In some supercomputers, it's very slow to remove large numbers of files
851850
# (e.g. directory containing trajectory) due to bad I/O performance.
852851
# So an asynchronously option is provided.
853852
self.block_checkcall(
854-
"rm -rf %s" % shlex.quote(remotepath),
853+
f"rm -rf {shlex.quote(remotepath)}",
855854
asynchronously=self.clean_asynchronously,
856855
)
857856

@@ -921,7 +920,7 @@ def _put_files(
921920
f"from {from_f} to {self.ssh_session.username} @ {self.ssh_session.hostname} : {to_f} Error!"
922921
)
923922
# remote extract
924-
self.block_checkcall("tar xf %s" % of)
923+
self.block_checkcall(f"tar xf {of}")
925924
# clean up
926925
os.remove(from_f)
927926
self.sftp.remove(to_f)

dpdispatcher/machine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def gen_script_env(self, job):
261261

262262
source_list = job.resources.source_list
263263
for ii in source_list:
264-
line = "{ source %s; } \n" % ii
264+
line = f"{{ source {ii}; }} \n"
265265
source_files_part += line
266266

267267
export_envs_part = ""
@@ -466,7 +466,7 @@ def kill(self, job):
466466
job : Job
467467
job
468468
"""
469-
dlog.warning("Job %s should be manually killed" % job.job_id)
469+
dlog.warning(f"Job {job.job_id} should be manually killed")
470470

471471
def get_exit_code(self, job):
472472
"""Get exit code of the job.

dpdispatcher/machines/distributed_shell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def gen_script_env(self, job):
6464

6565
source_list = job.resources.source_list
6666
for ii in source_list:
67-
line = "{ source %s; } \n" % ii
67+
line = f"{{ source {ii}; }} \n"
6868
source_files_part += line
6969

7070
export_envs_part = ""
@@ -96,7 +96,7 @@ def gen_script_env(self, job):
9696
def gen_script_end(self, job):
9797
all_task_dirs = ""
9898
for task in job.job_task_list:
99-
all_task_dirs += "%s " % task.task_work_path
99+
all_task_dirs += f"{task.task_work_path} "
100100
job_tag_finished = job.job_hash + "_job_tag_finished"
101101
flag_if_job_task_fail = job.job_hash + "_flag_if_job_task_fail"
102102

dpdispatcher/machines/lsf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def check_status(self, job):
121121
return JobStatus.unsubmitted
122122
ret, stdin, stdout, stderr = self.context.block_call("bjobs " + job_id)
123123
err_str = stderr.read().decode("utf-8")
124-
if ("Job <%s> is not found" % job_id) in err_str:
124+
if (f"Job <{job_id}> is not found") in err_str:
125125
if self.check_finish_tag(job):
126126
return JobStatus.finished
127127
else:

dpdispatcher/machines/slurm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def gen_script_header(self, job):
254254
).as_posix()
255255
if not self.context.check_file_exists(task_tag_finished):
256256
job_array.add(ii // slurm_job_size)
257-
return super().gen_script_header(job) + "\n#SBATCH --array=%s" % (
257+
return super().gen_script_header(job) + "\n#SBATCH --array={}".format(
258258
",".join(map(str, job_array))
259259
)
260260
return super().gen_script_header(job) + "\n#SBATCH --array=0-%d" % (

0 commit comments

Comments
 (0)