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

Upgrade syntax to Python 3.7 #13500

Merged
merged 1 commit into from
Mar 14, 2022
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
4 changes: 2 additions & 2 deletions config/plugins/webhooks/demo/tour_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _generate_tour(self):
if name in test_inputs:
hid = self._hids[name]
dataset = self._test.inputs[name][0]
step["content"] = "Select dataset: <b>{}: {}</b>".format(hid, dataset)
step["content"] = f"Select dataset: <b>{hid}: {dataset}</b>"
else:
step["content"] = "Select a dataset"

Expand Down Expand Up @@ -192,7 +192,7 @@ def _generate_tour(self):
if case_id in self._data_inputs.keys():
hid = self._hids[case_id]
dataset = self._test.inputs[tour_id][0]
step_msg = "Select dataset: <b>%s: %s</b>" % (hid, dataset)
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
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/containers/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def node_ps(self, node_id):
def node_update(self, node_id, **kwopts):
return self._run_docker(
subcommand="node update",
args="{kwopts} {node_id}".format(kwopts=self._stringify_kwopts(kwopts), node_id=node_id),
args=f"{self._stringify_kwopts(kwopts)} {node_id}",
)

@docker_json
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/blast.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def merge(split_files, output_file):
# For one file only, use base class method (move/copy)
return Text.merge(split_files, output_file)
if not split_files:
raise ValueError("Given no BLAST XML files, %r, to merge into %s" % (split_files, output_file))
raise ValueError(f"Given no BLAST XML files, {split_files!r}, to merge into {output_file}")
nsoranzo marked this conversation as resolved.
Show resolved Hide resolved
with open(output_file, "w") as out:
h = None
old_header = None
Expand Down
17 changes: 7 additions & 10 deletions lib/galaxy/datatypes/goldenpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _read_file(self):

line_number = 0
in_body = False
with open(self.fname, "r") as f:
with open(self.fname) as f:
for line in f:
line_number += 1
line = line.rstrip("\n")
Expand Down Expand Up @@ -217,14 +217,12 @@ def num_lines(self):

def iterate_objs(self):
"""Iterate over the objects of the AGP file."""
for obj in self._objects:
yield obj
yield from self._objects

def iterate_lines(self):
"""Iterate over the non-comment lines of AGP file."""
for obj in self.iterate_objs():
for j in obj.iterate_lines():
yield j
yield from obj.iterate_lines()


class AGPObject:
Expand Down Expand Up @@ -302,11 +300,10 @@ def add_line(self, agp_line):
self._agp_lines.append(agp_line)

def iterate_lines(self):
for i in self._agp_lines:
yield i
yield from self._agp_lines


