Skip to content

Commit

Permalink
style: fix Ruff 0.8.0 UP031 errors (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz-bot authored Nov 27, 2024
1 parent 051a69e commit 361d1fd
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 37 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# -- Project information -----------------------------------------------------

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


Expand Down
3 changes: 1 addition & 2 deletions dpdispatcher/base_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def block_checkcall(self, cmd, asynchronously=False) -> Tuple[Any, Any, Any]:
exit_status, stdin, stdout, stderr = self.block_call(cmd)
if exit_status != 0:
raise RuntimeError(
"Get error code %d in calling %s with job: %s . message: %s"
% (
"Get error code {} in calling {} with job: {} . message: {}".format(
exit_status,
cmd,
self.submission.submission_hash,
Expand Down
3 changes: 1 addition & 2 deletions dpdispatcher/contexts/ssh_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def ensure_alive(self, max_check=10, sleep_time=10):
while not self._check_alive():
if count == max_check:
raise RuntimeError(
"cannot connect ssh after %d failures at interval %d s"
% (max_check, sleep_time)
f"cannot connect ssh after {max_check} failures at interval {sleep_time} s"
)
dlog.info("connection check failed, try to reconnect to " + self.hostname)
self._setup_ssh()
Expand Down
3 changes: 1 addition & 2 deletions dpdispatcher/machines/JH_UniScheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def check_status(self, job):
elif ret != 0:
# just retry when any unknown error raised.
raise RetrySignal(
"Get error code %d in checking status with job: %s . message: %s"
% (ret, job.job_hash, err_str)
f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}"
)
status_out = stdout.read().decode("utf-8").split("\n")
if len(status_out) < 2:
Expand Down
6 changes: 2 additions & 4 deletions dpdispatcher/machines/distributed_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ def do_submit(self, job):
if ret != 0:
err_str = stderr.decode("utf-8")
raise RuntimeError(
"Command %s fails to execute, error message:%s\nreturn code %d\n"
% (cmd, err_str, ret)
f"Command {cmd} fails to execute, error message:{err_str}\nreturn code {ret}\n"
)
job_id = int(stdout.decode("utf-8").strip())

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

if_job_exists = bool(stdout.decode("utf-8").strip())
Expand Down
3 changes: 1 addition & 2 deletions dpdispatcher/machines/lsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def check_status(self, job):
elif ret != 0:
# just retry when any unknown error raised.
raise RetrySignal(
"Get error code %d in checking status with job: %s . message: %s"
% (ret, job.job_hash, err_str)
f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}"
)
status_out = stdout.read().decode("utf-8").split("\n")
if len(status_out) < 2:
Expand Down
6 changes: 2 additions & 4 deletions dpdispatcher/machines/pbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def check_status(self, job):
return JobStatus.terminated
else:
raise RuntimeError(
"status command %s fails to execute. erro info: %s return code %d"
% (command, err_str, ret)
f"status command {command} fails to execute. erro info: {err_str} return code {ret}"
)
status_line = stdout.read().decode("utf-8").split("\n")[-2]
status_word = status_line.split()[-2]
Expand Down Expand Up @@ -138,8 +137,7 @@ def check_status(self, job):
return JobStatus.terminated
else:
raise RuntimeError(
"status command %s fails to execute. erro info: %s return code %d"
% (command, err_str, ret)
f"status command {command} fails to execute. erro info: {err_str} return code {ret}"
)
status_line = stdout.read().decode("utf-8").split("\n")[-2]
status_word = status_line.split()[-2]
Expand Down
6 changes: 2 additions & 4 deletions dpdispatcher/machines/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def do_submit(self, job):
if ret != 0:
err_str = stderr.read().decode("utf-8")
raise RuntimeError(
"status command %s fails to execute\nerror message:%s\nreturn code %d\n"
% (cmd, err_str, ret)
f"status command {cmd} fails to execute\nerror message:{err_str}\nreturn code {ret}\n"
)
job_id = int(stdout.read().decode("utf-8").strip())
self.context.write_file(job_id_name, str(job_id))
Expand Down Expand Up @@ -80,8 +79,7 @@ def check_status(self, job):
if ret != 0:
err_str = stderr.read().decode("utf-8")
raise RuntimeError(
"status command %s fails to execute\nerror message:%s\nreturn code %d\n"
% (cmd, err_str, ret)
f"status command {cmd} fails to execute\nerror message:{err_str}\nreturn code {ret}\n"
)

if_job_exists = bool(stdout.read().decode("utf-8").strip())
Expand Down
24 changes: 9 additions & 15 deletions dpdispatcher/machines/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def do_submit(self, job):
):
# server network error, retry 3 times
raise RetrySignal(
"Get error code %d in submitting with job: %s . message: %s"
% (ret, job.job_hash, err_str)
f"Get error code {ret} in submitting with job: {job.job_hash} . message: {err_str}"
)
elif (
"Job violates accounting/QOS policy" in err_str
Expand All @@ -109,8 +108,7 @@ def do_submit(self, job):
# job number exceeds, skip the submitting
return ""
raise RuntimeError(
"command %s fails to execute\nerror message:%s\nreturn code %d\n"
% (command, err_str, ret)
f"command {command} fails to execute\nerror message:{err_str}\nreturn code {ret}\n"
)
subret = stdout.readlines()
# --parsable
Expand Down Expand Up @@ -145,13 +143,11 @@ def check_status(self, job):
):
# retry 3 times
raise RetrySignal(
"Get error code %d in checking status with job: %s . message: %s"
% (ret, job.job_hash, err_str)
f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}"
)
raise RuntimeError(
"status command %s fails to execute."
"job_id:%s \n error message:%s\n return code %d\n"
% (command, job_id, err_str, ret)
f"status command {command} fails to execute."
f"job_id:{job_id} \n error message:{err_str}\n return code {ret}\n"
)
status_line = stdout.read().decode("utf-8").split("\n")[-2]
status_word = status_line.split()[-1]
Expand Down Expand Up @@ -255,7 +251,7 @@ def gen_script_header(self, job):
return super().gen_script_header(job) + "\n#SBATCH --array={}".format(
",".join(map(str, job_array))
)
return super().gen_script_header(job) + "\n#SBATCH --array=0-%d" % (
return super().gen_script_header(job) + "\n#SBATCH --array=0-%s" % (
math.ceil(len(job.job_task_list) / slurm_job_size) - 1
)

Expand Down Expand Up @@ -333,13 +329,11 @@ def check_status(self, job):
):
# retry 3 times
raise RetrySignal(
"Get error code %d in checking status with job: %s . message: %s"
% (ret, job.job_hash, err_str)
f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}"
)
raise RuntimeError(
"status command %s fails to execute."
"job_id:%s \n error message:%s\n return code %d\n"
% (command, job_id, err_str, ret)
f"status command {command} fails to execute."
f"job_id:{job_id} \n error message:{err_str}\n return code {ret}\n"
)
status_lines = stdout.read().decode("utf-8").split("\n")[:-1]
status = []
Expand Down
2 changes: 1 addition & 1 deletion dpdispatcher/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def wrapper(*args, **kwargs):
else:
# raise all exceptions
raise RuntimeError(
"Failed to run %s for %d times" % (func.__name__, current_retry)
f"Failed to run {func.__name__} for {current_retry} times"
) from errors[-1]

return wrapper
Expand Down

0 comments on commit 361d1fd

Please sign in to comment.