Fix new UP031 errors from ruff 0.4.2

This commit is contained in:
Nicola Soranzo
2024-04-29 00:09:38 +01:00
parent 0e89124a13
commit 0629908541
127 changed files with 381 additions and 425 deletions
@@ -59,7 +59,7 @@ class TourGenerator:
filename = test_datasets[input_name]
input_path = self._tool.test_data_path(filename)
if not input_path:
raise ValueError('Test dataset "%s" doesn\'t exist.' % input_name)
raise ValueError(f'Test dataset "{input_name}" doesn\'t exist.')
upload_tool = self._trans.app.toolbox.get_tool("upload1")
filename = os.path.basename(input_path)
with open(input_path, "rb") as f:
@@ -92,12 +92,12 @@ class TourGenerator:
def _generate_tour(self):
"""Generate a tour."""
tour_name = self._tool.name + " Tour"
tour_name = f"{self._tool.name} Tour"
test_inputs = self._test.inputs.keys()
steps = [
{
"title": tour_name,
"content": "This short tour will guide you through the <b>" + self._tool.name + "</b> tool.",
"content": f"This short tour will guide you through the <b>{self._tool.name}</b> tool.",
"orphan": True,
}
]
@@ -107,26 +107,26 @@ class TourGenerator:
continue
step = {
"title": input.label,
"element": "[id='form-element-%s']" % name,
"element": f"[id='form-element-{name}']",
"placement": "right",
"content": "",
}
if input.type == "text":
if name in test_inputs:
param = self._test.inputs[name]
step["content"] = "Enter value(s): <b>%s</b>" % param
step["content"] = f"Enter value(s): <b>{param}</b>"
else:
step["content"] = "Enter a value"
elif input.type == "integer" or input.type == "float":
if name in test_inputs:
num_param = self._test.inputs[name][0]
step["content"] = "Enter number: <b>%s</b>" % num_param
step["content"] = f"Enter number: <b>{num_param}</b>"
else:
step["content"] = "Enter a number"
elif input.type == "boolean":
if name in test_inputs:
choice = "Yes" if self._test.inputs[name][0] is True else "No"
step["content"] = "Choose <b>%s</b>" % choice
step["content"] = f"Choose <b>{choice}</b>"
else:
step["content"] = "Choose Yes/No"
elif input.type == "select":
@@ -138,7 +138,7 @@ class TourGenerator:
params.append(option[0])
if params:
select_param = ", ".join(params)
step["content"] = "Select parameter(s): <b>%s</b>" % select_param
step["content"] = f"Select parameter(s): <b>{select_param}</b>"
else:
step["content"] = "Select a parameter"
elif input.type == "data":
@@ -151,7 +151,7 @@ class TourGenerator:
elif input.type == "conditional":
param_id = f"{input.name}|{input.test_param.name}"
step["title"] = input.test_param.label
step["element"] = "[id='form-element-%s']" % param_id
step["element"] = f"[id='form-element-{param_id}']"
params = []
if param_id in self._test.inputs.keys():
for option in input.test_param.static_options:
@@ -173,24 +173,24 @@ class TourGenerator:
step_msg = f"Select dataset: <b>{hid}: {dataset}</b>"
else:
case_params = ", ".join(self._test.inputs[tour_id])
step_msg = "Select parameter(s): " + "<b>%s</b>" % case_params
step_msg = f"Select parameter(s): <b>{case_params}</b>"
cond_case_steps.append(
{
"title": case_title,
"element": "[id='form-element-%s']" % tour_id,
"element": f"[id='form-element-{tour_id}']",
"placement": "right",
"content": step_msg,
}
)
if params:
cond_param = ", ".join(params)
step["content"] = "Select parameter(s): <b>%s</b>" % cond_param
step["content"] = f"Select parameter(s): <b>{cond_param}</b>"
else:
step["content"] = "Select a parameter"
elif input.type == "data_column":
if name in test_inputs:
column_param = self._test.inputs[name][0]
step["content"] = "Select <b>Column: %s</b>" % column_param
step["content"] = f"Select <b>Column: {column_param}</b>"
else:
step["content"] = "Select a column"
else:
@@ -210,7 +210,7 @@ class TourGenerator:
self._tour = {
"title_default": tour_name,
"name": tour_name,
"description": self._tool.name + " " + self._tool.description,
"description": f"{self._tool.name} {self._tool.description}",
"steps": steps,
}
+14 -18
View File
@@ -34,7 +34,7 @@ def main():
class Tag:
def __init__(self, line):
def __init__(self, line: str):
assert line.startswith("$tag:")
line_parts = line.split(" ")
first_part = line_parts[0]
@@ -52,12 +52,12 @@ class Tag:
@property
def _pretty_title(self):
return " > ".join("``%s``" % p for p in self.title.split("|"))
return " > ".join(f"``{p}``" for p in self.title.split("|"))
def build_help(self):
tag = xmlschema_doc.find(self.xpath)
if tag is None:
raise Exception("Could not find xpath for %s" % self.xpath)
raise Exception(f"Could not find xpath for {self.xpath}")
tag_help = StringIO()
tag_help.write("## " + self._pretty_title)
@@ -98,7 +98,7 @@ def _build_tag(tag, hide_attributes):
doc = _doc_or_none(element)
if doc is None:
doc = _doc_or_none(_type_el(element))
assert doc is not None, "Documentation for %s is empty" % element.attrib["name"]
assert doc is not None, f"Documentation for {element.attrib['name']} is empty"
doc = doc.strip()
element_el = _find_tag_el(element)
@@ -110,10 +110,9 @@ def _build_tag(tag, hide_attributes):
if best_practices := _get_bp_link(annotation_el):
tag_help.write("\n\n### Best Practices\n")
tag_help.write(
"""
Find the Intergalactic Utilities Commision suggested best practices for this
element [here](%s)."""
% best_practices
f"""
Find the Intergalactic Utilities Commission suggested best practices for this
element [here]({best_practices})."""
)
tag_help.write(_build_attributes_table(tag, attributes, hide_attributes))
@@ -140,7 +139,7 @@ def _get_bp_link(annotation_el):
anchor = annotation_el.attrib.get("{http://galaxyproject.org/xml/1.0}best_practices", None)
link = None
if anchor:
link = "https://galaxy-iuc-standards.readthedocs.io/en/latest/best_practices/tool_xml.html#%s" % anchor
link = f"https://galaxy-iuc-standards.readthedocs.io/en/latest/best_practices/tool_xml.html#{anchor}"
return link
@@ -149,7 +148,7 @@ def _build_attributes_table(tag, attributes, hide_attributes=False, attribute_na
attribute_table.write("\n\n")
if attributes and not hide_attributes:
header_prefix = "#" * header_level
attribute_table.write("\n%s Attributes\n\n" % header_prefix)
attribute_table.write(f"\n{header_prefix} Attributes\n\n")
attribute_table.write("Attribute | Details | Required\n")
attribute_table.write("--- | --- | ---\n")
for attribute in attributes:
@@ -159,7 +158,7 @@ def _build_attributes_table(tag, attributes, hide_attributes=False, attribute_na
details = _doc_or_none(attribute)
if details is None:
type_el = _type_el(attribute)
assert type_el is not None, "No details or type found for %s" % name
assert type_el is not None, f"No details or type found for {name}"
details = _doc_or_none(type_el)
annotation_el = type_el.find("{http://www.w3.org/2001/XMLSchema}annotation")
else:
@@ -170,10 +169,7 @@ def _build_attributes_table(tag, attributes, hide_attributes=False, attribute_na
details = details.replace("|", "\\|").strip()
best_practices = _get_bp_link(annotation_el)
if best_practices:
details += (
""" Find the Intergalactic Utilities Commision suggested best practices for this element [here](%s)."""
% best_practices
)
details += f""" Find the Intergalactic Utilities Commission suggested best practices for this element [here]({best_practices})."""
attribute_table.write(f"``{name}`` | {details} | {use}\n")
return attribute_table.getvalue()
@@ -204,7 +200,7 @@ def _find_attributes(tag):
for attribute_group in attribute_groups:
attribute_group_name = attribute_group.get("ref")
attribute_group_def = xmlschema_doc.find(
"//{http://www.w3.org/2001/XMLSchema}attributeGroup/[@name='%s']" % attribute_group_name
f"//{{http://www.w3.org/2001/XMLSchema}}attributeGroup/[@name='{attribute_group_name}']"
)
attributes.extend(_find_attributes(attribute_group_def))
return attributes
@@ -219,9 +215,9 @@ def _find_tag_el(tag):
def _type_el(tag):
element_type = tag.attrib["type"]
type_el = xmlschema_doc.find("//{http://www.w3.org/2001/XMLSchema}complexType/[@name='%s']" % element_type)
type_el = xmlschema_doc.find(f"//{{http://www.w3.org/2001/XMLSchema}}complexType/[@name='{element_type}']")
if type_el is None:
type_el = xmlschema_doc.find("//{http://www.w3.org/2001/XMLSchema}simpleType/[@name='%s']" % element_type)
type_el = xmlschema_doc.find(f"//{{http://www.w3.org/2001/XMLSchema}}simpleType/[@name='{element_type}']")
return type_el
+1 -1
View File
@@ -265,7 +265,7 @@ class LibraryActions:
if not os.path.exists(path):
bad_paths.append(path)
if bad_paths:
message = 'Invalid paths: "%s".' % '", "'.join(bad_paths)
message = 'Invalid paths: "{}".'.format('", "'.join(bad_paths))
response_code = 400
return None, response_code, message
return None
+2 -2
View File
@@ -135,8 +135,8 @@ class LDAP(AuthProvider):
self.role_search_attribute = options.get(self.role_search_option)
if self.auto_create_roles_or_groups and self.role_search_attribute is None:
raise ConfigurationError(
"If 'auto-create-roles' or 'auto-create-groups' is True, a '%s' attribute has to"
" be provided." % self.role_search_option
f"If 'auto-create-roles' or 'auto-create-groups' is True, a '{self.role_search_option}' attribute has to"
" be provided."
)
return ok, failure_mode
+3 -2
View File
@@ -944,7 +944,8 @@ class GalaxyAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin):
log.warning(
"The path '%s' for the 'sanitize_allowlist_file' config option is "
"deprecated and will be no longer checked in a future release. Please consult "
"the latest version of the sample configuration file." % deprecated
"the latest version of the sample configuration file.",
deprecated,
)
_sanitize_allowlist_path = deprecated
break
@@ -965,7 +966,7 @@ class GalaxyAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin):
)
# Searching data libraries
self.ftp_upload_dir_template = kwargs.get(
"ftp_upload_dir_template", "${ftp_upload_dir}%s${ftp_upload_dir_identifier}" % os.path.sep
"ftp_upload_dir_template", f"${{ftp_upload_dir}}{os.path.sep}${{ftp_upload_dir_identifier}}"
)
# Support older library-specific path paste option but just default to the new
# allow_path_paste value.
+7 -7
View File
@@ -2089,7 +2089,7 @@ class H5MLM(H5):
try:
return dataset.peek
except Exception:
return "HDF5 Model (%s)" % (nice_size(dataset.get_size()))
return f"HDF5 Model ({nice_size(dataset.get_size())})"
def display_data(
self,
@@ -4258,7 +4258,7 @@ class Pretext(Binary):
try:
return dataset.peek
except Exception:
return "Binary pretext file (%s)" % (nice_size(dataset.get_size()))
return f"Binary pretext file ({nice_size(dataset.get_size())})"
class JP2(Binary):
@@ -4302,7 +4302,7 @@ class JP2(Binary):
try:
return dataset.peek
except Exception:
return "Binary JPEG 2000 file (%s)" % (nice_size(dataset.get_size()))
return f"Binary JPEG 2000 file ({nice_size(dataset.get_size())})"
class Npz(CompressedArchive):
@@ -4356,7 +4356,7 @@ class Npz(CompressedArchive):
try:
return dataset.peek
except Exception:
return "Binary Numpy npz file (%s)" % (nice_size(dataset.get_size()))
return f"Binary Numpy npz file ({nice_size(dataset.get_size())})"
class HexrdImagesNpz(Npz):
@@ -4433,7 +4433,7 @@ class HexrdImagesNpz(Npz):
try:
return dataset.peek
except Exception:
return "Binary Numpy npz file (%s)" % (nice_size(dataset.get_size()))
return f"Binary Numpy npz file ({nice_size(dataset.get_size())})"
class HexrdEtaOmeNpz(Npz):
@@ -4495,7 +4495,7 @@ class HexrdEtaOmeNpz(Npz):
try:
return dataset.peek
except Exception:
return "Binary Numpy npz file (%s)" % (nice_size(dataset.get_size()))
return f"Binary Numpy npz file ({nice_size(dataset.get_size())})"
class FITS(Binary):
@@ -4624,4 +4624,4 @@ class Numpy(Binary):
try:
return dataset.peek
except Exception:
return "Binary numpy file (%s)" % (nice_size(dataset.get_size()))
return f"Binary numpy file ({nice_size(dataset.get_size())})"
@@ -181,7 +181,7 @@ def __main__():
fields = [str(item) for item in (region.chrom, region.start, region.end, name, 0, region.strand)]
if force_num_columns is not None and len(fields) != force_num_columns:
fields = force_bed_field_count(fields, count, force_num_columns)
out.write("%s\n" % "\t".join(fields))
out.write("{}\n".format("\t".join(fields)))
except Exception:
skipped_lines += 1
if first_skipped_line is None:
@@ -24,11 +24,12 @@ def __main__():
else:
spec_counts[spec] += 1
out.write(
"%s\n"
% maf_utilities.get_fasta_header(
c,
{"block_index": count, "species": spec, "sequence_index": spec_counts[spec]},
suffix="%s_%i_%i" % (spec, count, spec_counts[spec]),
"{}\n".format(
maf_utilities.get_fasta_header(
c,
{"block_index": count, "species": spec, "sequence_index": spec_counts[spec]},
suffix="%s_%i_%i" % (spec, count, spec_counts[spec]),
)
)
)
out.write(f"{c.text}\n")
@@ -20,7 +20,7 @@ def main():
with open(sys.argv[1]) as in_file, open(sys.argv[2], "w") as out_file:
try:
for fields in bx.wiggle.IntervalReader(UCSCOutWrapper(in_file)):
out_file.write("%s\n" % "\t".join(map(str, fields)))
out_file.write("{}\n".format("\t".join(map(str, fields))))
except UCSCLimitException:
# Wiggle data was truncated, at the very least need to warn the user.
sys.stderr.write(
+3 -3
View File
@@ -289,18 +289,18 @@ class Interval(Tabular):
if t < len(elems):
strand = cast(str, elems[t])
tmp = [elems[c], elems[s], elems[e], name, "0", strand]
fh.write("%s\n" % "\t".join(tmp))
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
if n >= 0 and n < len(elems):
name = cast(str, elems[n])
tmp = [elems[c], elems[s], elems[e], name]
fh.write("%s\n" % "\t".join(tmp))
fh.write("{}\n".format("\t".join(tmp)))
else:
for elems in compression_utils.file_iter(dataset.get_file_name()):
tmp = [elems[c], elems[s], elems[e]]
fh.write("%s\n" % "\t".join(tmp))
fh.write("{}\n".format("\t".join(tmp)))
return compression_utils.get_fileobj(fh.name, mode="rb")
def display_peek(self, dataset: DatasetProtocol) -> str:
+1 -2
View File
@@ -30,9 +30,8 @@ class Neo4j(Html):
"""
# self.regenerate_primary_file(dataset)
rval = [
"<html><head><title>Files for Composite Dataset (%s)</title></head><p/>\
f"<html><head><title>Files for Composite Dataset ({self.file_ext})</title></head><p/>\
This composite dataset is composed of the following files:<p/><ul>"
% (self.file_ext)
]
for composite_name, composite_file in self.get_composite_files(dataset=dataset).items():
opt_text = ""
+1 -1
View File
@@ -714,7 +714,7 @@ class ProteomicsXml(GenericXml):
if not line.startswith("<?"):
break
# pattern match <root or <ns:root for any ns string
pattern = r"<(\w*:)?%s" % self.root
pattern = rf"<(\w*:)?{self.root}"
return re.search(pattern, line) is not None
def set_peek(self, dataset: DatasetProtocol, **kwd) -> None:
+2 -2
View File
@@ -258,10 +258,10 @@ def _get_uuid(path):
if len(roots) == 0:
raise ValueError("Archive does not have a visible root directory.")
if len(roots) > 1:
raise ValueError("Archive has multiple root directories: %r" % roots)
raise ValueError(f"Archive has multiple root directories: {roots!r}")
uuid = roots.pop()
if not _is_uuid4(uuid):
raise ValueError("Archive root directory name %r is not a valid version 4 " "UUID." % uuid)
raise ValueError(f"Archive root directory name {uuid!r} is not a valid version 4 UUID.")
return uuid
+2 -3
View File
@@ -971,9 +971,8 @@ class Registry:
# If extension is not None and is uppercase or mixed case, we need to lowercase it
if extension is not None and not extension.islower():
self.log.debug(
"%s is not lower case, that could cause troubles in the future. \
Please change it to lower case"
% extension
"%s is not lower case, that could cause troubles in the future. Please change it to lower case",
extension,
)
extension = extension.lower()
return extension
+1 -1
View File
@@ -1075,7 +1075,7 @@ class BaseVcf(Tabular):
def validate(self, dataset: DatasetProtocol, **kwd) -> DatatypeValidation:
def validate_row(row):
if len(row) < 8:
raise Exception("Not enough columns in row %s" % row.join("\t"))
raise Exception("Not enough columns in row {}".format(row.join("\t")))
validate_tabular(dataset.get_file_name(), sep="\t", validate_row=validate_row, comment_designator="#")
return DatatypeValidation.validated()
+1 -2
View File
@@ -36,9 +36,8 @@ class UCSCTrackHub(Html):
cannot rename the datasets here - they come with the default unfortunately
"""
rval = [
"<html><head><title>Files for Composite Dataset (%s)</title></head><p/>\
f"<html><head><title>Files for Composite Dataset ({self.file_ext})</title></head><p/>\
This composite dataset is composed of the following files:<p/><ul>"
% (self.file_ext)
]
for composite_name, composite_file in self.get_composite_files(dataset=dataset).items():
opt_text = ""
+1 -1
View File
@@ -49,7 +49,7 @@ class GenericXml(data.Text):
if not line.startswith("<?"):
break
# pattern match <root or <ns:root for any ns string
pattern = r"^<(\w*:)?%s" % root
pattern = rf"^<(\w*:)?{root}"
return re.match(pattern, line) is not None
def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
+2 -2
View File
@@ -231,11 +231,11 @@ class RenameDatasetAction(DefaultJobAction):
elif operation == "lower":
replacement = replacement.lower()
new_name = new_name.replace("#{%s}" % to_be_replaced, replacement)
new_name = new_name.replace(f"#{{{to_be_replaced}}}", replacement)
if replacement_dict:
for k, v in replacement_dict.items():
new_name = new_name.replace("${%s}" % k, v)
new_name = new_name.replace(f"${{{k}}}", v)
return new_name
+1 -2
View File
@@ -2169,8 +2169,7 @@ class MinimalJobWrapper(HasResourceParameters):
)
return (
JobState.runner_states.OUTPUT_SIZE_LIMIT,
"Job output file grew too large (greater than %s), please try different inputs or parameters"
% util.nice_size(self.app.job_config.limits.output_size),
f"Job output file grew too large (greater than {util.nice_size(self.app.job_config.limits.output_size)}), please try different inputs or parameters",
)
if self.app.job_config.limits.walltime_delta is not None and runtime is not None:
if runtime > self.app.job_config.limits.walltime_delta:
+1 -1
View File
@@ -169,7 +169,7 @@ class BaseJobRunner:
try:
action_str = f"galaxy.jobs.runners.{self.__class__.__name__.lower()}.{name}"
action_timer = self.app.execution_timer_factory.get_timer(
f"internals.{action_str}", "job runner action %s for job ${job_id} executed" % (action_str)
f"internals.{action_str}", f"job runner action {action_str} for job ${{job_id}} executed"
)
method(arg)
log.trace(action_timer.to_str(job_id=job_id))
+1 -1
View File
@@ -528,7 +528,7 @@ class AWSBatchJobRunner(AsynchronousJobRunner):
parsed_params[k] = mapper(value) # type: ignore[operator]
if check_required:
raise AWSBatchRunnerException(
"AWSBatchJobRunner requires the following params to be provided: %s." % (", ".join(check_required))
"AWSBatchJobRunner requires the following params to be provided: {}.".format(", ".join(check_required))
)
# parse Platform
+2 -2
View File
@@ -13,7 +13,7 @@ except ImportError as exc:
PBS_IMPORT_MESSAGE = (
"The Python pbs-python package is required to use "
"this feature, please install it or correct the "
"following error:\nImportError %s" % str(exc)
f"following error:\nImportError {exc}"
)
from galaxy import (
@@ -514,7 +514,7 @@ class PBSJobRunner(AsynchronousJobRunner):
try:
pbs_server_name = self.__get_pbs_server(job.destination_params)
if pbs_server_name is None:
log.debug("(%s) Job queued but no destination stored in job params, cannot delete" % job_tag)
log.debug("(%s) Job queued but no destination stored in job params, cannot delete", job_tag)
return
c = pbs.pbs_connect(util.smart_str(pbs_server_name))
if c <= 0:
@@ -62,7 +62,7 @@ def _handle_resubmit_definitions(resubmit_definitions, app, job_runner, job_stat
# Is destination needed here, might these be serialized to the database?
destination = resubmit.get("environment") or resubmit.get("destination")
log.info(
"%s Job will be resubmitted to '%s' because %s at " "the '%s' destination",
"%s Job will be resubmitted to '%s' because %s at the '%s' destination",
job_log_prefix,
destination,
MESSAGES[runner_state],
@@ -106,7 +106,7 @@ def _handle_resubmit_definitions(resubmit_definitions, app, job_runner, job_stat
if job.params is None:
job.params = {}
job_state.runner_state_handled = True
info = "This job was resubmitted to the queue because %s on its " "compute resource." % MESSAGES[runner_state]
info = f"This job was resubmitted to the queue because {MESSAGES[runner_state]} on its compute resource."
job_runner.mark_as_resubmitted(job_state, info=info)
return
+1 -1
View File
@@ -52,7 +52,7 @@ class LSF(BaseJobExec):
# This should be really handled outside with something like
# parse_external. Currently CLI runner expect this to just send it in the last position
# of the string.
return "bsub <%s | awk '{ print $2}' | sed 's/[<>]//g'" % script_file
return f"bsub <{script_file} | awk '{{ print $2}}' | sed 's/[<>]//g'"
def delete(self, job_id):
return f"bkill {job_id}"
+1 -1
View File
@@ -25,7 +25,7 @@ except ImportError as exc:
K8S_IMPORT_MESSAGE = (
"The Python pykube package is required to use "
"this feature, please install it or correct the "
"following error:\nImportError %s" % str(exc)
f"following error:\nImportError {exc}"
)
log = logging.getLogger(__name__)
+3 -6
View File
@@ -69,7 +69,7 @@ class InteractiveToolSqlite:
try:
# Create table
c.execute(
"""CREATE TABLE %s
f"""CREATE TABLE {DATABASE_TABLE_NAME}
(key text,
key_type text,
token text,
@@ -78,7 +78,6 @@ class InteractiveToolSqlite:
info text,
PRIMARY KEY (key, key_type)
)"""
% (DATABASE_TABLE_NAME)
)
except Exception:
pass
@@ -90,11 +89,9 @@ class InteractiveToolSqlite:
key_type,
),
)
insert = """INSERT INTO %s
insert = f"""INSERT INTO {DATABASE_TABLE_NAME}
(key, key_type, token, host, port, info)
VALUES (?, ?, ?, ?, ?, ?)""" % (
DATABASE_TABLE_NAME
)
VALUES (?, ?, ?, ?, ?, ?)"""
c.execute(
insert,
(
+2 -2
View File
@@ -71,10 +71,10 @@ VALID_ARGUMENTS: Dict[str, Union[List[str], DynamicArguments]] = {
"invocation_inputs": [],
}
GALAXY_FLAVORED_MARKDOWN_CONTAINERS = list(VALID_ARGUMENTS.keys())
GALAXY_FLAVORED_MARKDOWN_CONTAINER_REGEX = r"(?P<container>%s)" % "|".join(GALAXY_FLAVORED_MARKDOWN_CONTAINERS)
GALAXY_FLAVORED_MARKDOWN_CONTAINER_REGEX = r"(?P<container>{})".format("|".join(GALAXY_FLAVORED_MARKDOWN_CONTAINERS))
ARG_VAL_REGEX = r"""[\w_\-]+|\"[^\"]+\"|\'[^\']+\'"""
FUNCTION_ARG = r"\s*[\w\|]+\s*=\s*(?:%s)\s*" % ARG_VAL_REGEX
FUNCTION_ARG = rf"\s*[\w\|]+\s*=\s*(?:{ARG_VAL_REGEX})\s*"
# embed commas between arguments
FUNCTION_MULTIPLE_ARGS = rf"(?P<firstargcall>{FUNCTION_ARG})(?P<restargcalls>(?:,{FUNCTION_ARG})*)"
FUNCTION_MULTIPLE_ARGS_PATTERN = re.compile(FUNCTION_MULTIPLE_ARGS)
+5 -5
View File
@@ -67,11 +67,11 @@ from .markdown_parse import (
log = logging.getLogger(__name__)
ARG_VAL_CAPTURED_REGEX = r"""(?:([\w_\-\|]+)|\"([^\"]+)\"|\'([^\']+)\')"""
OUTPUT_LABEL_PATTERN = re.compile(r"output=\s*%s\s*" % ARG_VAL_CAPTURED_REGEX)
INPUT_LABEL_PATTERN = re.compile(r"input=\s*%s\s*" % ARG_VAL_CAPTURED_REGEX)
STEP_LABEL_PATTERN = re.compile(r"step=\s*%s\s*" % ARG_VAL_CAPTURED_REGEX)
PATH_LABEL_PATTERN = re.compile(r"path=\s*%s\s*" % ARG_VAL_CAPTURED_REGEX)
SIZE_PATTERN = re.compile(r"size=\s*%s\s*" % ARG_VAL_CAPTURED_REGEX)
OUTPUT_LABEL_PATTERN = re.compile(rf"output=\s*{ARG_VAL_CAPTURED_REGEX}\s*")
INPUT_LABEL_PATTERN = re.compile(rf"input=\s*{ARG_VAL_CAPTURED_REGEX}\s*")
STEP_LABEL_PATTERN = re.compile(rf"step=\s*{ARG_VAL_CAPTURED_REGEX}\s*")
PATH_LABEL_PATTERN = re.compile(rf"path=\s*{ARG_VAL_CAPTURED_REGEX}\s*")
SIZE_PATTERN = re.compile(rf"size=\s*{ARG_VAL_CAPTURED_REGEX}\s*")
# STEP_OUTPUT_LABEL_PATTERN = re.compile(r'step_output=([\w_\-]+)/([\w_\-]+)')
UNENCODED_ID_PATTERN = re.compile(
r"(history_id|workflow_id|history_dataset_id|history_dataset_collection_id|job_id|implicit_collection_jobs_id|invocation_id)=([\d]+)"
+1 -1
View File
@@ -195,7 +195,7 @@ class UserManager(base.ModelManager, deletable.PurgableManagerMixin):
"The configuration of this Galaxy instance does not allow admins to delete or purge users."
)
if not user.deleted:
raise exceptions.MessageException("User '%s' has not been deleted, so they cannot be purged." % user.email)
raise exceptions.MessageException(f"User '{user.email}' has not been deleted, so they cannot be purged.")
private_role = self.app.security_agent.get_private_user_role(user)
# Delete History
for active_history in user.active_histories:
+2 -5
View File
@@ -612,13 +612,10 @@ def calculate_user_disk_usage_statements(user_id, quota_source_map, for_sqlite=F
if default_usage_dataset_condition.strip():
default_usage_dataset_condition = f"AND ( {default_usage_dataset_condition} )"
default_usage = UNIQUE_DATASET_USER_USAGE.format(and_dataset_condition=default_usage_dataset_condition)
default_usage = (
"""
UPDATE galaxy_user SET disk_usage = (%s)
default_usage = f"""
UPDATE galaxy_user SET disk_usage = ({default_usage})
WHERE id = :id
"""
% default_usage
)
params = {"id": user_id}
if default_exclude_ids:
params["exclude_object_store_ids"] = default_exclude_ids
+2 -2
View File
@@ -61,9 +61,9 @@ class SimpleTransientPathMapper(TransientPathMapper):
self._staging_directory = staging_directory
def transient_paths_for(self, old_dataset: Dataset) -> TransientDatasetPaths:
external_filename_basename = "dataset_%s.dat" % str(old_dataset.uuid)
external_filename_basename = f"dataset_{old_dataset.uuid}.dat"
external_filename = os.path.join(self._staging_directory, external_filename_basename)
external_extras_basename = "dataset_%s_files" % str(old_dataset.uuid)
external_extras_basename = f"dataset_{old_dataset.uuid}_files"
external_extras = os.path.join(self._staging_directory, external_extras_basename)
return TransientDatasetPaths(external_filename, external_extras, self._staging_directory)
+1 -1
View File
@@ -1621,7 +1621,7 @@ class BaseDirectoryImportModelStore(ModelImportStore):
attrs = load(open(file_name))
else:
if required:
raise Exception("Failed to find file [%s] in model store archive" % file_name)
raise Exception(f"Failed to find file [{file_name}] in model store archive")
attrs = []
return attrs
+2 -2
View File
@@ -1513,8 +1513,8 @@ def local_extra_dirs(func):
if c.__name__ == "DiskObjectStore":
return getattr(c, func.__name__)(self, *args, **kwargs)
raise Exception(
"Could not call DiskObjectStore's %s method, does your "
"Object Store plugin inherit from DiskObjectStore?" % func.__name__
f"Could not call DiskObjectStore's {func.__name__} method, does your "
"Object Store plugin inherit from DiskObjectStore?"
)
return wraps
@@ -35,7 +35,7 @@ class DeleteClient(UploadClient):
if not self.rses.get(rse):
rse_settings = self.rses.setdefault(rse, rsemgr.get_rse_info(rse, vo=self.client.vo))
if not ignore_availability and rse_settings["availability_delete"] != 1:
logger(logging.DEBUG, "%s is not available for deletion. No actions have been taken" % rse)
logger(logging.DEBUG, "%s is not available for deletion. No actions have been taken", rse)
continue
# protocol handling and deletion
@@ -52,8 +52,8 @@ class DeleteClient(UploadClient):
success = True
except Exception as error:
logger(logging.WARNING, "Delete attempt failed")
logger(logging.INFO, "Exception: %s" % str(error), exc_info=True)
logger(logging.DEBUG, "Successfully deleted dataset %s" % pfn)
logger(logging.INFO, "Exception: %s", error, exc_info=True)
logger(logging.DEBUG, "Successfully deleted dataset %s", pfn)
class InPlaceIngestClient(UploadClient):
@@ -107,7 +107,7 @@ class InPlaceIngestClient(UploadClient):
if not self.rses.get(rse):
rse_settings = self.rses.setdefault(rse, rsemgr.get_rse_info(rse, vo=self.client.vo))
if not ignore_availability and rse_settings["availability_write"] != 1:
raise RSEWriteBlocked("%s is not available for writing. No actions have been taken" % rse)
raise RSEWriteBlocked(f"{rse} is not available for writing. No actions have been taken")
dataset_scope = file.get("dataset_scope")
dataset_name = file.get("dataset_name")
@@ -120,7 +120,7 @@ class InPlaceIngestClient(UploadClient):
registered_file_dids.add(f"{file['did_scope']}:{file['did_name']}")
wrong_dids = registered_file_dids.intersection(registered_dataset_dids)
if len(wrong_dids):
raise InputValidationError("DIDs used to address both files and datasets: %s" % str(wrong_dids))
raise InputValidationError(f"DIDs used to address both files and datasets: {wrong_dids}")
logger(logging.DEBUG, "Input validation done.")
# clear this set again to ensure that we only try to register datasets once
@@ -129,7 +129,7 @@ class InPlaceIngestClient(UploadClient):
summary = []
for file in files:
basename = file["basename"]
logger(logging.INFO, "Preparing upload for file %s" % basename)
logger(logging.INFO, "Preparing upload for file %s", basename)
pfn = file.get("pfn")
@@ -169,7 +169,7 @@ class InPlaceIngestClient(UploadClient):
trace["transferEnd"] = time.time()
trace["clientState"] = "DONE"
file["state"] = "A"
logger(logging.INFO, "Successfully uploaded file %s" % basename)
logger(logging.INFO, "Successfully uploaded file %s", basename)
self._send_trace(trace)
if summary_file_path:
+5 -8
View File
@@ -87,22 +87,19 @@ def find_elements_by_sizzle(driver, sizzle_selector: str):
def _inject_sizzle(driver, sizzle_url, timeout):
script = (
"""
if(typeof(window.$) != "undefined") {
script = f"""
if(typeof(window.$) != "undefined") {{
// Just reuse jQuery if it is available, avoids potential amd problems
// that have cropped up with Galaxy for instance.
window.Sizzle = window.$;
} else {
}} else {{
var _s = document.createElement("script");
_s.type = "text/javascript";
_s.src = "%s";
_s.src = "{sizzle_url}";
var _h = document.getElementsByTagName("head")[0];
_h.appendChild(_s);
}
}}
"""
% sizzle_url
)
driver.execute_script(script)
wait = WebDriverWait(driver, timeout)
wait.until(lambda d: _is_sizzle_loaded(d), f"Can't inject Sizzle in {timeout} seconds")
+3 -4
View File
@@ -70,10 +70,9 @@ class ToolValidator:
sample_found = True
break
if not sample_found:
correction_msg = f"This file refers to a file named <b>{str(index_file_name)}</b>. "
correction_msg += (
"Upload a file named <b>%s.sample</b> to the repository to correct this error."
% str(index_file_name)
correction_msg = (
f"This file refers to a file named <b>{index_file_name}</b>. "
f"Upload a file named <b>{index_file_name}.sample</b> to the repository to correct this error."
)
invalid_files_and_errors_tups.append((tool_config_name, correction_msg))
return invalid_files_and_errors_tups
@@ -163,7 +163,7 @@ def set_image_paths(app, text, encoded_repository_id=None, tool_shed_repository=
# settings like .. images:: http_files/images/help.png
for match in re.findall(".. image:: (?!http)/?(.+)", text):
text = text.replace(match, match.replace("/", "%2F"))
text = re.sub(r"\.\. image:: (?!https?://)/?(.+)", r".. image:: %s/\1" % route_to_images, text)
text = re.sub(r"\.\. image:: (?!https?://)/?(.+)", rf".. image:: {route_to_images}/\1", text)
return text
+2 -2
View File
@@ -387,9 +387,9 @@ class EnvAction:
if self.action == "set" or not environ.get(self.variable, ""):
environ[self.variable] = self.__eval("${value}")
elif self.action == "prepend":
environ[self.variable] = self.__eval("${value}:%s" % environ[self.variable])
environ[self.variable] = self.__eval(f"${{value}}:{environ[self.variable]}")
else:
environ[self.variable] = self.__eval("%s:${value}" % environ[self.variable])
environ[self.variable] = self.__eval(f"{environ[self.variable]}:${{value}}")
def __eval(self, template):
return string.Template(template).safe_substitute(
@@ -307,7 +307,7 @@ def mull_targets(
conda_bin = "mamba"
if mamba_version is None:
mamba_version = ""
involucro_args.extend(["-set", "CONDA_BIN=%s" % conda_bin])
involucro_args.extend(["-set", f"CONDA_BIN={conda_bin}"])
if conda_version is not None or mamba_version is not None:
mamba_test = "true"
specs = []
+2 -1
View File
@@ -1133,7 +1133,8 @@ class StdioParser:
log.warning(
"Tool id %s: unable to determine if tool "
"stream source scanning is output, error, "
"or both. Defaulting to use both." % self.id
"or both. Defaulting to use both.",
self.id,
)
regex.stdout_match = True
regex.stderr_match = True
+3 -3
View File
@@ -2103,7 +2103,7 @@ class Tool(Dictifiable):
)
parent[input.name] = value
except Exception:
messages[prefixed_name] = "Attempt to replace invalid value for '%s' failed." % (prefixed_label)
messages[prefixed_name] = f"Attempt to replace invalid value for '{prefixed_label}' failed."
else:
messages[prefixed_name] = error
@@ -2315,7 +2315,7 @@ class Tool(Dictifiable):
if os.path.exists(filesystem_path):
tarball_files.append((filesystem_path, tarball_path))
image_found = True
tool_xml = tool_xml.replace("${static_path}/%s" % tarball_path, tarball_path)
tool_xml = tool_xml.replace(f"${{static_path}}/{tarball_path}", tarball_path)
# If one or more tool help images were found, add the modified tool XML to the tarball instead of the original.
if image_found:
with tempfile.NamedTemporaryFile(mode="w", suffix=".xml", delete=False) as fh2:
@@ -2684,7 +2684,7 @@ class Tool(Dictifiable):
)
if tool is None:
raise exceptions.MessageException(
"This dataset was created by an obsolete tool (%s). Can't re-run." % tool_id
f"This dataset was created by an obsolete tool ({tool_id}). Can't re-run."
)
if (self.id != tool_id and self.old_id != tool_id) or self.version != tool_version:
if self.id == tool_id:
@@ -154,7 +154,7 @@ class GitLabPlugin(BaseGitPlugin):
gl_emailquery = self.gitlab.users.list(search=gl_useremail)
log.debug(f"GitLab error reporting - User list: {gl_emailquery}")
if len(gl_emailquery) > 0:
log.debug("GitLab error reporting - Last Committer user ID: %s" % gl_emailquery[0].get_id())
log.debug("GitLab error reporting - Last Committer user ID: %s", gl_emailquery[0].get_id())
self.git_username_id_cache[gl_useremail] = gl_emailquery[0].get_id()
gl_userid = self.git_username_id_cache.get(gl_useremail, None)
+1 -1
View File
@@ -2,7 +2,7 @@
def literal_via_fence(content):
return "\n%s\n" % "\n".join(f" {line}" for line in content.splitlines())
return "\n{}\n".format("\n".join(f" {line}" for line in content.splitlines()))
def indicate_data_truncated():
+1 -1
View File
@@ -168,7 +168,7 @@ def topsort(pairlist):
for y in successors[x]:
numpreds[y] = numpreds[y] - 1
if numpreds[y] == 0:
answer.append(y) # noqa: B038
answer.append(y)
# following "del" isn't needed; just makes
# CycleError details easier to grasp
del successors[x]
@@ -171,7 +171,7 @@ def func_std_string(func_name):
# special case for built-in functions
name = func_name[2]
if name.startswith("<") and name.endswith(">"):
return "{%s}" % name[1:-1]
return f"{{{name[1:-1]}}}"
else:
return name
else:
+1 -1
View File
@@ -144,7 +144,7 @@ class WebApplication(base.WebApplication):
if rule.routepath.endswith(".:(format)") or not rule.routepath.startswith("api/"):
continue
# Try to replace routes various ways to encode variables with simple swagger {form}
swagger_path = "/%s" % RE_URL.sub(r"{\1}", rule.routepath)
swagger_path = "/{}".format(RE_URL.sub(r"{\1}", rule.routepath))
controller = rule.defaults.get("controller", "")
action = rule.defaults.get("action", "")
# Get the list of methods for the route
@@ -534,7 +534,7 @@ class AdminGalaxy(controller.JSAppLauncher):
in_groups.append(trans.security.encode_id(group.id))
all_groups.append((group.name, trans.security.encode_id(group.id)))
return {
"title": "Quota '%s'" % quota.name,
"title": f"Quota '{quota.name}'",
"message": "Quota '%s' is currently associated with %d user(s) and %d group(s)."
% (quota.name, len(in_users), len(in_groups)),
"status": "info",
@@ -797,7 +797,7 @@ class AdminGalaxy(controller.JSAppLauncher):
in_groups.append(trans.security.encode_id(group.id))
all_groups.append((group.name, trans.security.encode_id(group.id)))
return {
"title": "Role '%s'" % role.name,
"title": f"Role '{role.name}'",
"message": "Role '%s' is currently associated with %d user(s) and %d group(s)."
% (role.name, len(in_users), len(in_groups)),
"status": "info",
@@ -902,7 +902,7 @@ class AdminGalaxy(controller.JSAppLauncher):
in_roles.append(trans.security.encode_id(role.id))
all_roles.append((role.name, trans.security.encode_id(role.id)))
return {
"title": "Group '%s'" % group.name,
"title": f"Group '{group.name}'",
"message": "Group '%s' is currently associated with %d user(s) and %d role(s)."
% (group.name, len(in_users), len(in_roles)),
"status": "info",
@@ -332,7 +332,7 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
}
else:
return self.message_exception(
trans, "You do not have permission to edit this dataset's ( id: %s ) information." % str(dataset_id)
trans, f"You do not have permission to edit this dataset's ( id: {dataset_id} ) information."
)
@web.expose_api_anonymous
@@ -155,7 +155,7 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
"value": [trans.security.encode_id(role.id) for role in in_roles],
}
)
return {"title": "Change default dataset permissions for history '%s'" % history.name, "inputs": inputs}
return {"title": f"Change default dataset permissions for history '{history.name}'", "inputs": inputs}
else:
self.history_manager.error_unless_mutable(history)
permissions = {}
@@ -164,7 +164,7 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
in_roles = [trans.sa_session.get(Role, trans.security.decode_id(x)) for x in in_roles]
permissions[trans.app.security_agent.get_action(action.action)] = in_roles
trans.app.security_agent.history_set_default_permissions(history, permissions)
return {"message": "Default history '%s' dataset permissions have been changed." % history.name}
return {"message": f"Default history '{history.name}' dataset permissions have been changed."}
@web.legacy_expose_api
@web.require_login("make datasets private")
@@ -286,10 +286,10 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
new_name = payload.get("name_%i" % i)
# validate name is empty
if not isinstance(new_name, str) or not new_name.strip():
messages.append("You must specify a valid name for History '%s'." % cur_name)
messages.append(f"You must specify a valid name for History '{cur_name}'.")
# skip if not the owner
elif h.user_id != user.id:
messages.append("History '%s' does not appear to belong to you." % cur_name)
messages.append(f"History '{cur_name}' does not appear to belong to you.")
# skip if it wouldn't be a change
elif new_name != cur_name:
h.name = new_name
@@ -100,7 +100,7 @@ class PageController(BaseUIController, SharableMixin, UsesStoredWorkflowMixin, U
}
else:
page = self.page_manager.create_page(trans, CreatePagePayload(**payload))
return {"message": "Page '%s' successfully created." % page.title, "status": "success"}
return {"message": f"Page '{page.title}' successfully created.", "status": "success"}
@web.legacy_expose_api
@web.require_login("edit pages")
@@ -159,7 +159,7 @@ class PageController(BaseUIController, SharableMixin, UsesStoredWorkflowMixin, U
trans.sa_session.add(p)
with transaction(trans.sa_session):
trans.sa_session.commit()
return {"message": "Attributes of '%s' successfully saved." % p.title, "status": "success"}
return {"message": f"Attributes of '{p.title}' successfully saved.", "status": "success"}
@web.expose
@web.require_login()
@@ -46,9 +46,9 @@ class ToolRunner(BaseUIController):
def index(self, trans, tool_id=None, from_noframe=None, **kwd):
def __tool_404__():
log.debug("index called with tool id '%s' but no such tool exists", tool_id)
trans.log_event("Tool id '%s' does not exist" % tool_id)
trans.log_event(f"Tool id '{tool_id}' does not exist")
trans.response.status = 404
return trans.show_error_message("Tool '%s' does not exist." % (escape(tool_id)))
return trans.show_error_message(f"Tool '{escape(tool_id)}' does not exist.")
# tool id not available, redirect to main page
if tool_id is None:
@@ -225,7 +225,7 @@ class VisualizationController(
trans.sa_session.add(v)
with transaction(trans.sa_session):
trans.sa_session.commit()
return {"message": "Attributes of '%s' successfully saved." % v.title, "status": "success"}
return {"message": f"Attributes of '{v.title}' successfully saved.", "status": "success"}
# ------------------------- registry.
@web.expose
+2 -2
View File
@@ -138,7 +138,7 @@ def to_cwl(value, hda_references, step):
# I think the following two checks are needed but they may
# not be needed.
if not value.dataset.in_ready_state():
why = "dataset [%s] is needed for valueFrom expression and is non-ready" % value.id
why = f"dataset [{value.id}] is needed for valueFrom expression and is non-ready"
raise DelayedWorkflowEvaluation(why=why)
if not value.is_ok:
raise FailWorkflowEvaluation(
@@ -190,7 +190,7 @@ def from_cwl(value, hda_references, progress: "WorkflowProgress"):
# This is going to re-file -> HDA this each iteration I think, not a good
# implementation.
return progress.raw_to_galaxy(value)
assert value["location"].startswith("step_input://"), "Invalid location %s" % value
assert value["location"].startswith("step_input://"), f"Invalid location {value}"
return hda_references[int(value["location"][len("step_input://") :]) - 1]
elif isinstance(value, dict):
raise NotImplementedError()
+2 -2
View File
@@ -251,7 +251,7 @@ class WorkflowRefactorExecutor:
def _apply_extract_untyped_parameter(self, action: ExtractUntypedParameter, execution: RefactorActionExecution):
untyped_parameter_name = action.name
new_label = action.label or untyped_parameter_name
target_value = "${%s}" % untyped_parameter_name
target_value = f"${{{untyped_parameter_name}}}"
target_tool_inputs = []
rename_pjas = []
@@ -330,7 +330,7 @@ class WorkflowRefactorExecutor:
if untyped_parameter_name != new_label:
action_arguments = rename_pja.get("action_arguments")
old_newname = action_arguments["newname"]
new_newname = old_newname.replace(target_value, "${%s}" % new_label)
new_newname = old_newname.replace(target_value, f"${{{new_label}}}")
action_arguments["newname"] = new_newname
optional = False
+1 -1
View File
@@ -194,7 +194,7 @@ class TestLibrariesApi(ApiTestCase):
library = self.library_populator.new_private_library(library_name)
payload, files = self.library_populator.create_dataset_request(library, file_type="txt", contents="create_test")
create_response = self.galaxy_interactor.post(
"libraries/%s/contents" % library["id"], payload, files=files, key=self.master_api_key
f"libraries/{library['id']}/contents", payload, files=files, key=self.master_api_key
)
self._assert_status_code_is(create_response, 400)
@@ -137,8 +137,8 @@ class RepositoryDependencyAttributeHandler:
elem.attrib["changeset_revision"] = lastest_installable_changeset_revision
altered = True
else:
error_message = "Invalid latest installable changeset_revision %s " % str(
lastest_installable_changeset_revision
error_message = (
f"Invalid latest installable changeset_revision {lastest_installable_changeset_revision} "
)
error_message += f"retrieved for repository {name} owned by {owner}. "
else:
@@ -1036,10 +1036,10 @@ class RepositoryMetadataManager(ToolShedMetadataGenerator):
changeset_revisions.append(changeset_revision)
self._add_tool_versions(repository_id, repository_metadata, changeset_revisions)
elif len(repo) == 1 and not self.invalid_file_tups:
message = "Revision <b>%s</b> includes no Galaxy utilities for which metadata can " % str(
self.repository.tip()
message = (
f"Revision <b>{self.repository.tip()}</b> includes no Galaxy utilities for which metadata can "
"be defined so this revision cannot be automatically installed into a local Galaxy instance."
)
message += "be defined so this revision cannot be automatically installed into a local Galaxy instance."
status = "error"
if self.invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools(
+7 -15
View File
@@ -43,26 +43,18 @@ def generate_message_for_repository_type_change(app, repository):
repository_suite_definition_type_class = app.repository_types_registry.get_class_by_label(
REPOSITORY_SUITE_DEFINITION
)
message += (
"This repository currently contains a single file named <b>%s</b>. If the intent of this repository is "
% REPOSITORY_DEPENDENCY_DEFINITION_FILENAME
)
message += "to define relationships to a collection of repositories that contain related Galaxy utilities with "
message += (
"no plans to add additional files, consider setting its type to <b>%s</b>.<br/>"
% repository_suite_definition_type_class.label
message = (
f"This repository currently contains a single file named <b>{REPOSITORY_DEPENDENCY_DEFINITION_FILENAME}</b>. If the intent of this repository is "
"to define relationships to a collection of repositories that contain related Galaxy utilities with "
f"no plans to add additional files, consider setting its type to <b>{repository_suite_definition_type_class.label}</b>.<br/>"
)
elif repository.can_change_type_to(app, TOOL_DEPENDENCY_DEFINITION):
tool_dependency_definition_type_class = app.repository_types_registry.get_class_by_label(
TOOL_DEPENDENCY_DEFINITION
)
message += (
"This repository currently contains a single file named <b>%s</b>. If additional files will "
% TOOL_DEPENDENCY_DEFINITION_FILENAME
)
message += (
"not be added to this repository, consider setting its type to <b>%s</b>.<br/>"
% tool_dependency_definition_type_class.label
message = (
f"This repository currently contains a single file named <b>{TOOL_DEPENDENCY_DEFINITION_FILENAME}</b>. If additional files will "
f"not be added to this repository, consider setting its type to <b>{tool_dependency_definition_type_class.label}</b>.<br/>"
)
return message
+4 -6
View File
@@ -2048,9 +2048,7 @@ class ShedTwillTestCase(ShedApiTestCase):
def _assert_repo_has_tool_with_id(
self, installed_repository: galaxy_model.ToolShedRepository, tool_id: str
) -> None:
assert "tools" in installed_repository.metadata_, (
"No valid tools were defined in %s." % installed_repository.name
)
assert "tools" in installed_repository.metadata_, f"No valid tools were defined in {installed_repository.name}."
tools = installed_repository.metadata_["tools"]
found_it = False
for tool in tools: # type:ignore[attr-defined]
@@ -2064,9 +2062,9 @@ class ShedTwillTestCase(ShedApiTestCase):
def _assert_repo_has_invalid_tool_in_file(
self, installed_repository: galaxy_model.ToolShedRepository, name: str
) -> None:
assert "invalid_tools" in installed_repository.metadata_, (
"No invalid tools were defined in %s." % installed_repository.name
)
assert (
"invalid_tools" in installed_repository.metadata_
), f"No invalid tools were defined in {installed_repository.name}."
invalid_tools = installed_repository.metadata_["invalid_tools"]
found_it = name in invalid_tools
assert found_it, f"Did not find invalid tool file {name} in {invalid_tools}"
@@ -165,15 +165,14 @@ class TestDeletedDependencies(ShedTwillTestCase):
new_changeset_revision = self.get_repository_tip(repository)
# Check that the old changeset revision is still downloadable.
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, old_changeset_revision)
assert metadata_record.downloadable, (
"The revision of %s that contains repository_dependencies.xml is no longer downloadable." % repository.name
)
assert (
metadata_record.downloadable
), f"The revision of {repository.name} that contains repository_dependencies.xml is no longer downloadable."
# Check that the new tip is also downloadable.
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, new_changeset_revision)
assert metadata_record.downloadable, (
"The revision of %s that does not contain repository_dependencies.xml is not downloadable."
% repository.name
)
assert (
metadata_record.downloadable
), f"The revision of {repository.name} that does not contain repository_dependencies.xml is not downloadable."
# Verify that there are only two downloadable revisions.
assert (
len(self._db_repository(repository).downloadable_revisions) == 2
@@ -279,14 +278,14 @@ class TestDeletedDependencies(ShedTwillTestCase):
new_changeset_revision = self.get_repository_tip(repository)
# Check that the old changeset revision is still downloadable.
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, old_changeset_revision)
assert metadata_record.downloadable, (
"The revision of %s that contains tool_dependencies.xml is no longer downloadable." % repository.name
)
assert (
metadata_record.downloadable
), f"The revision of {repository.name} that contains tool_dependencies.xml is no longer downloadable."
# Check that the new tip is also downloadable.
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, new_changeset_revision)
assert metadata_record.downloadable, (
"The revision of %s that does not contain tool_dependencies.xml is not downloadable." % repository.name
)
assert (
metadata_record.downloadable
), f"The revision of {repository.name} that does not contain tool_dependencies.xml is not downloadable."
# Verify that there are only two downloadable revisions.
assert (
len(self._db_repository(repository).downloadable_revisions) == 2
@@ -331,9 +330,9 @@ class TestDeletedDependencies(ShedTwillTestCase):
assert old_changeset_revision != new_changeset_revision
# Check that the old changeset revision is still downloadable.
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, old_changeset_revision)
assert metadata_record.downloadable, (
"The revision of %s that contains tool_dependencies.xml is no longer downloadable." % repository.name
)
assert (
metadata_record.downloadable
), f"The revision of {repository.name} that contains tool_dependencies.xml is no longer downloadable."
# Check that the new tip does not have a metadata revision.
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, new_changeset_revision)
# If a changeset revision does not have metadata, the above method will return None.
@@ -364,15 +363,14 @@ class TestDeletedDependencies(ShedTwillTestCase):
new_changeset_revision = self.get_repository_tip(repository)
# Check that the old changeset revision is still downloadable.
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, old_changeset_revision)
assert metadata_record is None, (
"The revision of %s that does not contain tool_dependencies.xml should not be downloadable, but is."
% repository.name
)
assert (
metadata_record is None
), f"The revision of {repository.name} that does not contain tool_dependencies.xml should not be downloadable, but is."
# Check that the new tip is also downloadable.
metadata_record = self._get_repository_metadata_by_changeset_revision(repository, new_changeset_revision)
assert metadata_record.downloadable, (
"The revision of %s that contains tool_dependencies.xml is not downloadable." % repository.name
)
assert (
metadata_record.downloadable
), f"The revision of {repository.name} that contains tool_dependencies.xml is not downloadable."
# Verify that there are only two downloadable revisions.
assert (
len(self._db_repository(repository).downloadable_revisions) == 1
+2 -8
View File
@@ -136,20 +136,14 @@ def get_repository_file_contents(app: "ToolShedApp", file_path: str, repository_
safe_str = f"{safe_str}{basic_util.to_html_string(line)}"
# Stop reading after string is larger than MAX_CONTENT_SIZE.
if len(safe_str) > MAX_CONTENT_SIZE:
large_str = (
"<br/>File contents truncated because file size is larger than maximum viewing size of %s<br/>"
% util.nice_size(MAX_CONTENT_SIZE)
)
large_str = f"<br/>File contents truncated because file size is larger than maximum viewing size of {util.nice_size(MAX_CONTENT_SIZE)}<br/>"
safe_str = f"{safe_str}{large_str}"
break
if len(safe_str) > basic_util.MAX_DISPLAY_SIZE:
# Eliminate the middle of the file to display a file no larger than basic_util.MAX_DISPLAY_SIZE.
# This may not be ideal if the file is larger than MAX_CONTENT_SIZE.
join_by_str = (
"<br/><br/>...some text eliminated here because file size is larger than maximum viewing size of %s...<br/><br/>"
% util.nice_size(basic_util.MAX_DISPLAY_SIZE)
)
join_by_str = f"<br/><br/>...some text eliminated here because file size is larger than maximum viewing size of {util.nice_size(basic_util.MAX_DISPLAY_SIZE)}...<br/><br/>"
safe_str = util.shrink_string_by_size(
safe_str,
basic_util.MAX_DISPLAY_SIZE,
+6 -7
View File
@@ -85,8 +85,9 @@ class User(BaseUser):
if not success and not user and trans.app.config.require_login:
if trans.app.config.allow_user_creation:
create_account_str = (
" If you don't already have an account, <a href='%s'>you may create one</a>."
% web.url_for(controller="user", action="create", cntrller="user")
" If you don't already have an account, <a href='{}'>you may create one</a>.".format(
web.url_for(controller="user", action="create", cntrller="user")
)
)
header = REQUIRE_LOGIN_TEMPLATE % ("Galaxy tool shed", create_account_str)
else:
@@ -243,9 +244,9 @@ class User(BaseUser):
if not message:
# Default to a non-userinfo-leaking response message
message = (
"Your reset request for %s has been received. "
f"Your reset request for {escape(email)} has been received. "
"Please check your email account for more instructions. "
"If you do not receive an email shortly, please contact an administrator." % (escape(email))
"If you do not receive an email shortly, please contact an administrator."
)
reset_user = get_user_by_email(trans.sa_session, email, trans.app.model.User)
if not reset_user:
@@ -476,9 +477,7 @@ class User(BaseUser):
@web.expose
def logout(self, trans, logout_all=False, **kwd):
trans.handle_user_logout(logout_all=logout_all)
message = 'You have been logged out.<br>To log in again <a target="_top" href="%s">go to the home page</a>.' % (
url_for("/")
)
message = f'You have been logged out.<br>To log in again <a target="_top" href="{url_for("/")}">go to the home page</a>.'
if trans.app.config.use_remote_user and trans.app.config.remote_user_logout_href:
trans.response.send_redirect(trans.app.config.remote_user_logout_href)
else:
+5 -5
View File
@@ -36,7 +36,7 @@ def get(api_key, url):
try:
return json.loads(urlopen(url).read())
except ValueError as e:
print("URL did not return JSON data: %s" % e)
print(f"URL did not return JSON data: {e}")
sys.exit(1)
@@ -87,14 +87,14 @@ def display(api_key, url, return_formatted=True):
print("------------------")
for n, i in enumerate(r):
if isinstance(i, str):
print(" %s" % i)
print(f" {i}")
else:
# All collection members should have a name in the response.
# url is optional
if "url" in i:
print("#%d: %s" % (n + 1, i.pop("url")))
if "name" in i:
print(" name: %s" % i.pop("name"))
print(f" name: {i.pop('name')}")
try:
for k, v in i.items():
print(f" {k}: {v}")
@@ -112,7 +112,7 @@ def display(api_key, url, return_formatted=True):
elif isinstance(r, str):
print(r)
else:
print("response is unknown type: %s" % type(r))
print(f"response is unknown type: {type(r)}")
def submit(api_key, url, data, return_formatted=True):
@@ -143,7 +143,7 @@ def submit(api_key, url, data, return_formatted=True):
else:
print("----")
if "name" in i:
print(" name: %s" % i.pop("name"))
print(f" name: {i.pop('name')}")
for k, v in i.items():
print(f" {k}: {v}")
else:
+2 -2
View File
@@ -47,7 +47,7 @@ def run_tool(tool_id, history_id, params, api_key, galaxy_url, wait=True, sleep_
def get_dataset_state(hda_id, api_key, galaxy_url):
datasets_url = urljoin(galaxy_url, "api/datasets/%s" % hda_id)
datasets_url = urljoin(galaxy_url, f"api/datasets/{hda_id}")
dataset_info = get(api_key, datasets_url)
return dataset_info["state"]
@@ -117,7 +117,7 @@ if __name__ == "__main__":
wait=False,
)
else:
"dbkey (%s) was specified more than once, skipping additional specification." % (dbkey)
f"dbkey ({dbkey}) was specified more than once, skipping additional specification."
print("Genomes Queued for downloading.")
+1 -1
View File
@@ -9,7 +9,7 @@ from common import display # noqa: I100,I202
try:
display(*sys.argv[1:3])
except TypeError as e:
print("usage: %s key url" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url")
print(e)
sys.exit(1)
except URLError as e:
+4 -4
View File
@@ -33,11 +33,11 @@ def main(api_key, api_url, in_folder, out_folder, data_library, workflow):
lib_create_data = {"name": data_library}
library = submit(api_key, api_url + "libraries", lib_create_data, return_formatted=False)
library_id = library[0]["id"]
folders = display(api_key, api_url + "libraries/%s/contents" % library_id, return_formatted=False)
folders = display(api_key, api_url + f"libraries/{library_id}/contents", return_formatted=False)
for f in folders:
if f["name"] == "/":
library_folder_id = f["id"]
workflow = display(api_key, api_url + "workflows/%s" % workflow, return_formatted=False)
workflow = display(api_key, api_url + f"workflows/{workflow}", return_formatted=False)
if not workflow:
print("Workflow %s not found, terminating.")
sys.exit(1)
@@ -57,7 +57,7 @@ def main(api_key, api_url, in_folder, out_folder, data_library, workflow):
data["upload_option"] = "upload_paths"
data["filesystem_paths"] = fullpath
data["create_type"] = "file"
libset = submit(api_key, api_url + "libraries/%s/contents" % library_id, data, return_formatted=False)
libset = submit(api_key, api_url + f"libraries/{library_id}/contents", data, return_formatted=False)
# TODO Handle this better, but the datatype isn't always
# set for the followup workflow execution without this
# pause.
@@ -88,6 +88,6 @@ if __name__ == "__main__":
data_library = sys.argv[5]
workflow = sys.argv[6]
except IndexError:
print("usage: %s key url in_folder out_folder data_library workflow" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url in_folder out_folder data_library workflow")
sys.exit(1)
main(api_key, api_url, in_folder, out_folder, data_library, workflow)
@@ -16,8 +16,7 @@ from bioblend.galaxy import (
if len(sys.argv) < 5:
print(
"Usage: %s <GalaxyUrl> <ApiKey> <HistoryName (must be unique)> <CollectionHistoryId (i.e. the simple integer id)>"
% sys.argv[0]
f"Usage: {sys.argv[0]} <GalaxyUrl> <ApiKey> <HistoryName (must be unique)> <CollectionHistoryId (i.e. the simple integer id)>"
)
exit(0)
+1 -1
View File
@@ -8,7 +8,7 @@ from common import submit
try:
assert sys.argv[2]
except IndexError:
print("usage: %s key url [name] " % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url [name] ")
sys.exit(1)
try:
data = {}
+1 -1
View File
@@ -8,7 +8,7 @@ from common import delete
try:
assert sys.argv[2]
except IndexError:
print("usage: %s key url [purge (true/false)] " % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url [purge (true/false)] ")
sys.exit(1)
try:
data = {}
@@ -10,7 +10,7 @@ try:
data = {}
data["from_ld_id"] = sys.argv[3]
except IndexError:
print("usage: %s key url library_file_id" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url library_file_id")
print(" library_file_id is from /api/libraries/<library_id>/contents/<library_file_id>")
sys.exit(1)
+1 -1
View File
@@ -11,7 +11,7 @@ try:
data["name"] = sys.argv[4]
data["create_type"] = "folder"
except IndexError:
print("usage: %s key url folder_id name [description]" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url folder_id name [description]")
sys.exit(1)
try:
data["description"] = sys.argv[5]
+1 -1
View File
@@ -9,7 +9,7 @@ try:
data = {}
data["name"] = sys.argv[3]
except IndexError:
print("usage: %s key url name [description] [synopsys]" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url name [description] [synopsys]")
sys.exit(1)
try:
data["description"] = sys.argv[4]
@@ -18,7 +18,7 @@ try:
data["upload_option"] = "upload_directory"
data["create_type"] = "file"
except IndexError:
print("usage: %s key url folder_id file_type server_dir dbkey" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url folder_id file_type server_dir dbkey")
sys.exit(1)
submit(sys.argv[1], sys.argv[2], data)
+2 -2
View File
@@ -39,7 +39,7 @@ def load_file(fullpath, api_key, api_url, library_id, library_folder_id, uuid_fi
if uuid_field is not None and uuid_field in ext_meta:
data["uuid"] = ext_meta[uuid_field]
libset = submit(api_key, api_url + "libraries/%s/contents" % library_id, data, return_formatted=True)
libset = submit(api_key, api_url + f"libraries/{library_id}/contents", data, return_formatted=True)
print(libset)
@@ -54,7 +54,7 @@ def main(api_key, api_url, in_folder, data_library, uuid_field=None):
lib_create_data = {"name": data_library}
library = submit(api_key, api_url + "libraries", lib_create_data, return_formatted=False)
library_id = library["id"]
folders = display(api_key, api_url + "libraries/%s/contents" % library_id, return_formatted=False)
folders = display(api_key, api_url + f"libraries/{library_id}/contents", return_formatted=False)
for f in folders:
if f["name"] == "/":
library_folder_id = f["id"]
@@ -15,7 +15,7 @@ from common import submit
def main(options):
base_galaxy_url = options.galaxy_url.rstrip("/")
url = "%s/api/tool_shed_repositories/reset_metadata_on_installed_repositories" % base_galaxy_url
url = f"{base_galaxy_url}/api/tool_shed_repositories/reset_metadata_on_installed_repositories"
submit(options.api, url, {})
+1 -1
View File
@@ -17,7 +17,7 @@ from common import delete
try:
assert sys.argv[2]
except IndexError:
print("usage: %s key url [purge (true/false)] " % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url [purge (true/false)] ")
sys.exit(1)
try:
data = {}
+1 -1
View File
@@ -24,7 +24,7 @@ def main():
step, src, ds_id = v.split("=")
data["ds_map"][step] = {"src": src, "id": ds_id}
except IndexError:
print("usage: %s key url workflow_id history step=src=dataset_id" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url workflow_id history step=src=dataset_id")
sys.exit(1)
submit(sys.argv[1], sys.argv[2], data)
+1 -1
View File
@@ -46,7 +46,7 @@ def main():
print("TOOL ID ERROR:")
except IndexError:
print("usage: %s key url workflow_id history step=src=dataset_id" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url workflow_id history step=src=dataset_id")
sys.exit(1)
submit(sys.argv[1], sys.argv[2], data)
+2 -2
View File
@@ -14,14 +14,14 @@ from common import submit
def main():
api_key = sys.argv[1]
api_base_url = sys.argv[2]
api_url = "%s/api/workflows" % api_base_url
api_url = f"{api_base_url}/api/workflows"
try:
data = {}
data["installed_repository_file"] = sys.argv[3]
if len(sys.argv) > 4 and sys.argv[4] == "--add_to_menu":
data["add_to_menu"] = True
except IndexError:
print("usage: %s key galaxy_url workflow_file" % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key galaxy_url workflow_file")
sys.exit(1)
submit(api_key, api_url, data, return_formatted=False)
@@ -20,7 +20,7 @@ def openWorkflow(in_file):
try:
assert sys.argv[2]
except IndexError:
print("usage: %s key url [name] " % os.path.basename(sys.argv[0]))
print(f"usage: {os.path.basename(sys.argv[0])} key url [name] ")
sys.exit(1)
try:
data = {}
+3 -3
View File
@@ -29,12 +29,12 @@ class ApplyTagsHistory:
try:
update_history = history.show_history(self.history_id)
except Exception as exception:
print("Some problem occurred with history: %s" % self.history_id)
print(f"Some problem occurred with history: {self.history_id}")
print(exception)
return
update_history_id = update_history["id"]
print("History name: %s" % update_history["name"])
print("History id: %s" % update_history_id)
print(f"History name: {update_history['name']}")
print(f"History id: {update_history_id}")
self.find_dataset_parents_update_tags(history, job, update_history_id)
def find_dataset_parents_update_tags(self, history, job, history_id):
+1 -1
View File
@@ -141,7 +141,7 @@ def scanfiles(filenamelist):
newtoolelement = ET.Element("tool", attrib)
toolboxpositionelements = toolelement.findall("toolboxposition")
if not toolboxpositionelements:
print("DBG> %s has no toolboxposition" % fn)
print(f"DBG> {fn} has no toolboxposition")
else:
for toolboxpositionelement in toolboxpositionelements:
toolbox.add(newtoolelement, toolboxpositionelement)
+4 -3
View File
@@ -3,6 +3,8 @@ If the current installed Python version is not supported, prints an error
message to stderr and returns 1
"""
from __future__ import print_function # noqa: UP010
import sys
@@ -13,13 +15,12 @@ def check_python():
else:
version_string = ".".join(str(_) for _ in sys.version_info[:3])
msg = (
"""\
ERROR: Your Python version is: %s
"""ERROR: Your Python version is: %s
Galaxy is currently supported on Python >=3.8 .
To run Galaxy, please install a supported Python version.
If a supported version is already installed but is not your default,
https://docs.galaxyproject.org/en/latest/admin/python.html contains instructions
on how to force Galaxy to use a different version."""
on how to force Galaxy to use a different version.""" # noqa: UP031
% version_string
)
print(msg, file=sys.stderr)
@@ -151,7 +151,7 @@ def main():
template_file = args.template
if template_file is None:
default_template = os.path.join(scriptdir, "admin_cleanup_deletion_template.txt")
sample_template_file = "%s.sample" % default_template
sample_template_file = f"{default_template}.sample"
if os.path.exists(default_template):
template_file = default_template
elif os.path.exists(sample_template_file):
@@ -164,7 +164,7 @@ def main():
"found, please specify template as an option (--template)."
)
elif not os.path.exists(template_file):
parser.error("Specified template file (%s) not found." % template_file)
parser.error(f"Specified template file ({template_file}) not found.")
config = galaxy.config.Configuration(**app_properties)
@@ -273,9 +273,9 @@ def administrative_delete_datasets(
subject = "Galaxy Server Cleanup " "- %d datasets DELETED" % len(dataset_list)
fromaddr = config.email_from
print()
print("From: %s" % fromaddr)
print("To: %s" % email)
print("Subject: %s" % subject)
print(f"From: {fromaddr}")
print(f"To: {email}")
print(f"Subject: {subject}")
print("----------")
print(msgtext)
if not info_only:
+9 -9
View File
@@ -143,22 +143,22 @@ class Action:
else:
logf = os.path.join(self._log_dir, self.name + ".log")
if self._dry_run:
log.info("--dry-run specified, logging changes to stderr instead of log file: %s" % logf)
log.info("--dry-run specified, logging changes to stderr instead of log file: %s", logf)
h = set_log_handler()
else:
log.info("Opening log file: %s" % logf)
log.info("Opening log file: %s", logf)
h = set_log_handler(filename=logf)
h.setLevel(logging.DEBUG if self._debug else logging.INFO)
h.setFormatter(LevelFormatter())
self.__log = logging.getLogger(self.name)
self.__log.addHandler(h)
self.__log.propagate = False
m = ("==== Log opened: %s " % datetime.datetime.now().isoformat()).ljust(72, "=")
m = (f"==== Log opened: {datetime.datetime.now().isoformat()} ").ljust(72, "=")
self.__log.info(m)
self.__log.info(f"Epoch time for this action: {self._epoch_time}")
self.__log.info("Epoch time for this action: %s", self._epoch_time)
def __close_log(self):
m = ("==== Log closed: %s " % datetime.datetime.now().isoformat()).ljust(72, "=")
m = (f"==== Log closed: {datetime.datetime.now().isoformat()} ").ljust(72, "=")
self.log.info(m)
self.__log = None
@@ -1221,7 +1221,7 @@ class Cleanup:
self.__conn = psycopg2.connect(cursor_factory=NamedTupleCursor, **args)
# TODO: is this per session or cursor?
if self.args.work_mem is not None:
log.info("Setting work_mem to %s" % self.args.work_mem)
log.info("Setting work_mem to %s", self.args.work_mem)
self.__conn.cursor().execute("SET work_mem TO %s", (self.args.work_mem,))
return self.__conn
@@ -1271,7 +1271,7 @@ class Cleanup:
nargs="*",
metavar="ACTION",
default=[],
help="Action(s) to perform, chosen from: %s" % ", ".join(sorted(self.actions.keys())),
help="Action(s) to perform, chosen from: {}".format(", ".join(sorted(self.actions.keys()))),
)
self.args = parser.parse_args()
@@ -1292,7 +1292,7 @@ class Cleanup:
ok = True
for name in self.args.actions:
if name not in self.actions.keys():
log.error("Unknown action in sequence: %s" % name)
log.error("Unknown action in sequence: %s", name)
ok = False
if not ok:
log.critical("Exiting due to previous error(s)")
@@ -1381,7 +1381,7 @@ class Cleanup:
self.__current_action = name
with cls(self) as action:
self._run_action(action)
log.info("Finished %s" % name)
log.info("Finished %s", name)
if __name__ == "__main__":
+4 -4
View File
@@ -55,14 +55,14 @@ def _dump_option(option, current_section_desc):
type = "str"
if default == "None":
default = None
print_line("%s:" % key)
print_line(" type: %s" % type)
print_line(f"{key}:")
print_line(f" type: {type}")
if default is not None:
print_line(" default: %s" % default)
print_line(f" default: {default}")
# print_line(" required: false")
print_line(" desc: |")
for line in current_section_desc:
print_line(" %s" % line)
print_line(f" {line}")
print_line("")
+3 -3
View File
@@ -85,7 +85,7 @@ def printquery(statement, bind=None):
"""
if isinstance(value, str):
value = value.replace("'", "''")
return "'%s'" % value
return f"'{value}'"
elif value is None:
return "NULL"
elif isinstance(value, (float, int)):
@@ -93,10 +93,10 @@ def printquery(statement, bind=None):
elif isinstance(value, decimal.Decimal):
return str(value)
elif isinstance(value, datetime.datetime):
return "TO_DATE('%s','YYYY-MM-DD HH24:MI:SS')" % value.strftime("%Y-%m-%d %H:%M:%S")
return f"TO_DATE('{value.strftime('%Y-%m-%d %H:%M:%S')}','YYYY-MM-DD HH24:MI:SS')"
else:
raise NotImplementedError("Don't know how to literal-quote value %r" % value)
raise NotImplementedError(f"Don't know how to literal-quote value {value!r}")
compiler = LiteralCompiler(dialect, statement)
print(compiler.process(statement))
+1 -1
View File
@@ -14,7 +14,7 @@ import drmaa
def validate_paramters():
if len(sys.argv) < 3:
sys.stderr.write("usage: %s [job ID] [user uid]\n" % sys.argv[0])
sys.stderr.write(f"usage: {sys.argv[0]} [job ID] [user uid]\n")
exit(1)
jobID = sys.argv[1]
+3 -3
View File
@@ -50,14 +50,14 @@ def get_user_id_by_name(username):
try:
pw = pwd.getpwnam(username)
except KeyError:
sys.stderr.write("error: User name (%s) is not valid.\n" % username)
sys.stderr.write(f"error: User name ({username}) is not valid.\n")
exit(1)
return pw.pw_uid
def json_file_exists(json_filename):
if not os.path.exists(json_filename):
sys.stderr.write("error: JobTemplate file (%s) doesn't exist\n" % (json_filename))
sys.stderr.write(f"error: JobTemplate file ({json_filename}) doesn't exist\n")
exit(1)
return True
@@ -70,7 +70,7 @@ def validate_paramters():
sys.argv.remove("--assign_all_groups")
if len(sys.argv) < 3:
sys.stderr.write("usage: %s [USER-ID] [JSON-JOB-TEMPLATE-FILE]\n" % sys.argv[0])
sys.stderr.write(f"usage: {sys.argv[0]} [USER-ID] [JSON-JOB-TEMPLATE-FILE]\n")
exit(1)
userid = sys.argv[1]
+2 -2
View File
@@ -138,11 +138,11 @@ def _get_library_dataset_paths(args, kwargs):
filename = object_store.get_filename(dataset)
files_dir = dataset.get_extra_files_path()
if (args.exists and object_store.exists(dataset)) or not args.exists:
output.write("%s\n" % _path(filename, args))
output.write(f"{_path(filename, args)}\n")
elif args.exists:
log.warning("Missing %s", filename)
if files_dir and os.path.exists(files_dir):
output.write("%s\n" % _path(files_dir, args))
output.write(f"{_path(files_dir, args)}\n")
last_library = library
output.close()
+3 -3
View File
@@ -15,7 +15,7 @@ ALLOWED_PATHS = None
def validate_parameters():
if len(sys.argv) < 4:
sys.stderr.write("usage: %s path user_name gid\n" % sys.argv[0])
sys.stderr.write(f"usage: {sys.argv[0]} path user_name gid\n")
exit(1)
path = os.path.abspath(sys.argv[1])
@@ -28,7 +28,7 @@ def validate_parameters():
allowed = True
break
if not allowed:
sys.stderr.write("owner and group modifications in %s are not allowed\n" % path)
sys.stderr.write(f"owner and group modifications in {path} are not allowed\n")
sys.exit(1)
galaxy_user_name = sys.argv[2]
@@ -44,7 +44,7 @@ def main():
(stdoutdata, stderrdata) = p.communicate()
exitcode = p.returncode
if exitcode != 0:
sys.exit("external_chown_script: could not chown\ncmd was %s\n" % " ".join(cmd))
sys.exit("external_chown_script: could not chown\ncmd was {}\n".format(" ".join(cmd)))
if __name__ == "__main__":
+1 -1
View File
@@ -56,7 +56,7 @@ def kw_metrics(job):
def round_to_2sd(number):
if number:
return str(int(float("%.2g" % number)))
return str(int(float(f"{number:.2g}")))
else:
return "-1"
+27 -34
View File
@@ -272,16 +272,16 @@ def __main__():
paths_to_look_in = [os.path.join(options.genome_dir, "%s")]
# say what we're looking in
print("\nLooking in:\n\t%s" % "\n\t".join(p % "<build_name>" for p in paths_to_look_in))
poss_names = ["<build_name>%s" % _ for _ in variants]
print("for files that are named %s" % ", ".join(poss_names[:-1]), end=" ")
print("\nLooking in:\n\t{}".format("\n\t".join(p % "<build_name>" for p in paths_to_look_in)))
poss_names = [f"<build_name>{_}" for _ in variants]
print("for files that are named {}".format(", ".join(poss_names[:-1])), end=" ")
if len(poss_names) > 1:
print("or %s" % poss_names[-1], end=" ")
print(f"or {poss_names[-1]}", end=" ")
if len(options.fasta_exts) == 1:
print("with the extension %s." % ", ".join(fasta_exts[:-1]))
print("with the extension {}.".format(", ".join(fasta_exts[:-1])))
else:
print("with the extension {} or {}.".format(", ".join(fasta_exts[:-1]), fasta_exts[-1]))
print("\nSkipping the following:\n\t%s" % "\n\t".join(exemptions))
print("\nSkipping the following:\n\t{}".format("\n\t".join(exemptions)))
# get column names
col_values = []
@@ -350,40 +350,33 @@ def __main__():
# output results
print(
"\nThere were %s fasta files found that were not included because they did not have the expected file names."
% len(unmatching_fasta_paths)
f"\nThere were {len(unmatching_fasta_paths)} fasta files found that were not included because they did not have the expected file names."
)
print("%s fasta files were found and listed.\n" % len(fasta_locs.keys()))
print(f"{len(fasta_locs.keys())} fasta files were found and listed.\n")
# output unmatching fasta files
if options.unmatching_fasta and unmatching_fasta_paths:
open(options.unmatching_fasta, "wb").write("%s\n" % "\n".join(unmatching_fasta_paths))
open(options.unmatching_fasta, "wb").write("{}\n".format("\n".join(unmatching_fasta_paths)))
# output loc file
if options.append:
all_fasta_loc = open(loc_path, "ab")
else:
all_fasta_loc = open(loc_path, "wb")
# put sample loc file text at top of file if appropriate
if sample_text:
if options.loc_sample_name:
all_fasta_loc.write("%s\n" % open(options.loc_sample_name, "rb").read().strip())
else:
all_fasta_loc.write("%s\n" % open("%s.sample" % loc_path, "rb").read().strip())
# output list of fasta files in alphabetical order
fasta_bases = list(fasta_locs.keys())
fasta_bases.sort(key=str.upper)
for fb in fasta_bases:
out_line = []
for col in col_values:
try:
out_line.append(fasta_locs[fb][col])
except KeyError:
raise Exception("Unexpected column (%s) encountered" % col)
if out_line:
all_fasta_loc.write("%s\n" % "\t".join(out_line))
# close up output loc file
all_fasta_loc.close()
with open(loc_path, "ab" if options.append else "wb") as all_fasta_loc:
# put sample loc file text at top of file if appropriate
if sample_text:
loc_sample_name = options.loc_sample_name if options.loc_sample_name else f"{loc_path}.sample"
with open(loc_sample_name, "rb") as loc_sample_name_fh:
all_fasta_loc.write(f"{loc_sample_name_fh.read().strip()}\n")
# output list of fasta files in alphabetical order
fasta_bases = list(fasta_locs.keys())
fasta_bases.sort(key=str.upper)
for fb in fasta_bases:
out_line = []
for col in col_values:
try:
out_line.append(fasta_locs[fb][col])
except KeyError:
raise Exception(f"Unexpected column ({col}) encountered")
if out_line:
all_fasta_loc.write("{}\n".format("\t".join(out_line)))
if __name__ == "__main__":
+7 -7
View File
@@ -95,11 +95,11 @@ def __main__():
chr["chromosome"],
"sequence",
"fasta",
os.path.join(org["base_dir"], "%s.fna" % chr["chromosome"]),
os.path.join(org["base_dir"], f"{chr['chromosome']}.fna"),
)
)
# GeneMark
if os.path.exists(os.path.join(org["base_dir"], "%s.GeneMark.bed" % chr["chromosome"])):
if os.path.exists(os.path.join(org["base_dir"], f"{chr['chromosome']}.GeneMark.bed")):
print(
"DATA\t{}_{}_{}\t{}\t{}\t{}\t{}\t{}".format(
build,
@@ -109,11 +109,11 @@ def __main__():
chr["chromosome"],
"GeneMark",
"bed",
os.path.join(org["base_dir"], "%s.GeneMark.bed" % chr["chromosome"]),
os.path.join(org["base_dir"], f"{chr['chromosome']}.GeneMark.bed"),
)
)
# GenMarkHMM
if os.path.exists(os.path.join(org["base_dir"], "%s.GeneMarkHMM.bed" % chr["chromosome"])):
if os.path.exists(os.path.join(org["base_dir"], f"{chr['chromosome']}.GeneMarkHMM.bed")):
print(
"DATA\t{}_{}_{}\t{}\t{}\t{}\t{}\t{}".format(
build,
@@ -123,11 +123,11 @@ def __main__():
chr["chromosome"],
"GeneMarkHMM",
"bed",
os.path.join(org["base_dir"], "%s.GeneMarkHMM.bed" % chr["chromosome"]),
os.path.join(org["base_dir"], f"{chr['chromosome']}.GeneMarkHMM.bed"),
)
)
# Glimmer3
if os.path.exists(os.path.join(org["base_dir"], "%s.Glimmer3.bed" % chr["chromosome"])):
if os.path.exists(os.path.join(org["base_dir"], f"{chr['chromosome']}.Glimmer3.bed")):
print(
"DATA\t{}_{}_{}\t{}\t{}\t{}\t{}\t{}".format(
build,
@@ -137,7 +137,7 @@ def __main__():
chr["chromosome"],
"Glimmer3",
"bed",
os.path.join(org["base_dir"], "%s.Glimmer3.bed" % chr["chromosome"]),
os.path.join(org["base_dir"], f"{chr['chromosome']}.Glimmer3.bed"),
)
)
+2 -2
View File
@@ -74,8 +74,8 @@ def __main__():
for chr in org["chrs"]:
chr = org["chrs"][chr]
fasta_file = os.path.join(org["base_dir"], "%s.fna" % chr["chromosome"])
nib_out_file = os.path.join(seq_path, "%s.nib " % chr["chromosome"])
fasta_file = os.path.join(org["base_dir"], f"{chr['chromosome']}.fna")
nib_out_file = os.path.join(seq_path, f"{chr['chromosome']}.nib ")
# create nibs using faToNib binary
# TODO: when bx supports writing nib, use it here instead
command = f"faToNib {fasta_file} {nib_out_file}"
+18 -18
View File
@@ -158,18 +158,18 @@ def process_FASTA(filename, org_num, refseq):
fasta = "".join(fasta)
# Create Chrom Info File:
chrom_info_file = open(os.path.join(os.path.split(filename)[0], "%s.info" % refseq), "wb+")
chrom_info_file = open(os.path.join(os.path.split(filename)[0], f"{refseq}.info"), "wb+")
chrom_info_file.write(f"chromosome={refseq}\nname={chr_name}\nlength={len(fasta)}\norganism={org_num}\n")
try:
chrom_info_file.write("gi=%s\n" % accesions["gi"])
chrom_info_file.write(f"gi={accesions['gi']}\n")
except Exception:
chrom_info_file.write("gi=None\n")
try:
chrom_info_file.write("gb=%s\n" % accesions["gb"])
chrom_info_file.write(f"gb={accesions['gb']}\n")
except Exception:
chrom_info_file.write("gb=None\n")
try:
chrom_info_file.write("refseq=%s\n" % refseq)
chrom_info_file.write(f"refseq={refseq}\n")
except Exception:
chrom_info_file.write("refseq=None\n")
chrom_info_file.close()
@@ -191,7 +191,7 @@ def process_Glimmer3(filename, org_num, refseq):
except Exception as e:
print("Converting Glimmer3 to bed FAILED! For chrom:", refseq, "file:", filename, e)
glimmer3_bed = []
glimmer3_bed_file = open(os.path.join(os.path.split(filename)[0], "%s.Glimmer3.bed" % refseq), "wb+")
glimmer3_bed_file = open(os.path.join(os.path.split(filename)[0], f"{refseq}.Glimmer3.bed"), "wb+")
glimmer3_bed_file.write("\n".join(glimmer3_bed))
glimmer3_bed_file.close()
@@ -202,7 +202,7 @@ def process_GeneMarkHMM(filename, org_num, refseq):
except Exception as e:
print("Converting GeneMarkHMM to bed FAILED! For chrom:", refseq, "file:", filename, e)
geneMarkHMM_bed = []
geneMarkHMM_bed_bed_file = open(os.path.join(os.path.split(filename)[0], "%s.GeneMarkHMM.bed" % refseq), "wb+")
geneMarkHMM_bed_bed_file = open(os.path.join(os.path.split(filename)[0], f"{refseq}.GeneMarkHMM.bed"), "wb+")
geneMarkHMM_bed_bed_file.write("\n".join(geneMarkHMM_bed))
geneMarkHMM_bed_bed_file.close()
@@ -213,7 +213,7 @@ def process_GeneMark(filename, org_num, refseq):
except Exception as e:
print("Converting GeneMark to bed FAILED! For chrom:", refseq, "file:", filename, e)
geneMark_bed = []
geneMark_bed_bed_file = open(os.path.join(os.path.split(filename)[0], "%s.GeneMark.bed" % refseq), "wb+")
geneMark_bed_bed_file = open(os.path.join(os.path.split(filename)[0], f"{refseq}.GeneMark.bed"), "wb+")
geneMark_bed_bed_file.write("\n".join(geneMark_bed))
geneMark_bed_bed_file.close()
@@ -228,9 +228,9 @@ def __main__():
try:
os.mkdir(base_dir)
print("path '%s' has been created" % base_dir)
print(f"path '{base_dir}' has been created")
except Exception:
print("path '%s' seems to already exist" % base_dir)
print(f"path '{base_dir}' seems to already exist")
for org_num, name, chroms, kingdom, group, _, _, info_url, ftp_url in iter_genome_projects():
if chroms is None:
@@ -240,7 +240,7 @@ def __main__():
org_dir = os.path.join(base_dir, org_num)
os.mkdir(org_dir)
except Exception:
print("Organism %s already exists on disk, skipping" % org_num)
print(f"Organism {org_num} already exists on disk, skipping")
continue
# get ftp contents
@@ -254,14 +254,14 @@ def __main__():
print("Org:", org_num, "chrom:", refseq, "[", time.time() - start_time, "seconds elapsed. ]")
# Create org info file
info_file = open(os.path.join(org_dir, "%s.info" % org_num), "wb+")
info_file.write("genome project id=%s\n" % org_num)
info_file.write("name=%s\n" % name)
info_file.write("kingdom=%s\n" % kingdom)
info_file.write("group=%s\n" % group)
info_file.write("chromosomes=%s\n" % ",".join(chroms))
info_file.write("info url=%s\n" % info_url)
info_file.write("ftp url=%s\n" % ftp_url)
info_file = open(os.path.join(org_dir, f"{org_num}.info"), "wb+")
info_file.write(f"genome project id={org_num}\n")
info_file.write(f"name={name}\n")
info_file.write(f"kingdom={kingdom}\n")
info_file.write(f"group={group}\n")
info_file.write("chromosomes={}\n".format(",".join(chroms)))
info_file.write(f"info url={info_url}\n")
info_file.write(f"ftp url={ftp_url}\n")
info_file.close()
print("Finished Harvesting", "[", time.time() - start_time, "seconds elapsed. ]")
+2 -2
View File
@@ -58,11 +58,11 @@ def main(argv):
with transaction(session):
session.commit()
else:
print("Modifying revision %s." % p.id)
print(f"Modifying revision {p.id}.")
print(difflib.unified_diff(p.content, newcontent))
except Exception:
logging.exception(
"Error parsing page, rolling changes back and skipping revision %s. Please report this error." % p.id
"Error parsing page, rolling changes back and skipping revision %s. Please report this error.", p.id
)
session.rollback()
+12 -12
View File
@@ -90,7 +90,7 @@ def parse_arguments():
parser.add_argument("-M", "--max", type=int, default=-1, help="Ignore runtimes greater than MAX seconds")
parser.add_argument("-u", "--user", help="Return stats for only this user (id, email, " "or username)")
parser.add_argument(
"-s", "--source", default="metrics", help="Runtime data source (SOURCES: %s)" % ", ".join(DATA_SOURCES)
"-s", "--source", default="metrics", help="Runtime data source (SOURCES: {})".format(", ".join(DATA_SOURCES))
)
args = parser.parse_args()
@@ -144,13 +144,13 @@ def query(
if row:
user_id = row[0]
else:
print("Invalid user: %s" % user)
print(f"Invalid user: {user}")
sys.exit(1)
if like:
query_tool_id = "%%/%s/%%" % tool_id
query_tool_id = f"%/{tool_id}/%"
elif "/" in tool_id and not re.match(r"\d+\.\d+", tool_id.split("/")[-1]):
query_tool_id = "%s%%" % tool_id
query_tool_id = f"{tool_id}%"
like = True
else:
query_tool_id = tool_id
@@ -187,14 +187,14 @@ def query(
if min > 0 and max > 0:
time_clause = """WHERE ctimes[1] - ctimes[2] > interval %s
AND ctimes[1] - ctimes[2] < interval %s"""
sql_args.append("%s seconds" % min)
sql_args.append("%s seconds" % max)
sql_args.append(f"{min} seconds")
sql_args.append(f"{max} seconds")
elif min > 0:
time_clause = "WHERE ctimes[1] - ctimes[2] > interval %s"
sql_args.append("%s seconds" % min)
sql_args.append(f"{min} seconds")
elif max > 0:
time_clause = "WHERE ctimes[1] - ctimes[2] < interval %s"
sql_args.append("%s seconds" % max)
sql_args.append(f"{max} seconds")
else:
time_clause = ""
sql = HISTORY_SQL
@@ -218,7 +218,7 @@ def query(
return
if user:
print("Displaying statistics for user %s" % user)
print(f"Displaying statistics for user {user}")
stats = (
("Mean runtime", numpy.mean(times)),
@@ -229,11 +229,11 @@ def query(
for name, seconds in stats:
hours, minutes = nice_times(seconds)
msg = name + " is %0.0f seconds" % seconds
msg = name + f" is {seconds:0.0f} seconds"
if minutes:
msg += " (=%0.2f minutes)" % minutes
msg += f" (={minutes:0.2f} minutes)"
if hours:
msg += " (=%0.2f hours)" % hours
msg += f" (={hours:0.2f} hours)"
print(msg)
+2 -2
View File
@@ -62,9 +62,9 @@ def quotacheck(sa_session, users, engine, object_store):
print("none")
else:
if new > current:
print("+%s" % (nice_size(new - current)))
print(f"+{nice_size(new - current)}")
else:
print("-%s" % (nice_size(current - new)))
print(f"-{nice_size(current - new)}")
if __name__ == "__main__":
+2 -2
View File
@@ -244,10 +244,10 @@ def __inject_api_timing_summary_test(test):
continue
endpoint_summary = {"total_time": summarize_times(timings), "label": endpoint[len("api.") :]}
sql_times = "sql.%s" % endpoint
sql_times = f"sql.{endpoint}"
if sql_times in timing:
endpoint_summary["sql_time"] = summarize_times(timing[sql_times])
sql_queries = "sqlqueries.%s" % endpoint
sql_queries = f"sqlqueries.{endpoint}"
if sql_queries in counter:
endpoint_summary["sql_queries"] = summarize_counter(counter[sql_queries])
api_endpoints[endpoint] = endpoint_summary

Some files were not shown because too many files have changed in this diff Show More