class AGPLine(object, metaclass=abc.ABCMeta):
class AGPLine(metaclass=abc.ABCMeta):
"""
An abstract base class representing a single AGP file line. Inheriting subclasses should
override or implement new methods to check the validity of a single AFP line. Validity
Expand Down Expand Up @@ -388,7 +385,7 @@ def __init__(
self.orientation = orientation

# Set the object attributes and perform superclass-defined validations
super(AGPSeqLine, self).__init__(fname, line_number, obj, obj_beg, obj_end, pid, comp_type)
super().__init__(fname, line_number, obj, obj_beg, obj_end, pid, comp_type)

self.is_gap = False
self.seqdict = dict(
Expand Down Expand Up @@ -509,7 +506,7 @@ def __init__(
self.linkage_evidence = linkage_evidence

# Set the object attributes and perform superclass-defined validations
super(AGPGapLine, self).__init__(fname, line_number, obj, obj_beg, obj_end, pid, comp_type)
super().__init__(fname, line_number, obj, obj_beg, obj_end, pid, comp_type)

self.is_gap = True
self.gapdict = dict(
Expand Down
8 changes: 3 additions & 5 deletions lib/galaxy/datatypes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ def ucsc_links(self, dataset, type, app, base_url):
"%s%s/display_as?id=%i&display_app=%s&authz_method=display_at"
% (base_url, app.url_for(controller="root"), dataset.id, type)
)
redirect_url = quote_plus(
"%sdb=%s&position=%s:%s-%s&hgt.customText=%%s" % (site_url, dataset.dbkey, chrom, start, stop)
)
redirect_url = quote_plus(f"{site_url}db={dataset.dbkey}&position={chrom}:{start}-{stop}&hgt.customText=%s")
link = f"{internal_url}?redirect_url={redirect_url}&display_url={display_url}"
ret_val.append((site_name, link))
return ret_val
Expand Down Expand Up @@ -884,7 +882,7 @@ def get_estimated_display_viewport(self, dataset):
stop = int(elems[1].split("..")[1])
break # use location declared in file
else:
log.debug(f"line ({str(line)}) uses an unsupported ##sequence-region definition.")
log.debug(f"line ({line}) uses an unsupported ##sequence-region definition.")
# break #no break, if bad definition, we try another line
elif line.startswith("browser position"):
# Allow UCSC style browser and track info in the GFF file
Expand Down Expand Up @@ -933,7 +931,7 @@ def ucsc_links(self, dataset, type, app, base_url):
for site_name, site_url in app.datatypes_registry.get_legacy_sites_by_build("ucsc", dataset.dbkey):
if site_name in app.datatypes_registry.get_display_sites("ucsc"):
redirect_url = quote_plus(
"%sdb=%s&position=%s:%s-%s&hgt.customText=%%s" % (site_url, dataset.dbkey, seqid, start, stop)
f"{site_url}db={dataset.dbkey}&position={seqid}:{start}-{stop}&hgt.customText=%s"
)
link = self._get_remote_call_url(redirect_url, site_name, dataset, type, app, base_url)
ret_val.append((site_name, link))
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/datatypes/molecules.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def merge(split_files, output_file):
# For one file only, use base class method (move/copy)
return Text.merge(split_files, output_file)
if not split_files:
raise ValueError("No fps files given, %r, to merge into %s" % (split_files, output_file))
raise ValueError(f"No fps files given, {split_files!r}, to merge into {output_file}")
with open(output_file, "w") as out:
first = True
for filename in split_files:
Expand Down Expand Up @@ -682,7 +682,7 @@ def set_peek(self, dataset):
hetatm_numbers = count_special_lines("^HETATM", dataset.file_name)
chain_ids = ",".join(dataset.metadata.chain_ids) if len(dataset.metadata.chain_ids) > 0 else "None"
dataset.peek = get_file_peek(dataset.file_name)
dataset.blurb = f"{atom_numbers} atoms and {hetatm_numbers} HET-atoms\nchain_ids: {str(chain_ids)}"
dataset.blurb = f"{atom_numbers} atoms and {hetatm_numbers} HET-atoms\nchain_ids: {chain_ids}"
else:
dataset.peek = "file does not exist"
dataset.blurb = "file purged from disk"
Expand Down Expand Up @@ -940,7 +940,7 @@ def merge(split_files, output_file):
# For one file only, use base class method (move/copy)
return Text.merge(split_files, output_file)
if not split_files:
raise ValueError("Given no CML files, %r, to merge into %s" % (split_files, output_file))
raise ValueError(f"Given no CML files, {split_files!r}, to merge into {output_file}")
with open(output_file, "w") as out:
for filename in split_files:
with open(filename) as handle:
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def generate_primary_file(self, dataset=None):
opt_text = ""
if composite_file.optional:
opt_text = " (optional)"
rval.append('<li><a href="%s">%s</a>%s' % (composite_name, composite_name, opt_text))
rval.append(f'<li><a href="{composite_name}">{composite_name}</a>{opt_text}')
rval.append("</ul></html>")
return "\n".join(rval)

Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/datatypes/spaln.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def generate_primary_file(self, dataset=None):
% (fn, fn, composite_file.get("description"), opt_text)
)
else:
rval.append('<li><a href="%s" type="application/binary">%s</a>%s</li>' % (fn, fn, opt_text))
rval.append(f'<li><a href="{fn}" type="application/binary">{fn}</a>{opt_text}</li>')
rval.append("</ul></div></html>")
return "\n".join(rval)

Expand Down Expand Up @@ -141,7 +141,7 @@ def display_data(self, trans, data, preview=False, filename=None, to_ext=None, s
msg = title
# Galaxy assumes HTML for the display of composite datatypes,
return (
smart_str("<html><head><title>%s</title></head><body><pre>%s</pre></body></html>" % (title, msg)),
smart_str(f"<html><head><title>{title}</title></head><body><pre>{msg}</pre></body></html>"),
headers,
)

Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/util/gff_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(
for interval in self.intervals:
# Error checking. NOTE: intervals need not share the same strand.
if interval.chrom != self.chrom:
raise ValueError("interval chrom does not match self chrom: %s != %s" % (interval.chrom, self.chrom))
raise ValueError(f"interval chrom does not match self chrom: {interval.chrom} != {self.chrom}")
# Set start, end of interval.
if interval.start < self.start:
self.start = interval.start
Expand Down
10 changes: 4 additions & 6 deletions lib/galaxy/managers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,10 @@ def get_object(trans, id, class_name, check_ownership=False, check_accessible=Fa
security_check(trans, item, check_ownership, check_accessible)
if deleted is True and not item.deleted:
raise exceptions.ItemDeletionException(
'%s "%s" is not deleted' % (class_name, getattr(item, "name", id)), type="warning"
f'{class_name} "{getattr(item, "name", id)}" is not deleted', type="warning"
)
elif deleted is False and item.deleted:
raise exceptions.ItemDeletionException(
'%s "%s" is deleted' % (class_name, getattr(item, "name", id)), type="warning"
)
raise exceptions.ItemDeletionException(f'{class_name} "{getattr(item, "name", id)}" is deleted', type="warning")
return item


Expand Down Expand Up @@ -799,7 +797,7 @@ def matches_type(key: str, val: Any, types: Union[type, Tuple[Union[type, Tuple[
:raises exceptions.RequestParameterInvalidException: if not an instance.
"""
if not isinstance(val, types):
msg = f"must be a type: {str(types)}"
msg = f"must be a type: {types}"
raise exceptions.RequestParameterInvalidException(msg, key=key, val=val)
return val

