diff --git a/Makefile b/Makefile index 15e90641d751..7b413259b3c7 100644 --- a/Makefile +++ b/Makefile @@ -53,9 +53,9 @@ remove-unused-imports: ## Remove unused imports in Python code base $(IN_VENV) autoflake --in-place --remove-all-unused-imports --recursive --verbose lib/ test/ pyupgrade: ## Convert older code patterns to Python3.7/3.8 idiomatic ones - ack --type=python -f | grep -v '^lib/galaxy/schema/bco/\|^lib/galaxy/schema/drs/\|^lib/tool_shed_client/schema/trs\|^tools/\|^.venv/\|^.tox/\|^lib/galaxy/files/sources/\|^lib/galaxy/job_metrics/\|^lib/galaxy/objectstore/\|^lib/galaxy/tool_util/\|^lib/galaxy/util/\|^test/functional/tools/cwl_tools/' | xargs pyupgrade --py38-plus - ack --type=python -f | grep -v '^lib/galaxy/schema/bco/\|^lib/galaxy/schema/drs/\|^lib/tool_shed_client/schema/trs\|^tools/\|^.venv/\|^.tox/\|^lib/galaxy/files/sources/\|^lib/galaxy/job_metrics/\|^lib/galaxy/objectstore/\|^lib/galaxy/tool_util/\|^lib/galaxy/util/\|^test/functional/tools/cwl_tools/' | xargs auto-walrus - ack --type=python -f lib/galaxy/files/sources/ lib/galaxy/job_metrics/ lib/galaxy/objectstore/ lib/galaxy/tool_util/ lib/galaxy/util/ | xargs pyupgrade --py37-plus + ack --type=python -f | grep -v '^lib/galaxy/schema/bco/\|^lib/galaxy/schema/drs/\|^lib/tool_shed_client/schema/trs\|^tools/\|^.venv/\|^.tox/\|^lib/galaxy/exceptions/\|^lib/galaxy/job_metrics/\|^lib/galaxy/objectstore/\|^lib/galaxy/tool_util/\|^lib/galaxy/util/\|^test/functional/tools/cwl_tools/' | xargs pyupgrade --py38-plus + ack --type=python -f | grep -v '^lib/galaxy/schema/bco/\|^lib/galaxy/schema/drs/\|^lib/tool_shed_client/schema/trs\|^tools/\|^.venv/\|^.tox/\|^lib/galaxy/exceptions/\|^lib/galaxy/job_metrics/\|^lib/galaxy/objectstore/\|^lib/galaxy/tool_util/\|^lib/galaxy/util/\|^test/functional/tools/cwl_tools/' | xargs auto-walrus + ack --type=python -f lib/galaxy/exceptions/ lib/galaxy/job_metrics/ lib/galaxy/objectstore/ lib/galaxy/tool_util/ lib/galaxy/util/ | xargs pyupgrade --py37-plus docs-slides-ready: test -f plantuml.jar || wget http://jaist.dl.sourceforge.net/project/plantuml/plantuml.jar diff --git a/lib/galaxy/authnz/managers.py b/lib/galaxy/authnz/managers.py index 6b526643162e..3fca049269fc 100644 --- a/lib/galaxy/authnz/managers.py +++ b/lib/galaxy/authnz/managers.py @@ -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: diff --git a/lib/galaxy/datatypes/anvio.py b/lib/galaxy/datatypes/anvio.py index a6feff14af5c..e89e3db59edd 100644 --- a/lib/galaxy/datatypes/anvio.py +++ b/lib/galaxy/datatypes/anvio.py @@ -45,7 +45,7 @@ def generate_primary_file(self, dataset: HasExtraFilesAndMetadata) -> str: missing_text = " (missing)" rval.append(f'
  • {composite_name}{opt_text}{missing_text}
  • ') rval.append("") - 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: diff --git a/lib/galaxy/datatypes/binary.py b/lib/galaxy/datatypes/binary.py index de92e2a165dc..de47ca2548ae 100644 --- a/lib/galaxy/datatypes/binary.py +++ b/lib/galaxy/datatypes/binary.py @@ -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() @@ -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" diff --git a/lib/galaxy/datatypes/dataproviders/base.py b/lib/galaxy/datatypes/dataproviders/base.py index 30f02eea525c..c1239f86b9ff 100644 --- a/lib/galaxy/datatypes/dataproviders/base.py +++ b/lib/galaxy/datatypes/dataproviders/base.py @@ -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): diff --git a/lib/galaxy/datatypes/dataproviders/dataset.py b/lib/galaxy/datatypes/dataproviders/dataset.py index dfce2edef527..6c8075835393 100644 --- a/lib/galaxy/datatypes/dataproviders/dataset.py +++ b/lib/galaxy/datatypes/dataproviders/dataset.py @@ -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 diff --git a/lib/galaxy/datatypes/dataproviders/line.py b/lib/galaxy/datatypes/dataproviders/line.py index d47215b58382..ac2dc3a51f3a 100644 --- a/lib/galaxy/datatypes/dataproviders/line.py +++ b/lib/galaxy/datatypes/dataproviders/line.py @@ -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): """ diff --git a/lib/galaxy/datatypes/goldenpath.py b/lib/galaxy/datatypes/goldenpath.py index 94ce38b547bd..9ce878714a69 100644 --- a/lib/galaxy/datatypes/goldenpath.py +++ b/lib/galaxy/datatypes/goldenpath.py @@ -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 diff --git a/lib/galaxy/datatypes/text.py b/lib/galaxy/datatypes/text.py index 54a8f28aa4b9..95fa625aa789 100644 --- a/lib/galaxy/datatypes/text.py +++ b/lib/galaxy/datatypes/text.py @@ -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) diff --git a/lib/galaxy/datatypes/util/maf_utilities.py b/lib/galaxy/datatypes/util/maf_utilities.py index 52c18931c3c9..8ed6f1670c5b 100644 --- a/lib/galaxy/datatypes/util/maf_utilities.py +++ b/lib/galaxy/datatypes/util/maf_utilities.py @@ -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) @@ -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) @@ -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): @@ -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): diff --git a/lib/galaxy/files/sources/__init__.py b/lib/galaxy/files/sources/__init__.py index 0339e3aaed48..61d6a328108e 100644 --- a/lib/galaxy/files/sources/__init__.py +++ b/lib/galaxy/files/sources/__init__.py @@ -468,8 +468,7 @@ def _get_error_msg_for(rule_name: str) -> str: def uri_join(*args): # url_join doesn't work with non-standard scheme - arg0 = args[0] - if "://" in arg0: + if "://" in (arg0 := args[0]): scheme, path = arg0.split("://", 1) rval = f"{scheme}://{slash_join(path, *args[1:]) if path else slash_join(*args[1:])}" else: diff --git a/lib/galaxy/files/sources/drs.py b/lib/galaxy/files/sources/drs.py index 3e05ca4bd56e..590bfd4666b3 100644 --- a/lib/galaxy/files/sources/drs.py +++ b/lib/galaxy/files/sources/drs.py @@ -8,13 +8,13 @@ from typing_extensions import Unpack -from galaxy.util.drs import fetch_drs_to_file from . import ( BaseFilesSource, FilesSourceOptions, FilesSourceProperties, PluginKind, ) +from .util import fetch_drs_to_file log = logging.getLogger(__name__) diff --git a/lib/galaxy/files/sources/http.py b/lib/galaxy/files/sources/http.py index d2a5b331ccea..0e538baec1dc 100644 --- a/lib/galaxy/files/sources/http.py +++ b/lib/galaxy/files/sources/http.py @@ -85,8 +85,7 @@ def _serialization_props(self, user_context=None) -> HTTPFilesSourceProperties: return cast(HTTPFilesSourceProperties, effective_props) def score_url_match(self, url: str): - match = self._url_regex.match(url) - if match: + if match := self._url_regex.match(url): return match.span()[1] else: return 0 diff --git a/lib/galaxy/util/drs.py b/lib/galaxy/files/sources/util.py similarity index 100% rename from lib/galaxy/util/drs.py rename to lib/galaxy/files/sources/util.py diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 86c43b45ed7c..b015cdd38198 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -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: @@ -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): @@ -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") @@ -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: @@ -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 @@ -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() diff --git a/lib/galaxy/jobs/runners/condor.py b/lib/galaxy/jobs/runners/condor.py index 629d165f5625..04b4d2f2e3c6 100644 --- a/lib/galaxy/jobs/runners/condor.py +++ b/lib/galaxy/jobs/runners/condor.py @@ -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: diff --git a/lib/galaxy/jobs/runners/drmaa.py b/lib/galaxy/jobs/runners/drmaa.py index 6abb6fbef02e..05c2398da190 100644 --- a/lib/galaxy/jobs/runners/drmaa.py +++ b/lib/galaxy/jobs/runners/drmaa.py @@ -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) diff --git a/lib/galaxy/jobs/runners/godocker.py b/lib/galaxy/jobs/runners/godocker.py index bcacb84fb700..4ba4b6c67ab5 100644 --- a/lib/galaxy/jobs/runners/godocker.py +++ b/lib/galaxy/jobs/runners/godocker.py @@ -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 @@ -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.") diff --git a/lib/galaxy/jobs/runners/kubernetes.py b/lib/galaxy/jobs/runners/kubernetes.py index ffac91490a2f..a360f0c87aab 100644 --- a/lib/galaxy/jobs/runners/kubernetes.py +++ b/lib/galaxy/jobs/runners/kubernetes.py @@ -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 @@ -972,8 +972,7 @@ def __cleanup_k8s_guest_ports(self, job_wrapper, k8s_job): else: log.debug(f"No service found for job with k8s_job_name {k8s_job_name}") # remove the interactive environment entrypoints - eps = job_wrapper.get_job().interactivetool_entry_points - if eps: + if eps := job_wrapper.get_job().interactivetool_entry_points: log.debug(f"Removing entry points for job with ID {job_wrapper.get_id_tag()}") self.app.interactivetool_manager.remove_entry_points(eps) diff --git a/lib/galaxy/jobs/runners/univa.py b/lib/galaxy/jobs/runners/univa.py index 12cf317db4f5..edcfdce07fca 100644 --- a/lib/galaxy/jobs/runners/univa.py +++ b/lib/galaxy/jobs/runners/univa.py @@ -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)) @@ -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] @@ -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 == "": diff --git a/lib/galaxy/managers/collections.py b/lib/galaxy/managers/collections.py index 8db9037b55a5..9798445bcc6f 100644 --- a/lib/galaxy/managers/collections.py +++ b/lib/galaxy/managers/collections.py @@ -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, diff --git a/lib/galaxy/managers/datasets.py b/lib/galaxy/managers/datasets.py index 612a69989deb..207d92ca407c 100644 --- a/lib/galaxy/managers/datasets.py +++ b/lib/galaxy/managers/datasets.py @@ -164,8 +164,7 @@ def update_object_store_id(self, trans, dataset, object_store_id: str): # has been shared. raise exceptions.InsufficientPermissionsException("Cannot change dataset permissions...") - quota_source_map = self.app.object_store.get_quota_source_map() - if quota_source_map: + if quota_source_map := self.app.object_store.get_quota_source_map(): old_label = quota_source_map.get_quota_source_label(old_object_store_id) new_label = quota_source_map.get_quota_source_label(new_object_store_id) if old_label != new_label: diff --git a/lib/galaxy/managers/datatypes.py b/lib/galaxy/managers/datatypes.py index 72dbbdb8f5a5..9899cf8b98a2 100644 --- a/lib/galaxy/managers/datatypes.py +++ b/lib/galaxy/managers/datatypes.py @@ -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: diff --git a/lib/galaxy/managers/history_contents.py b/lib/galaxy/managers/history_contents.py index 0a4a09f08f00..c73e82b12ce1 100644 --- a/lib/galaxy/managers/history_contents.py +++ b/lib/galaxy/managers/history_contents.py @@ -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) diff --git a/lib/galaxy/managers/libraries.py b/lib/galaxy/managers/libraries.py index 45c1c582a074..2ed55907fe79 100644 --- a/lib/galaxy/managers/libraries.py +++ b/lib/galaxy/managers/libraries.py @@ -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: diff --git a/lib/galaxy/managers/users.py b/lib/galaxy/managers/users.py index 8f4b9c428e82..c1795da3b395 100644 --- a/lib/galaxy/managers/users.py +++ b/lib/galaxy/managers/users.py @@ -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): diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 1e7353c93060..0291c08fbced 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2562,7 +2562,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) @@ -4241,8 +4241,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 @@ -4404,7 +4404,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 ( @@ -6571,7 +6571,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 @@ -8493,7 +8493,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): diff --git a/lib/galaxy/model/dataset_collections/structure.py b/lib/galaxy/model/dataset_collections/structure.py index af6395054b27..673585a8c87f 100644 --- a/lib/galaxy/model/dataset_collections/structure.py +++ b/lib/galaxy/model/dataset_collections/structure.py @@ -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): diff --git a/lib/galaxy/model/security.py b/lib/galaxy/model/security.py index 378f446c5155..8769c132c3db 100644 --- a/lib/galaxy/model/security.py +++ b/lib/galaxy/model/security.py @@ -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): """ @@ -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): """ @@ -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): """ diff --git a/lib/galaxy/model/tags.py b/lib/galaxy/model/tags.py index a62051b79eef..8d31bc32ba1d 100644 --- a/lib/galaxy/model/tags.py +++ b/lib/galaxy/model/tags.py @@ -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. @@ -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 diff --git a/lib/galaxy/objectstore/pithos.py b/lib/galaxy/objectstore/pithos.py index cd20cbbe8771..fdfb78bf6d90 100644 --- a/lib/galaxy/objectstore/pithos.py +++ b/lib/galaxy/objectstore/pithos.py @@ -43,7 +43,7 @@ def parse_config_xml(config_xml): :returns: (dict) according to syntax :raises: various XML parse errors """ - r = dict() + r = {} try: for tag, required_attrs, optional_attrs in ( ( diff --git a/lib/galaxy/security/object_wrapper.py b/lib/galaxy/security/object_wrapper.py index 1c7176a29b16..df4ead07d6ea 100644 --- a/lib/galaxy/security/object_wrapper.py +++ b/lib/galaxy/security/object_wrapper.py @@ -217,7 +217,7 @@ def pickle_safe_object(safe_object): no_wrap_classes = list(no_wrap_classes) + list(__DONT_SANITIZE_TYPES__) + [SafeStringWrapper] else: no_wrap_classes = list(__DONT_SANITIZE_TYPES__) + [SafeStringWrapper] - no_wrap_classes = tuple(set(sorted(no_wrap_classes, key=str))) + no_wrap_classes = tuple(set(no_wrap_classes)) return __do_wrap(value) diff --git a/lib/galaxy/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py b/lib/galaxy/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py index b367a3322fba..17facc7a0b39 100644 --- a/lib/galaxy/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py @@ -193,7 +193,7 @@ def create_repository_dependency_objects( all_repo_info_dicts = all_required_repo_info_dict.get("all_repo_info_dicts", []) if not all_repo_info_dicts: # No repository dependencies were discovered so process the received repositories. - all_repo_info_dicts = [rid for rid in repo_info_dicts] + all_repo_info_dicts = list(repo_info_dicts) for repo_info_dict in all_repo_info_dicts: # If the user elected to install repository dependencies, all items in the # all_repo_info_dicts list will be processed. However, if repository dependencies diff --git a/lib/galaxy/tool_shed/galaxy_install/tools/data_manager.py b/lib/galaxy/tool_shed/galaxy_install/tools/data_manager.py index 95af11b21f53..d4f2157f82d5 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tools/data_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/tools/data_manager.py @@ -92,7 +92,9 @@ def install_data_managers( raise if tree is None: return rval - config_elems = [elem for elem in tree.getroot()] + config_elems = list( + tree.getroot().__iter__() + ) # `.__iter__()` is a workaround for lxml-stubs declaring _Element a subclass of Iterable["_Element"] repo_data_manager_conf_filename = metadata_dict["data_manager"].get("config_filename", None) if repo_data_manager_conf_filename is None: log.debug("No data_manager_conf.xml file has been defined.") diff --git a/lib/galaxy/tool_shed/util/utility_container_manager.py b/lib/galaxy/tool_shed/util/utility_container_manager.py index 07582e5e8362..e67d552aa2ee 100644 --- a/lib/galaxy/tool_shed/util/utility_container_manager.py +++ b/lib/galaxy/tool_shed/util/utility_container_manager.py @@ -863,7 +863,7 @@ def prune_repository_dependencies(self, folder): dependency has its own repository dependency). This method will remove all repository dependencies from folder that are also sub-folders of folder. """ - repository_dependencies = [rd for rd in folder.repository_dependencies] + repository_dependencies = list(folder.repository_dependencies) for repository_dependency in repository_dependencies: self.prune_folder(folder, repository_dependency) for sub_folder in folder.folders: diff --git a/lib/galaxy/tool_util/data/__init__.py b/lib/galaxy/tool_util/data/__init__.py index 921dc100fd38..04786715be8e 100644 --- a/lib/galaxy/tool_util/data/__init__.py +++ b/lib/galaxy/tool_util/data/__init__.py @@ -1113,7 +1113,7 @@ def to_xml_file( else: raise root = tree.getroot() - out_elems = [elem for elem in root] + out_elems = list(root) except Exception as e: out_elems = [] log.debug("Could not parse existing tool data table config, assume no existing elements: %s", e) diff --git a/lib/galaxy/tool_util/deps/__init__.py b/lib/galaxy/tool_util/deps/__init__.py index 2dc75c3dfac3..6a1eff2f1aa6 100644 --- a/lib/galaxy/tool_util/deps/__init__.py +++ b/lib/galaxy/tool_util/deps/__init__.py @@ -149,7 +149,7 @@ def __init__( def set_enabled_container_types(self, container_types_to_destinations): """Set the union of all enabled container types.""" - self._enabled_container_types = [container_type for container_type in container_types_to_destinations.keys()] + self._enabled_container_types = list(container_types_to_destinations.keys()) # Just pick first enabled destination for a container type, probably covers the most common deployment scenarios self._destination_for_container_type = container_types_to_destinations @@ -323,7 +323,7 @@ def _requirements_to_dependencies_dict(self, requirements, search=False, **kwds) return requirement_to_dependency def uses_tool_shed_dependencies(self): - return any(map(lambda r: isinstance(r, ToolShedPackageDependencyResolver), self.dependency_resolvers)) + return any(isinstance(r, ToolShedPackageDependencyResolver) for r in self.dependency_resolvers) def find_dep(self, name: str, version: Optional[str] = None, type: str = "package", **kwds): log.debug(f"Find dependency {name} version {version}") diff --git a/lib/galaxy/tool_util/deps/brew_exts.py b/lib/galaxy/tool_util/deps/brew_exts.py index 852d7425a908..0f56b279251a 100755 --- a/lib/galaxy/tool_util/deps/brew_exts.py +++ b/lib/galaxy/tool_util/deps/brew_exts.py @@ -380,7 +380,7 @@ def __init__(self, keg_root, action_description): @staticmethod def build_env(env_actions): new_env = os.environ.copy() - map(lambda env_action: env_action.modify_environ(new_env), env_actions) + (env_action.modify_environ(new_env) for env_action in env_actions) return new_env def modify_environ(self, environ): @@ -523,7 +523,7 @@ def recipe_cellar_path(cellar_path, recipe, version): recipe_base_path = os.path.join(cellar_path, recipe_base, version) revision_paths = glob.glob(f"{recipe_base_path}_*") if revision_paths: - revisions = map(lambda x: int(x.rsplit("_", 1)[-1]), revision_paths) + revisions = (int(x.rsplit("_", 1)[-1]) for x in revision_paths) max_revision = max(revisions) recipe_path = "%s_%d" % (recipe_base_path, max_revision) else: diff --git a/lib/galaxy/tool_util/deps/conda_util.py b/lib/galaxy/tool_util/deps/conda_util.py index d5190383a1f9..4905b6091e3e 100644 --- a/lib/galaxy/tool_util/deps/conda_util.py +++ b/lib/galaxy/tool_util/deps/conda_util.py @@ -254,7 +254,7 @@ def exec_command(self, operation: str, args: List[str], stdout_path: Optional[st if self.condarc_override: env["CONDARC"] = self.condarc_override cmd_string = shlex_join(cmd) - kwds: Dict[str, Any] = dict() + kwds: Dict[str, Any] = {} try: if stdout_path: kwds["stdout"] = open(stdout_path, "w") diff --git a/lib/galaxy/tool_util/deps/container_classes.py b/lib/galaxy/tool_util/deps/container_classes.py index 6fade14c37b4..880a3a5d4b59 100644 --- a/lib/galaxy/tool_util/deps/container_classes.py +++ b/lib/galaxy/tool_util/deps/container_classes.py @@ -320,7 +320,7 @@ def _expand_volume_str(self: ContainerProtocol, value: str) -> str: return value template = string.Template(value) - variables = dict() + variables = {} def add_var(name, value): if value: diff --git a/lib/galaxy/tool_util/deps/container_resolvers/mulled.py b/lib/galaxy/tool_util/deps/container_resolvers/mulled.py index 1e51bcf97a17..b976662ccf6b 100644 --- a/lib/galaxy/tool_util/deps/container_resolvers/mulled.py +++ b/lib/galaxy/tool_util/deps/container_resolvers/mulled.py @@ -111,8 +111,8 @@ def __init__(self, path: str, hash_func: Literal["v1", "v2"] = "v2") -> None: def _list_cached_mulled_images_from_path(self) -> List[CachedTarget]: contents = os.listdir(self.path) sorted_images = version_sorted(contents) - raw_images = map(lambda name: identifier_to_cached_target(name, self.hash_func), sorted_images) - return list(i for i in raw_images if i is not None) + raw_images = (identifier_to_cached_target(name, self.hash_func) for name in sorted_images) + return [i for i in raw_images if i is not None] @abstractmethod def list_cached_mulled_images_from_path(self) -> List[CachedTarget]: @@ -202,7 +202,7 @@ def output_line_to_image(line: str) -> Optional[CachedTarget]: return image name_filter = get_filter(namespace) - sorted_images = version_sorted([_ for _ in filter(name_filter, images_and_versions)]) + sorted_images = version_sorted(list(filter(name_filter, images_and_versions))) raw_images = (output_line_to_image(_) for _ in sorted_images) return [i for i in raw_images if i is not None] diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build.py b/lib/galaxy/tool_util/deps/mulled/mulled_build.py index d2f6e0dc0090..173f4a9fc2f6 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build.py @@ -150,7 +150,7 @@ def get_affected_packages(args): def conda_versions(pkg_name, file_name): """Return all conda version strings for a specified package name.""" j = json.load(open(file_name)) - ret = list() + ret = [] for pkg in j["packages"].values(): if pkg["name"] == pkg_name: ret.append(f"{pkg['version']}--{pkg['build']}") diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_search.py b/lib/galaxy/tool_util/deps/mulled/mulled_search.py index adb9cb91fc1b..a2553ddf770c 100755 --- a/lib/galaxy/tool_util/deps/mulled/mulled_search.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_search.py @@ -88,7 +88,7 @@ def search_repository(self, search_string, non_strict): results_tmp = searcher.search(query) results.extend(results_tmp) - out = list() + out = [] for result in results: title = result["title"] diff --git a/lib/galaxy/tool_util/deps/mulled/util.py b/lib/galaxy/tool_util/deps/mulled/util.py index 507a6bb5fe89..17aa33ba8fa2 100644 --- a/lib/galaxy/tool_util/deps/mulled/util.py +++ b/lib/galaxy/tool_util/deps/mulled/util.py @@ -347,14 +347,14 @@ def v2_image_name( return _simple_image_name(targets, image_build=image_build) else: targets_order = sorted(targets, key=lambda t: t.package) - package_name_buffer = "\n".join(map(lambda t: t.package, targets_order)) + package_name_buffer = "\n".join(t.package for t in targets_order) package_hash = hashlib.sha1() package_hash.update(package_name_buffer.encode()) - versions = map(lambda t: t.version, targets_order) + versions = (t.version for t in targets_order) if any(versions): # Only hash versions if at least one package has versions... - version_name_buffer = "\n".join(map(lambda t: t.version or "null", targets_order)) + version_name_buffer = "\n".join(t.version or "null" for t in targets_order) version_hash = hashlib.sha1() version_hash.update(version_name_buffer.encode()) version_hash_str = version_hash.hexdigest() diff --git a/lib/galaxy/tool_util/linters/inputs.py b/lib/galaxy/tool_util/linters/inputs.py index 7f0e8889543f..d24644a1f37b 100644 --- a/lib/galaxy/tool_util/linters/inputs.py +++ b/lib/galaxy/tool_util/linters/inputs.py @@ -622,7 +622,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): if param_type != "select": continue select_options = param.findall("./option") - select_options_values = list() + select_options_values = [] for option in select_options: value = option.attrib.get("value", "") select_options_values.append((value, option.attrib.get("selected", "false"))) @@ -648,7 +648,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): if param_type != "select": continue select_options = param.findall("./option") - select_options_texts = list() + select_options_texts = [] for option in select_options: if option.text is None: text = option.attrib.get("value", "").capitalize() @@ -702,7 +702,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): if options is None: continue filter_adds_options = any( - [f.get("type", None) in ["add_value", "data_meta"] for f in param.findall("./options/filter")] + f.get("type", None) in ["add_value", "data_meta"] for f in param.findall("./options/filter") ) from_file = options.get("from_file", None) from_parameter = options.get("from_parameter", None) @@ -1314,11 +1314,11 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): continue if first_param_type == "select": options = first_param.findall("./option[@value]") - option_ids = set([option.get("value") for option in options]) + option_ids = {option.get("value") for option in options} else: # boolean - option_ids = set([first_param.get("truevalue", "true"), first_param.get("falsevalue", "false")]) + option_ids = {first_param.get("truevalue", "true"), first_param.get("falsevalue", "false")} whens = conditional.findall("./when[@value]") - when_ids = set([w.get("value") for w in whens if w.get("value") is not None]) + when_ids = {w.get("value") for w in whens if w.get("value") is not None} for option_id in option_ids - when_ids: lint_ctx.warn( f"Conditional [{conditional_name}] no block found for {first_param_type} option '{option_id}'", @@ -1337,9 +1337,9 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): if first_param_type != "select": continue options = first_param.findall("./option[@value]") - option_ids = set([option.get("value") for option in options]) + option_ids = {option.get("value") for option in options} whens = conditional.findall("./when[@value]") - when_ids = set([w.get("value") for w in whens if w.get("value") is not None]) + when_ids = {w.get("value") for w in whens if w.get("value") is not None} for when_id in when_ids - option_ids: lint_ctx.warn( f"Conditional [{conditional_name}] no