Skip to content

Commit 361d1fd

Browse files
authored
style: fix Ruff 0.8.0 UP031 errors (#510)
1 parent 051a69e commit 361d1fd

File tree

10 files changed

+21
-37
lines changed

10 files changed

+21
-37
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# -- Project information -----------------------------------------------------
2121

2222
project = "DPDispatcher"
23-
copyright = "2020-%d, Deep Modeling" % date.today().year
23+
copyright = f"2020-{date.today().year}, Deep Modeling"
2424
author = "DeepModeling"
2525

2626

dpdispatcher/base_context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ def block_checkcall(self, cmd, asynchronously=False) -> Tuple[Any, Any, Any]:
102102
exit_status, stdin, stdout, stderr = self.block_call(cmd)
103103
if exit_status != 0:
104104
raise RuntimeError(
105-
"Get error code %d in calling %s with job: %s . message: %s"
106-
% (
105+
"Get error code {} in calling {} with job: {} . message: {}".format(
107106
exit_status,
108107
cmd,
109108
self.submission.submission_hash,

dpdispatcher/contexts/ssh_context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ def ensure_alive(self, max_check=10, sleep_time=10):
9090
while not self._check_alive():
9191
if count == max_check:
9292
raise RuntimeError(
93-
"cannot connect ssh after %d failures at interval %d s"
94-
% (max_check, sleep_time)
93+
f"cannot connect ssh after {max_check} failures at interval {sleep_time} s"
9594
)
9695
dlog.info("connection check failed, try to reconnect to " + self.hostname)
9796
self._setup_ssh()

dpdispatcher/machines/JH_UniScheduler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def check_status(self, job):
105105
elif ret != 0:
106106
# just retry when any unknown error raised.
107107
raise RetrySignal(
108-
"Get error code %d in checking status with job: %s . message: %s"
109-
% (ret, job.job_hash, err_str)
108+
f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}"
110109
)
111110
status_out = stdout.read().decode("utf-8").split("\n")
112111
if len(status_out) < 2:

dpdispatcher/machines/distributed_shell.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ def do_submit(self, job):
181181
if ret != 0:
182182
err_str = stderr.decode("utf-8")
183183
raise RuntimeError(
184-
"Command %s fails to execute, error message:%s\nreturn code %d\n"
185-
% (cmd, err_str, ret)
184+
f"Command {cmd} fails to execute, error message:{err_str}\nreturn code {ret}\n"
186185
)
187186
job_id = int(stdout.decode("utf-8").strip())
188187

@@ -200,8 +199,7 @@ def check_status(self, job):
200199
if ret != 0:
201200
err_str = stderr.decode("utf-8")
202201
raise RuntimeError(
203-
"Command fails to execute, error message:%s\nreturn code %d\n"
204-
% (err_str, ret)
202+
f"Command fails to execute, error message:{err_str}\nreturn code {ret}\n"
205203
)
206204

207205
if_job_exists = bool(stdout.decode("utf-8").strip())

dpdispatcher/machines/lsf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ def check_status(self, job):
129129
elif ret != 0:
130130
# just retry when any unknown error raised.
131131
raise RetrySignal(
132-
"Get error code %d in checking status with job: %s . message: %s"
133-
% (ret, job.job_hash, err_str)
132+
f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}"
134133
)
135134
status_out = stdout.read().decode("utf-8").split("\n")
136135
if len(status_out) < 2:

dpdispatcher/machines/pbs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def check_status(self, job):
8787
return JobStatus.terminated
8888
else:
8989
raise RuntimeError(
90-
"status command %s fails to execute. erro info: %s return code %d"
91-
% (command, err_str, ret)
90+
f"status command {command} fails to execute. erro info: {err_str} return code {ret}"
9291
)
9392
status_line = stdout.read().decode("utf-8").split("\n")[-2]
9493
status_word = status_line.split()[-2]
@@ -138,8 +137,7 @@ def check_status(self, job):
138137
return JobStatus.terminated
139138
else:
140139
raise RuntimeError(
141-
"status command %s fails to execute. erro info: %s return code %d"
142-
% (command, err_str, ret)
140+
f"status command {command} fails to execute. erro info: {err_str} return code {ret}"
143141
)
144142
status_line = stdout.read().decode("utf-8").split("\n")[-2]
145143
status_word = status_line.split()[-2]

dpdispatcher/machines/shell.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def do_submit(self, job):
4343
if ret != 0:
4444
err_str = stderr.read().decode("utf-8")
4545
raise RuntimeError(
46-
"status command %s fails to execute\nerror message:%s\nreturn code %d\n"
47-
% (cmd, err_str, ret)
46+
f"status command {cmd} fails to execute\nerror message:{err_str}\nreturn code {ret}\n"
4847
)
4948
job_id = int(stdout.read().decode("utf-8").strip())
5049
self.context.write_file(job_id_name, str(job_id))
@@ -80,8 +79,7 @@ def check_status(self, job):
8079
if ret != 0:
8180
err_str = stderr.read().decode("utf-8")
8281
raise RuntimeError(
83-
"status command %s fails to execute\nerror message:%s\nreturn code %d\n"
84-
% (cmd, err_str, ret)
82+
f"status command {cmd} fails to execute\nerror message:{err_str}\nreturn code {ret}\n"
8583
)
8684

8785
if_job_exists = bool(stdout.read().decode("utf-8").strip())

dpdispatcher/machines/slurm.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def do_submit(self, job):
9797
):
9898
# server network error, retry 3 times
9999
raise RetrySignal(
100-
"Get error code %d in submitting with job: %s . message: %s"
101-
% (ret, job.job_hash, err_str)
100+
f"Get error code {ret} in submitting with job: {job.job_hash} . message: {err_str}"
102101
)
103102
elif (
104103
"Job violates accounting/QOS policy" in err_str
@@ -109,8 +108,7 @@ def do_submit(self, job):
109108
# job number exceeds, skip the submitting
110109
return ""
111110
raise RuntimeError(
112-
"command %s fails to execute\nerror message:%s\nreturn code %d\n"
113-
% (command, err_str, ret)
111+
f"command {command} fails to execute\nerror message:{err_str}\nreturn code {ret}\n"
114112
)
115113
subret = stdout.readlines()
116114
# --parsable
@@ -145,13 +143,11 @@ def check_status(self, job):
145143
):
146144
# retry 3 times
147145
raise RetrySignal(
148-
"Get error code %d in checking status with job: %s . message: %s"
149-
% (ret, job.job_hash, err_str)
146+
f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}"
150147
)
151148
raise RuntimeError(
152-
"status command %s fails to execute."
153-
"job_id:%s \n error message:%s\n return code %d\n"
154-
% (command, job_id, err_str, ret)
149+
f"status command {command} fails to execute."
150+
f"job_id:{job_id} \n error message:{err_str}\n return code {ret}\n"
155151
)
156152
status_line = stdout.read().decode("utf-8").split("\n")[-2]
157153
status_word = status_line.split()[-1]
@@ -255,7 +251,7 @@ def gen_script_header(self, job):
255251
return super().gen_script_header(job) + "\n#SBATCH --array={}".format(
256252
",".join(map(str, job_array))
257253
)
258-
return super().gen_script_header(job) + "\n#SBATCH --array=0-%d" % (
254+
return super().gen_script_header(job) + "\n#SBATCH --array=0-%s" % (
259255
math.ceil(len(job.job_task_list) / slurm_job_size) - 1
260256
)
261257

@@ -333,13 +329,11 @@ def check_status(self, job):
333329
):
334330
# retry 3 times
335331
raise RetrySignal(
336-
"Get error code %d in checking status with job: %s . message: %s"
337-
% (ret, job.job_hash, err_str)
332+
f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}"
338333
)
339334
raise RuntimeError(
340-
"status command %s fails to execute."
341-
"job_id:%s \n error message:%s\n return code %d\n"
342-
% (command, job_id, err_str, ret)
335+
f"status command {command} fails to execute."
336+
f"job_id:{job_id} \n error message:{err_str}\n return code {ret}\n"
343337
)
344338
status_lines = stdout.read().decode("utf-8").split("\n")[:-1]
345339
status = []

dpdispatcher/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def wrapper(*args, **kwargs):
191191
else:
192192
# raise all exceptions
193193
raise RuntimeError(
194-
"Failed to run %s for %d times" % (func.__name__, current_retry)
194+
f"Failed to run {func.__name__} for {current_retry} times"
195195
) from errors[-1]
196196

197197
return wrapper

0 commit comments

Comments
 (0)