Expand Down Expand Up @@ -1258,7 +1256,7 @@ def parse_bool(bool_string: Union[str, bool]) -> bool:
return True
if bool_string in ("False", False):
return False
raise ValueError(f"invalid boolean: {str(bool_string)}")
raise ValueError(f"invalid boolean: {bool_string}")


def raise_filter_err(attr, op, val, msg):
Expand Down
8 changes: 3 additions & 5 deletions lib/galaxy/objectstore/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def _empty(self, obj, **kwargs):
if self._exists(obj, **kwargs):
return bool(self._size(obj, **kwargs) > 0)
else:
raise ObjectNotFound("objectstore.empty, object does not exist: %s, kwargs: %s" % (str(obj), str(kwargs)))
raise ObjectNotFound(f"objectstore.empty, object does not exist: {obj}, kwargs: {kwargs}")

def _size(self, obj, **kwargs):
rel_path = self._construct_path(obj, **kwargs)
Expand Down Expand Up @@ -711,7 +711,7 @@ def _get_filename(self, obj, **kwargs):
# even if it does not exist.
# if dir_only:
# return cache_path
raise ObjectNotFound("objectstore.get_filename, no cache_path: %s, kwargs: %s" % (str(obj), str(kwargs)))
raise ObjectNotFound(f"objectstore.get_filename, no cache_path: {obj}, kwargs: {kwargs}")
# return cache_path # Until the upload tool does not explicitly create the dataset, return expected path

