Skip to content

Commit

Permalink
Enable flake8-comprehensions ruff rules
Browse files Browse the repository at this point in the history
but allow `dict()` calls that make use of keyword arguments (e.g.,
`dict(a=1, b=2)`).
  • Loading branch information
nsoranzo committed Mar 9, 2024
1 parent 9ddb6ad commit a2018a5
Show file tree
Hide file tree
Showing 110 changed files with 233 additions and 237 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/authnz/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _parse_custos_config(self, config_xml):
if config_xml.find("well_known_oidc_config_uri") is not None:
rtv["well_known_oidc_config_uri"] = config_xml.find("well_known_oidc_config_uri").text
if config_xml.findall("allowed_idp") is not None:
self.allowed_idps = list(map(lambda idp: idp.text, config_xml.findall("allowed_idp")))
self.allowed_idps = [idp.text for idp in config_xml.findall("allowed_idp")]
if config_xml.find("ca_bundle") is not None:
rtv["ca_bundle"] = config_xml.find("ca_bundle").text
if config_xml.find("icon") is not None:
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/anvio.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def generate_primary_file(self, dataset: HasExtraFilesAndMetadata) -> str:
missing_text = " (missing)"
rval.append(f'<li><a href="{composite_name}">{composite_name}</a>{opt_text}{missing_text}</li>')
rval.append("</ul>")
defined_files = map(lambda x: x[0], defined_files)
defined_files = (x[0] for x in defined_files)
extra_files = []
for dirpath, _dirnames, filenames in os.walk(dataset.extra_files_path, followlinks=True):
for filename in filenames:
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/datatypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,8 +2210,8 @@ def set_meta(self, dataset: DatasetProtocol, overwrite: bool = True, **kwd) -> N
try:
with h5py.File(dataset.get_file_name(), "r") as mat_file:
dataset.metadata.materials = list(mat_file.keys())
sgn = dict()
lp = dict()
sgn = {}
lp = {}
for m in mat_file.keys():
if "SpaceGroupNumber" in mat_file[m] and len(mat_file[m]["SpaceGroupNumber"]) > 0:
sgn[m] = mat_file[m]["SpaceGroupNumber"][0].item()
Expand Down Expand Up @@ -2401,8 +2401,8 @@ def init_meta(self, dataset: HasMetadata, copy_from: Optional[HasMetadata] = Non
def set_meta(self, dataset: DatasetProtocol, overwrite: bool = True, **kwd) -> None:
try:
tables = []
columns = dict()
rowcounts = dict()
columns = {}
rowcounts = {}
conn = sqlite.connect(dataset.get_file_name())
c = conn.cursor()
tables_query = "SELECT name,sql FROM sqlite_master WHERE type='table' ORDER BY name"
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/dataproviders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def writelines(self, sequence):
# def readline( self ):
# return self.next()
def readlines(self):
return [line for line in self]
return list(self)

# iterator interface
def __iter__(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/dataproviders/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def __iter__(self):
for i, row in enumerate(results):
if i >= self.limit:
break
yield [val for val in row]
yield list(row)
else:
yield

Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/dataproviders/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def assemble_current_block(self):
Called per block (just before providing).
"""
# empty block_lines and assemble block
return list(self.block_lines.popleft() for i in range(len(self.block_lines)))
return [self.block_lines.popleft() for i in range(len(self.block_lines))]

def filter_block(self, block):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/goldenpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
assert line[8] in ["+", "-", "?", "0", "na"]
if line[4] == "U":
assert int(line[5]) == 100
assert all(map(lambda x: str(x).isnumeric() and int(x) > 0, ostensible_numbers))
assert all(str(x).isnumeric() and int(x) > 0 for x in ostensible_numbers)
found_non_comment_lines = True
except Exception:
return False
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def _transform_dict_list_ids(dict_list):
for k, v in column["metadata"].items():
if v is not None:
keep_columns.add(k)
final_list = sorted(list(keep_columns))
final_list = sorted(keep_columns)
dataset.metadata.table_column_metadata_headers = final_list
if b_name in b_transform:
metadata_value = b_transform[b_name](metadata_value)
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/datatypes/util/maf_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_sequence(self, species):

# returns the reverse complement of the sequence for a species
def get_sequence_reverse_complement(self, species):
complement = [base for base in self.get_sequence(species).translate(self.DNA_COMPLEMENT)]
complement = list(self.get_sequence(species).translate(self.DNA_COMPLEMENT))
complement.reverse()
return "".join(complement)

Expand Down Expand Up @@ -274,7 +274,7 @@ def get_sequence(self, species):

# returns the reverse complement of the sequence for a species
def get_sequence_reverse_complement(self, species):
complement = [base for base in self.get_sequence(species).translate(self.DNA_COMPLEMENT)]
complement = list(self.get_sequence(species).translate(self.DNA_COMPLEMENT))
complement.reverse()
return "".join(complement)

Expand Down Expand Up @@ -683,7 +683,7 @@ def iter_components_by_src(block, src):


def get_components_by_src(block, src):
return [value for value in iter_components_by_src(block, src)]
return list(iter_components_by_src(block, src))


def iter_components_by_src_start(block, src):
Expand All @@ -693,7 +693,7 @@ def iter_components_by_src_start(block, src):


def get_components_by_src_start(block, src):
return [value for value in iter_components_by_src_start(block, src)]
return list(iter_components_by_src_start(block, src))


def sort_block_components_by_block(block1, block2):
Expand Down
14 changes: 7 additions & 7 deletions lib/galaxy/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, **kwds):
self["env"] = []
self["resubmit"] = []
# dict is appropriate (rather than a bunch) since keys may not be valid as attributes
self["params"] = dict()
self["params"] = {}

# Use the values persisted in an existing job
if "from_job" in kwds and kwds["from_job"].destination_id is not None:
Expand All @@ -143,7 +143,7 @@ class JobToolConfiguration(Bunch):
def __init__(self, **kwds):
self["handler"] = None
self["destination"] = None
self["params"] = dict()
self["params"] = {}
super().__init__(**kwds)

def get_resource_group(self):
Expand Down Expand Up @@ -448,7 +448,7 @@ def _configure_from_dict(self, job_config_dict):
execution_dict = job_config_dict.get("execution", {})
environments = execution_dict.get("environments", [])
enviroment_iter = (
map(lambda e: (e["id"], e), environments) if isinstance(environments, list) else environments.items()
((e["id"], e) for e in environments) if isinstance(environments, list) else environments.items()
)
for environment_id, environment_dict in enviroment_iter:
metrics = environment_dict.get("metrics")
Expand Down Expand Up @@ -520,11 +520,11 @@ def _configure_from_dict(self, job_config_dict):
assert tool_class is None
tool_id = raw_tool_id.lower().rstrip("/")
if tool_id not in self.tools:
self.tools[tool_id] = list()
self.tools[tool_id] = []
else:
assert tool_class in VALID_TOOL_CLASSES, tool_class
if tool_class not in self.tool_classes:
self.tool_classes[tool_class] = list()
self.tool_classes[tool_class] = []

params = tool.get("params")
if params is None:
Expand Down Expand Up @@ -663,7 +663,7 @@ def get_params(config, parent):
key = param.get("id")
if key in ["container", "container_override"]:
containers = map(requirements.container_from_element, param.findall("container"))
param_value = list(map(lambda c: c.to_dict(), containers))
param_value = [c.to_dict() for c in containers]
else:
param_value = param.text

Expand Down Expand Up @@ -2273,7 +2273,7 @@ def setup_external_metadata(
if set_extension:
for output_dataset_assoc in job.output_datasets:
if output_dataset_assoc.dataset.ext == "auto":
context = self.get_dataset_finish_context(dict(), output_dataset_assoc)
context = self.get_dataset_finish_context({}, output_dataset_assoc)
output_dataset_assoc.dataset.extension = context.get("ext", "data")
with transaction(self.sa_session):
self.sa_session.commit()
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/jobs/runners/condor.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def stop_job(self, job_wrapper):
try:
log.info(f"stop_job(): {job.id}: trying to stop container .... ({external_id})")
# self.watched = [cjs for cjs in self.watched if cjs.job_id != external_id]
new_watch_list = list()
new_watch_list = []
cjs = None
for tcjs in self.watched:
if tcjs.job_id != external_id:
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/jobs/runners/drmaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, app, nworkers, **kwargs):
runner_param_specs[f"{retry_exception}_retries"] = dict(map=int, valid=lambda x: int(x) >= 0, default=0)

if "runner_param_specs" not in kwargs:
kwargs["runner_param_specs"] = dict()
kwargs["runner_param_specs"] = {}
kwargs["runner_param_specs"].update(runner_param_specs)

super().__init__(app, nworkers, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/jobs/runners/godocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(self, app, nworkers, **kwargs):
godocker_master=dict(map=str), user=dict(map=str), key=dict(map=str), godocker_project=dict(map=str)
)
if "runner_param_specs" not in kwargs:
kwargs["runner_param_specs"] = dict()
kwargs["runner_param_specs"] = {}
kwargs["runner_param_specs"].update(runner_param_specs)

# Start the job runner parent object
Expand Down Expand Up @@ -379,7 +379,7 @@ def post_task(self, job_wrapper):
volume = job_destination.params["godocker_volumes"]
volume = volume.split(",")
for i in volume:
temp = dict({"name": i})
temp = {"name": i}
volumes.append(temp)
except Exception:
log.debug("godocker_volume not set, using default.")
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/jobs/runners/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, app, nworkers, **kwargs):
)

if "runner_param_specs" not in kwargs:
kwargs["runner_param_specs"] = dict()
kwargs["runner_param_specs"] = {}
kwargs["runner_param_specs"].update(runner_param_specs)

# Start the job runner parent object
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/jobs/runners/univa.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def check_watched_item(self, ajs, new_watched):
return state

def _complete_terminal_job(self, ajs, drmaa_state, **kwargs):
extinfo = dict()
extinfo = {}
# get state with job_info/qstat + wait/qacct
state = self._get_drmaa_state(ajs.job_id, self.ds, True, extinfo)
# log.debug("UnivaJobRunner:_complete_terminal_job ({jobid}) -> state {state} info {info}".format(jobid=ajs.job_id, state=self.drmaa_job_state_strings[state], info=extinfo))
Expand Down Expand Up @@ -214,7 +214,7 @@ def _get_drmaa_state_qacct(self, job_id, extinfo):
# log.debug("UnivaJobRunner._get_drmaa_state_qacct ({jobid})".format(jobid=job_id))
signals = {
k: v
for v, k in reversed(sorted(signal.__dict__.items()))
for v, k in sorted(signal.__dict__.items(), reverse=True)
if v.startswith("SIG") and not v.startswith("SIG_")
}
cmd = ["qacct", "-j", job_id]
Expand All @@ -235,7 +235,7 @@ def _get_drmaa_state_qacct(self, job_id, extinfo):
return self.drmaa.JobState.UNDETERMINED
else:
break
qacct = dict()
qacct = {}
for line in stdout.split("\n"):
# remove header
if line.startswith("=") or line == "":
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def get_converters_for_collection(
suitable_converters = suitable_converters.intersection(set_of_new_converters)
if suitable_converters:
most_recent_datatype = datatype
suitable_tool_ids = list()
suitable_tool_ids = []
for tool in suitable_converters:
tool_info = {
"tool_id": tool[1].id,
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def view_index(
if upload_only:
return datatypes_registry.upload_file_formats
else:
return [ext for ext in datatypes_registry.datatypes_by_extension]
return list(datatypes_registry.datatypes_by_extension)
else:
rval = []
for datatype_info_dict in datatypes_registry.datatype_info_dicts:
Expand Down
4 changes: 1 addition & 3 deletions lib/galaxy/managers/history_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ def _union_of_contents(self, container, expand_models=True, **kwargs):
return contents_results

# partition ids into a map of { component_class names -> list of ids } from the above union query
id_map: Dict[str, List[int]] = dict(
[(self.contained_class_type_name, []), (self.subcontainer_class_type_name, [])]
)
id_map: Dict[str, List[int]] = {self.contained_class_type_name: [], self.subcontainer_class_type_name: []}
for result in contents_results:
result_type = self._get_union_type(result)
contents_id = self._get_union_id(result)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def list(self, trans, deleted: Optional[bool] = False) -> Tuple[Query, Dict[str,
"""
is_admin = trans.user_is_admin
library_access_action = trans.app.security_agent.permitted_actions.LIBRARY_ACCESS.action
restricted_library_ids = {id for id in get_library_ids(trans.sa_session, library_access_action)}
restricted_library_ids = set(get_library_ids(trans.sa_session, library_access_action))
prefetched_ids = {"restricted_library_ids": restricted_library_ids}

if is_admin:
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def user_can_do_run_as(self, user) -> bool:

# ---- preferences
def preferences(self, user):
return {key: value for key, value in user.preferences.items()}
return dict(user.preferences.items())

# ---- roles and permissions
def private_role(self, user):
Expand Down
12 changes: 6 additions & 6 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,7 @@ class FakeDatasetAssociation:

def __init__(self, dataset=None):
self.dataset = dataset
self.metadata = dict()
self.metadata = {}

def get_file_name(self, sync_cache=True):
return self.dataset.get_file_name(sync_cache)
Expand Down Expand Up @@ -4255,8 +4255,8 @@ def to_int(n) -> Optional[int]:
total_size=to_int(self.total_size),
created_from_basename=self.created_from_basename,
uuid=str(self.uuid or "") or None,
hashes=list(map(lambda h: h.serialize(id_encoder, serialization_options), self.hashes)),
sources=list(map(lambda s: s.serialize(id_encoder, serialization_options), self.sources)),
hashes=[h.serialize(id_encoder, serialization_options) for h in self.hashes],
sources=[s.serialize(id_encoder, serialization_options) for s in self.sources],
)
serialization_options.attach_identifier(id_encoder, self, rval)
return rval
Expand Down Expand Up @@ -4418,7 +4418,7 @@ def __init__(
self.designation = designation
# set private variable to None here, since the attribute may be needed in by MetadataCollection.__init__
self._metadata = None
self.metadata = metadata or dict()
self.metadata = metadata or {}
self.metadata_deferred = metadata_deferred
self.extended_metadata = extended_metadata
if (
Expand Down Expand Up @@ -6585,7 +6585,7 @@ def _serialize(self, id_encoder, serialization_options):
type=self.collection_type,
populated_state=self.populated_state,
populated_state_message=self.populated_state_message,
elements=list(map(lambda e: e.serialize(id_encoder, serialization_options), self.elements)),
elements=[e.serialize(id_encoder, serialization_options) for e in self.elements],
)
serialization_options.attach_identifier(id_encoder, self, rval)
return rval
Expand Down Expand Up @@ -8507,7 +8507,7 @@ def poll_unhandled_workflow_ids(sa_session):
.where(WorkflowInvocation.handler.is_(None))
.order_by(WorkflowInvocation.id.asc())
)
return [wid for wid in sa_session.scalars(stmt)]
return list(sa_session.scalars(stmt))

@staticmethod
def poll_active_workflow_ids(engine, scheduler=None, handler=None):
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/model/dataset_collections/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def clone(self):
return Tree(cloned_children, self.collection_type_description)

def __str__(self):
return f"Tree[collection_type={self.collection_type_description},children={','.join(map(lambda identifier_and_element: f'{identifier_and_element[0]}={identifier_and_element[1]}', self.children))}]"
return f"Tree[collection_type={self.collection_type_description},children={','.join(f'{identifier_and_element[0]}={identifier_and_element[1]}' for identifier_and_element in self.children)}]"


def tool_output_to_structure(get_sliced_input_collection_structure, tool_output, collections_manager):
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/model/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_all_roles(self, trans, cntrller):
# Add all remaining non-private, non-sharing roles
for role in self._get_npns_roles(trans):
roles.add(role)
return self.sort_by_attr([role for role in roles], "name")
return self.sort_by_attr(list(roles), "name")

def get_roles_for_action(self, item, action):
"""
Expand Down Expand Up @@ -218,7 +218,7 @@ def get_valid_roles(self, trans, item, query=None, page=None, page_limit=None, i
return_roles = set(roles)
if total_count is None:
total_count = len(return_roles)
return self.sort_by_attr([role for role in return_roles], "name"), total_count
return self.sort_by_attr(list(return_roles), "name"), total_count

def get_legitimate_roles(self, trans, item, cntrller):
"""
Expand Down Expand Up @@ -269,7 +269,7 @@ def get_legitimate_roles(self, trans, item, cntrller):
for ura in user.roles:
if admin_controller or self.ok_to_display(trans.user, ura.role):
roles.add(ura.role)
return self.sort_by_attr([role for role in roles], "name")
return self.sort_by_attr(list(roles), "name")

def ok_to_display(self, user, role):
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/model/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def parse_tags(self, tag_str):
"""
# Gracefully handle None.
if not tag_str:
return dict()
return {}
# Strip unicode control characters
tag_str = strip_control_characters(tag_str)
# Split tags based on separators.
Expand Down Expand Up @@ -423,7 +423,7 @@ def _scrub_tag_name(self, name):

def _scrub_tag_name_list(self, tag_name_list):
"""Scrub a tag name list."""
scrubbed_tag_list = list()
scrubbed_tag_list = []
for tag in tag_name_list:
scrubbed_tag_list.append(self._scrub_tag_name(tag))
return scrubbed_tag_list
Expand Down
Loading

0 comments on commit a2018a5

Please sign in to comment.