Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UP031 errors - Part 5 #19282

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/galaxy/datatypes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def as_ucsc_display_file(self, dataset: DatasetProtocol, **kwd) -> Union[FileObj
if t >= 0: # strand column (should) exists
for i, elems in enumerate(compression_utils.file_iter(dataset.get_file_name())):
strand = "+"
name = "region_%i" % i
name = f"region_{i}"
if n >= 0 and n < len(elems):
name = cast(str, elems[n])
if t < len(elems):
Expand All @@ -293,7 +293,7 @@ def as_ucsc_display_file(self, dataset: DatasetProtocol, **kwd) -> Union[FileObj
fh.write("{}\n".format("\t".join(tmp)))
elif n >= 0: # name column (should) exists
for i, elems in enumerate(compression_utils.file_iter(dataset.get_file_name())):
name = "region_%i" % i
name = f"region_{i}"
if n >= 0 and n < len(elems):
name = cast(str, elems[n])
tmp = [elems[c], elems[s], elems[e], name]
Expand Down Expand Up @@ -346,8 +346,7 @@ def ucsc_links(self, dataset: DatasetProtocol, type: str, app, base_url: str) ->
filename="ucsc_" + site_name,
)
display_url = quote_plus(
"%s%s/display_as?id=%i&display_app=%s&authz_method=display_at"
% (
"{}{}/display_as?id={}&display_app={}&authz_method=display_at".format(
base_url,
app.url_for(controller="root"),
dataset.id,
Expand Down Expand Up @@ -784,8 +783,7 @@ def _get_remote_call_url(
internal_url = f"{app.url_for(controller='dataset', dataset_id=dataset.id, action='display_at', filename=f'{type}_{site_name}')}"
base_url = app.config.get("display_at_callback", base_url)
display_url = quote_plus(
"%s%s/display_as?id=%i&display_app=%s&authz_method=display_at"
% (
"{}{}/display_as?id={}&display_app={}&authz_method=display_at".format(
base_url,
app.url_for(controller="root"),
dataset.id,
Expand Down Expand Up @@ -1567,8 +1565,7 @@ def ucsc_links(self, dataset: DatasetProtocol, type: str, app, base_url: str) ->
if site_name in app.datatypes_registry.get_display_sites("ucsc"):
internal_url = f"{app.url_for(controller='dataset', dataset_id=dataset.id, action='display_at', filename='ucsc_' + site_name)}"
display_url = quote_plus(
"%s%s/display_as?id=%i&display_app=%s&authz_method=display_at"
% (
"{}{}/display_as?id={}&display_app={}&authz_method=display_at".format(
base_url,
app.url_for(controller="root"),
dataset.id,
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/mothur.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ def make_html_table(self, dataset: DatasetProtocol, skipchars: Optional[List] =
out += "<th>2. Flows</th>"
for i in range(3, dataset.metadata.columns + 1):
base = dataset.metadata.flow_order[(i + 1) % 4]
out += "<th>%d. %s</th>" % (i - 2, base)
out += f"<th>{i - 2}. {base}</th>"
out += "</tr>"
out += self.make_html_peek_rows(dataset, skipchars=skipchars)
out += "</table>"
Expand Down
10 changes: 5 additions & 5 deletions lib/galaxy/datatypes/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def set_peek(self, dataset: DatasetProtocol, **kwd) -> None:
parsed_data = json.load(open(dataset.get_file_name()))
# dataset.peek = json.dumps(data, sort_keys=True, indent=4)
dataset.peek = data.get_file_peek(dataset.get_file_name())
dataset.blurb = "%d sections" % len(parsed_data["sections"])
dataset.blurb = "{} sections".format(len(parsed_data["sections"]))
except Exception:
dataset.peek = "Not FQTOC file"
dataset.blurb = "Not FQTOC file"
Expand Down Expand Up @@ -465,7 +465,7 @@ def split(cls, input_datasets: List, subdir_generator_function: Callable, split_
raise Exception("Tool does not define a split mode")
elif split_params["split_mode"] == "number_of_parts":
split_size = int(split_params["split_size"])
log.debug("Split %s into %i parts..." % (input_file, split_size))
log.debug("Split %s into %i parts...", input_file, split_size)
# if split_mode = number_of_parts, and split_size = 10, and
# we know the number of sequences (say 1234), then divide by
# by ten, giving ten files of approx 123 sequences each.
Expand All @@ -484,7 +484,7 @@ def split(cls, input_datasets: List, subdir_generator_function: Callable, split_
# Split the input file into as many sub-files as required,
# each containing to_size many sequences
batch_size = int(split_params["split_size"])
log.debug("Split %s into batches of %i records..." % (input_file, batch_size))
log.debug("Split %s into batches of %i records...", input_file, batch_size)
cls._count_split(input_file, batch_size, subdir_generator_function)
else:
raise Exception(f"Unsupported split mode {split_params['split_mode']}")
Expand All @@ -496,7 +496,7 @@ def _size_split(cls, input_file: str, chunk_size: int, subdir_generator_function
This does of course preserve complete records - it only splits at the
start of a new FASTQ sequence record.
"""
log.debug("Attemping to split FASTA file %s into chunks of %i bytes" % (input_file, chunk_size))
log.debug("Attemping to split FASTA file %s into chunks of %i bytes", input_file, chunk_size)
with open(input_file) as f:
part_file = None
try:
Expand Down Expand Up @@ -530,7 +530,7 @@ def _size_split(cls, input_file: str, chunk_size: int, subdir_generator_function
@classmethod
def _count_split(cls, input_file: str, chunk_size: int, subdir_generator_function: Callable) -> None:
"""Split a FASTA file into chunks based on counting records."""
log.debug("Attemping to split FASTA file %s into chunks of %i sequences" % (input_file, chunk_size))
log.debug("Attemping to split FASTA file %s into chunks of %i sequences", input_file, chunk_size)
with open(input_file) as f:
part_file = None
try:
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/datatypes/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ def set_meta(
if line:
line_pieces = line.split("\t")
if len(line_pieces) != 22:
raise Exception("%s:%d:Corrupt line!" % (dataset.get_file_name(), i))
raise Exception(f"{dataset.get_file_name()}:{i}:Corrupt line!")
lanes[line_pieces[2]] = 1
tiles[line_pieces[3]] = 1
barcodes[line_pieces[6]] = 1
Expand Down Expand Up @@ -1353,7 +1353,7 @@ def set_meta(
"str",
]
dataset.metadata.lanes = list(lanes.keys())
dataset.metadata.tiles = ["%04d" % int(t) for t in tiles.keys()]
dataset.metadata.tiles = [f"{int(t):04d}" for t in tiles.keys()]
dataset.metadata.barcodes = [_ for _ in barcodes.keys() if _ != "0"] + [
"NoIndex" for _ in barcodes.keys() if _ == "0"
]
Expand Down Expand Up @@ -1477,7 +1477,7 @@ def set_meta(self, dataset: DatasetProtocol, overwrite: bool = True, **kwd) -> N
except StopIteration:
pass
except csv.Error as e:
raise Exception("CSV reader error - line %d: %s" % (reader.line_num, e))
raise Exception(f"CSV reader error - line {reader.line_num}: {e}")
else:
data_lines = reader.line_num - 1

Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def set_meta(self, dataset: DatasetProtocol, overwrite: bool = True, **kwd) -> N
tax_names = []
for entry in json_dict:
if "taxonId" in entry:
names = "%d: %s" % (entry["taxonId"], ",".join(entry["speciesNames"]))
names = "{}: {}".format(entry["taxonId"], ",".join(entry["speciesNames"]))
tax_names.append(names)
dataset.metadata.taxon_names = tax_names
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/datatypes/util/gff_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def __init__(
# Handle feature, score column.
self.feature_col = feature_col
if self.nfields <= self.feature_col:
raise MissingFieldError("No field for feature_col (%d)" % feature_col)
raise MissingFieldError(f"No field for feature_col ({feature_col})")
self.feature = self.fields[self.feature_col]
self.score_col = score_col
if self.nfields <= self.score_col:
raise MissingFieldError("No field for score_col (%d)" % score_col)
raise MissingFieldError(f"No field for score_col ({score_col})")
self.score = self.fields[self.score_col]

# GFF attributes.
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/exceptions/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __str__(self):

def __repr__(self):
"""Return object representation of this error code."""
return "ErrorCode[code=%d,message=%s]" % (self.code, str(self.default_error_message))
return f"ErrorCode[code={self.code},message={str(self.default_error_message)}]"

def __int__(self):
"""Return the error code integer."""
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/job_metrics/instrumenters/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def format(self, key: str, value: Any) -> FormattedMetric:
return FormattedMetric("Container Type", value)
value = int(value)
if key == GALAXY_SLOTS_KEY:
return FormattedMetric("Cores Allocated", "%d" % value)
return FormattedMetric("Cores Allocated", f"{value}")
elif key == GALAXY_MEMORY_MB_KEY:
return FormattedMetric("Memory Allocated (MB)", "%d" % value)
return FormattedMetric("Memory Allocated (MB)", f"{value}")
elif key == RUNTIME_SECONDS_KEY:
return FormattedMetric("Job Runtime (Wall Clock)", seconds_to_str(value))
else:
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2768,8 +2768,10 @@ def finish(self, stdout, stderr, tool_exit_code=None, **kwds):

# This may have ended too soon
log.debug(
"task %s for job %d ended; exit code: %d"
% (self.task_id, self.job_id, tool_exit_code if tool_exit_code is not None else -256)
"task %s for job %d ended; exit code: %d",
self.task_id,
self.job_id,
tool_exit_code if tool_exit_code is not None else -256,
)
# default post job setup_external_metadata
task = self.get_task()
Expand Down
18 changes: 9 additions & 9 deletions lib/galaxy/jobs/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,22 +552,22 @@ def __handle_waiting_jobs(self):
if job_state == JOB_WAIT:
new_waiting_jobs.append(job.id)
elif job_state == JOB_INPUT_ERROR:
log.info("(%d) Job unable to run: one or more inputs in error state" % job.id)
log.info("(%d) Job unable to run: one or more inputs in error state", job.id)
elif job_state == JOB_INPUT_DELETED:
log.info("(%d) Job unable to run: one or more inputs deleted" % job.id)
log.info("(%d) Job unable to run: one or more inputs deleted", job.id)
elif job_state == JOB_READY:
self.dispatcher.put(self.job_wrappers.pop(job.id))
log.info("(%d) Job dispatched" % job.id)
log.info("(%d) Job dispatched", job.id)
elif job_state == JOB_DELETED:
log.info("(%d) Job deleted by user while still queued" % job.id)
log.info("(%d) Job deleted by user while still queued", job.id)
elif job_state == JOB_ADMIN_DELETED:
log.info("(%d) Job deleted by admin while still queued" % job.id)
log.info("(%d) Job deleted by admin while still queued", job.id)
elif job_state in (JOB_USER_OVER_QUOTA, JOB_USER_OVER_TOTAL_WALLTIME):
if job_state == JOB_USER_OVER_QUOTA:
log.info("(%d) User (%s) is over quota: job paused" % (job.id, job.user_id))
log.info("(%d) User (%s) is over quota: job paused", job.id, job.user_id)
what = "your disk quota"
else:
log.info("(%d) User (%s) is over total walltime limit: job paused" % (job.id, job.user_id))
log.info("(%d) User (%s) is over total walltime limit: job paused", job.id, job.user_id)
what = "your total job runtime"

job.set_state(model.Job.states.PAUSED)
Expand All @@ -580,7 +580,7 @@ def __handle_waiting_jobs(self):
# A more informative message is shown wherever the job state is set to error
pass
else:
log.error("(%d) Job in unknown state '%s'" % (job.id, job_state))
log.error("(%d) Job in unknown state '%s'", job.id, job_state)
new_waiting_jobs.append(job.id)
except Exception:
log.exception("failure running job %d", job.id)
Expand Down Expand Up @@ -1277,7 +1277,7 @@ def stop(self, job, job_wrapper):

def recover(self, job, job_wrapper):
runner_name = (job.job_runner_name.split(":", 1))[0]
log.debug("recovering job %d in %s runner" % (job.id, runner_name))
log.debug("recovering job %d in %s runner", job.id, runner_name)
runner = self.get_job_runner(job_wrapper)
try:
runner.recover(job, job_wrapper)
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/jobs/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _init_worker_threads(self):
self.work_threads = []
log.debug(f"Starting {self.nworkers} {self.runner_name} workers")
for i in range(self.nworkers):
worker = threading.Thread(name="%s.work_thread-%d" % (self.runner_name, i), target=self.run_next)
worker = threading.Thread(name=f"{self.runner_name}.work_thread-{i}", target=self.run_next)
worker.daemon = True
worker.start()
self.work_threads.append(worker)
Expand Down Expand Up @@ -493,7 +493,7 @@ def _handle_metadata_externally(self, job_wrapper: "MinimalJobWrapper", resolve_
env=os.environ,
preexec_fn=os.setpgrp,
)
log.debug("execution of external set_meta for job %d finished" % job_wrapper.job_id)
log.debug("execution of external set_meta for job %d finished", job_wrapper.job_id)

def get_job_file(self, job_wrapper: "MinimalJobWrapper", **kwds) -> str:
job_metrics = job_wrapper.app.job_metrics
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/jobs/runners/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def _register_job_definition(self, jd_name, container_image, destination_params)
"environment": _add_galaxy_environment_variables(
destination_params.get("vcpu"), destination_params.get("memory"),
),
"user": "%d:%d" % (os.getuid(), os.getgid()),
"user": f"{os.getuid()}:{os.getgid()}",
"privileged": destination_params.get("privileged"),
"logConfiguration": {"logDriver": "awslogs"},
}
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/jobs/runners/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def stop_job(self, job_wrapper):
return
pid = int(pid)
if not check_pg(pid):
log.warning("stop_job(): %s: Process group %d was already dead or can't be signaled" % (job.id, pid))
log.warning("stop_job(): %s: Process group %d was already dead or can't be signaled", job.id, pid)
return
log.debug("stop_job(): %s: Terminating process group %d", job.id, pid)
kill_pg(pid)
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/jobs/runners/pbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def queue_job(self, job_wrapper):
pbs.pbs_disconnect(c)
break
errno, text = pbs.error()
log.warning("(%s) pbs_submit failed (try %d/5), PBS error %d: %s" % (galaxy_job_id, tries, errno, text))
log.warning("(%s) pbs_submit failed (try %d/5), PBS error %d: %s", galaxy_job_id, tries, errno, text)
time.sleep(2)
else:
log.error(f"({galaxy_job_id}) All attempts to submit job failed")
Expand Down Expand Up @@ -386,7 +386,7 @@ def check_watched_items(self):
else:
# Unhandled error, continue to monitor
log.info(
"(%s/%s) PBS state check resulted in error (%d): %s" % (galaxy_job_id, job_id, errno, text)
"(%s/%s) PBS state check resulted in error (%d): %s", galaxy_job_id, job_id, errno, text
)
new_watched.append(pbs_job_state)
continue
Expand Down
22 changes: 14 additions & 8 deletions lib/galaxy/jobs/runners/pulsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,13 @@ def check_pid(self, pid):
return True
except OSError as e:
if e.errno == errno.ESRCH:
log.debug("check_pid(): PID %d is dead" % pid)
log.debug("check_pid(): PID %d is dead", pid)
else:
log.warning(
"check_pid(): Got errno %s when attempting to check PID %d: %s"
% (errno.errorcode[e.errno], pid, e.strerror)
"check_pid(): Got errno %s when attempting to check PID %d: %s",
errno.errorcode[e.errno],
pid,
e.strerror,
)
return False

Expand All @@ -747,23 +749,27 @@ def stop_job(self, job_wrapper):
return
pid = int(pid)
if not self.check_pid(pid):
log.warning("stop_job(): %s: PID %d was already dead or can't be signaled" % (job.id, pid))
log.warning("stop_job(): %s: PID %d was already dead or can't be signaled", job.id, pid)
return
for sig in [15, 9]:
try:
os.killpg(pid, sig)
except OSError as e:
log.warning(
"stop_job(): %s: Got errno %s when attempting to signal %d to PID %d: %s"
% (job.id, errno.errorcode[e.errno], sig, pid, e.strerror)
"stop_job(): %s: Got errno %s when attempting to signal %d to PID %d: %s",
job.id,
errno.errorcode[e.errno],
sig,
pid,
e.strerror,
)
return # give up
sleep(2)
if not self.check_pid(pid):
log.debug("stop_job(): %s: PID %d successfully killed with signal %d" % (job.id, pid, sig))
log.debug("stop_job(): %s: PID %d successfully killed with signal %d", job.id, pid, sig)
return
else:
log.warning("stop_job(): %s: PID %d refuses to die after signaling TERM/KILL" % (job.id, pid))
log.warning("stop_job(): %s: PID %d refuses to die after signaling TERM/KILL", job.id, pid)
else:
# Remote kill
pulsar_url = job.job_runner_name
Expand Down
Loading
Loading