def _update_from_file(self, obj, file_name=None, create=False, **kwargs):
Expand All @@ -736,9 +736,7 @@ def _update_from_file(self, obj, file_name=None, create=False, **kwargs):
# Update the file on cloud
self._push_to_os(rel_path, source_file)
else:
raise ObjectNotFound(
"objectstore.update_from_file, object does not exist: %s, kwargs: %s" % (str(obj), str(kwargs))
)
raise ObjectNotFound(f"objectstore.update_from_file, object does not exist: {obj}, kwargs: {kwargs}")

def _get_object_url(self, obj, **kwargs):
if self._exists(obj, **kwargs):
Expand Down
34 changes: 16 additions & 18 deletions lib/galaxy/objectstore/irods.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ def _get_size_in_irods(self, rel_path):
data_object_name = p.stem + p.suffix
subcollection_name = p.parent

collection_path = f"{self.home}/{str(subcollection_name)}"
data_object_path = f"{collection_path}/{str(data_object_name)}"
collection_path = f"{self.home}/{subcollection_name}"
data_object_path = f"{collection_path}/{data_object_name}"
options = {kw.DEST_RESC_NAME_KW: self.resource}

try:
Expand All @@ -334,8 +334,8 @@ def _data_object_exists(self, rel_path):
data_object_name = p.stem + p.suffix
subcollection_name = p.parent

collection_path = f"{self.home}/{str(subcollection_name)}"
data_object_path = f"{collection_path}/{str(data_object_name)}"
collection_path = f"{self.home}/{subcollection_name}"
data_object_path = f"{collection_path}/{data_object_name}"
options = {kw.DEST_RESC_NAME_KW: self.resource}

try:
Expand Down Expand Up @@ -372,8 +372,8 @@ def _download(self, rel_path):
data_object_name = p.stem + p.suffix
subcollection_name = p.parent

collection_path = f"{self.home}/{str(subcollection_name)}"
data_object_path = f"{collection_path}/{str(data_object_name)}"
collection_path = f"{self.home}/{subcollection_name}"
data_object_path = f"{collection_path}/{data_object_name}"
options = {kw.DEST_RESC_NAME_KW: self.resource}

try:
Expand Down Expand Up @@ -411,8 +411,8 @@ def _push_to_irods(self, rel_path, source_file=None, from_string=None):
return False

# Check if the data object exists in iRODS
collection_path = f"{self.home}/{str(subcollection_name)}"
data_object_path = f"{collection_path}/{str(data_object_name)}"
collection_path = f"{self.home}/{subcollection_name}"
data_object_path = f"{collection_path}/{data_object_name}"
exists = False

try:
Expand Down Expand Up @@ -542,7 +542,7 @@ def _empty(self, obj, **kwargs):
if self._exists(obj, **kwargs):
return bool(self._size(obj, **kwargs) > 0)
else:
raise ObjectNotFound("objectstore.empty, object does not exist: %s, kwargs: %s" % (str(obj), str(kwargs)))
raise ObjectNotFound(f"objectstore.empty, object does not exist: {obj}, kwargs: {kwargs}")

def _size(self, obj, **kwargs):
ipt_timer = ExecutionTimer()
Expand Down Expand Up @@ -584,7 +584,7 @@ def _delete(self, obj, entire_dir=False, **kwargs):
if entire_dir and extra_dir:
shutil.rmtree(self._get_cache_path(rel_path), ignore_errors=True)

col_path = f"{self.home}/{str(rel_path)}"
col_path = f"{self.home}/{rel_path}"
col = None
try:
col = self.session.collections.get(col_path)
Expand Down Expand Up @@ -612,8 +612,8 @@ def _delete(self, obj, entire_dir=False, **kwargs):
data_object_name = p.stem + p.suffix
subcollection_name = p.parent

collection_path = f"{self.home}/{str(subcollection_name)}"
data_object_path = f"{collection_path}/{str(data_object_name)}"
collection_path = f"{self.home}/{subcollection_name}"
data_object_path = f"{collection_path}/{data_object_name}"

try:
data_obj = self.session.data_objects.get(data_object_path, **options)
Expand Down Expand Up @@ -682,7 +682,7 @@ def _get_filename(self, obj, **kwargs):
# if dir_only:
# return cache_path
log.debug("irods_pt _get_filename: %s", ipt_timer)
raise ObjectNotFound("objectstore.get_filename, no cache_path: %s, kwargs: %s" % (str(obj), str(kwargs)))
raise ObjectNotFound(f"objectstore.get_filename, no cache_path: {obj}, kwargs: {kwargs}")
# return cache_path # Until the upload tool does not explicitly create the dataset, return expected path

def _update_from_file(self, obj, file_name=None, create=False, **kwargs):
Expand All @@ -709,9 +709,7 @@ def _update_from_file(self, obj, file_name=None, create=False, **kwargs):
self._push_to_irods(rel_path, source_file)
else:
log.debug("irods_pt _update_from_file: %s", ipt_timer)
raise ObjectNotFound(
"objectstore.update_from_file, object does not exist: %s, kwargs: %s" % (str(obj), str(kwargs))
)
raise ObjectNotFound(f"objectstore.update_from_file, object does not exist: {obj}, kwargs: {kwargs}")
log.debug("irods_pt _update_from_file: %s", ipt_timer)

# Unlike S3, url is not really applicable to iRODS
Expand All @@ -723,8 +721,8 @@ def _get_object_url(self, obj, **kwargs):
data_object_name = p.stem + p.suffix
subcollection_name = p.parent

collection_path = f"{self.home}/{str(subcollection_name)}"
data_object_path = f"{collection_path}/{str(data_object_name)}"
collection_path = f"{self.home}/{subcollection_name}"
data_object_path = f"{collection_path}/{data_object_name}"

return data_object_path

Expand Down
8 changes: 3 additions & 5 deletions lib/galaxy/objectstore/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def _empty(self, obj, **kwargs):
if self._exists(obj, **kwargs):
return bool(self._size(obj, **kwargs) > 0)
else:
raise ObjectNotFound("objectstore.empty, object does not exist: %s, kwargs: %s" % (str(obj), str(kwargs)))
raise ObjectNotFound(f"objectstore.empty, object does not exist: {obj}, kwargs: {kwargs}")

def _size(self, obj, **kwargs):
rel_path = self._construct_path(obj, **kwargs)
Expand Down Expand Up @@ -723,7 +723,7 @@ def _get_filename(self, obj, **kwargs):
# even if it does not exist.
# if dir_only:
# return cache_path
raise ObjectNotFound("objectstore.get_filename, no cache_path: %s, kwargs: %s" % (str(obj), str(kwargs)))
raise ObjectNotFound(f"objectstore.get_filename, no cache_path: {obj}, kwargs: {kwargs}")
# return cache_path # Until the upload tool does not explicitly create the dataset, return expected path

def _update_from_file(self, obj, file_name=None, create=False, **kwargs):
Expand All @@ -748,9 +748,7 @@ def _update_from_file(self, obj, file_name=None, create=False, **kwargs):
# Update the file on S3
self._push_to_os(rel_path, source_file)
else:
raise ObjectNotFound(
"objectstore.update_from_file, object does not exist: %s, kwargs: %s" % (str(obj), str(kwargs))
)
raise ObjectNotFound(f"objectstore.update_from_file, object does not exist: {obj}, kwargs: {kwargs}")

def _get_object_url(self, obj, **kwargs):
if self._exists(obj, **kwargs):
Expand Down
4 changes: 1 addition & 3 deletions lib/galaxy/queue_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ def admin_job_lock(app, **kwargs):
# job_queue is exposed in the root app, but this will be 'fixed' at some
# point, so we're using the reference from the handler.
app.job_manager.job_lock = job_lock
log.info(
"Administrative Job Lock is now set to %s. Jobs will %s dispatch." % (job_lock, "not" if job_lock else "now")
)
log.info(f"Administrative Job Lock is now set to {job_lock}. Jobs will {'not' if job_lock else 'now'} dispatch.")


control_message_to_task = {
Expand Down
Loading