From d8f123f647812d92b312a388207404c3446cf98c Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 12 Jul 2022 13:27:33 +0100 Subject: [PATCH] Code cleanups from pyupgrade Found by running: ``` ack --type=python -f | grep -v '^tools/' | xargs pyupgrade --py37-plus ``` --- lib/galaxy/datatypes/molecules.py | 2 +- lib/galaxy/files/sources/__init__.py | 7 ++++--- lib/galaxy/files/sources/_pyfilesystem2.py | 2 +- lib/galaxy/files/uris.py | 2 +- lib/galaxy/managers/workflows.py | 2 +- lib/galaxy/model/store/__init__.py | 2 +- lib/galaxy/model/store/load_objects.py | 2 +- lib/galaxy/web/short_term_storage/__init__.py | 2 +- lib/galaxy/web_stack/gunicorn_config.py | 2 +- test/integration/test_job_files.py | 4 ++-- test/unit/data/test_dataset_materialization.py | 2 +- 11 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/galaxy/datatypes/molecules.py b/lib/galaxy/datatypes/molecules.py index 0c6460d6133..bebf7b99b1d 100644 --- a/lib/galaxy/datatypes/molecules.py +++ b/lib/galaxy/datatypes/molecules.py @@ -1382,7 +1382,7 @@ class ExtendedXYZ(XYZ): if properties is None: # re.search returned None raise ValueError(f"Could not find column properties in line: {comment}") properties = [s.split(":") for s in re.findall(r"[a-zA-Z]+:[SIRL]:[0-9]+", properties.group(1))] - total_columns = sum([int(s[2]) for s in properties]) + total_columns = sum(int(s[2]) for s in properties) for _ in range(n_atoms): atom_dict = {} diff --git a/lib/galaxy/files/sources/__init__.py b/lib/galaxy/files/sources/__init__.py index 20f8eb2ad16..d4ec947f5bc 100644 --- a/lib/galaxy/files/sources/__init__.py +++ b/lib/galaxy/files/sources/__init__.py @@ -1,9 +1,10 @@ import abc import os import time -from typing import Set - -from typing_extensions import ClassVar +from typing import ( + ClassVar, + Set, +) from galaxy.exceptions import ( ConfigurationError, diff --git a/lib/galaxy/files/sources/_pyfilesystem2.py b/lib/galaxy/files/sources/_pyfilesystem2.py index 13e0f9d2102..08abb9e4574 100644 --- a/lib/galaxy/files/sources/_pyfilesystem2.py +++ b/lib/galaxy/files/sources/_pyfilesystem2.py @@ -4,6 +4,7 @@ import logging import os from typing import ( Any, + ClassVar, Dict, List, Optional, @@ -12,7 +13,6 @@ from typing import ( import fs from fs.base import FS -from typing_extensions import ClassVar from ..sources import BaseFilesSource diff --git a/lib/galaxy/files/uris.py b/lib/galaxy/files/uris.py index 1e3fd64fc80..12bbf14b746 100644 --- a/lib/galaxy/files/uris.py +++ b/lib/galaxy/files/uris.py @@ -36,7 +36,7 @@ def stream_url_to_str( ) -> str: tmp_file = stream_url_to_file(path, file_sources=file_sources, prefix=prefix) try: - with open(tmp_file, "r") as f: + with open(tmp_file) as f: return f.read() finally: os.remove(tmp_file) diff --git a/lib/galaxy/managers/workflows.py b/lib/galaxy/managers/workflows.py index c85f61a0edb..1f866fb0206 100644 --- a/lib/galaxy/managers/workflows.py +++ b/lib/galaxy/managers/workflows.py @@ -146,7 +146,7 @@ class WorkflowsManager(sharable.SharableModelManager): filters.append(model.StoredWorkflowUserShareAssociation.user == user) if show_published or user is None and show_published is None: - filters.append((model.StoredWorkflow.published == true())) + filters.append(model.StoredWorkflow.published == true()) query = trans.sa_session.query(model.StoredWorkflow) if show_shared: diff --git a/lib/galaxy/model/store/__init__.py b/lib/galaxy/model/store/__init__.py index 8fb18ac9aa1..d1161f1168c 100644 --- a/lib/galaxy/model/store/__init__.py +++ b/lib/galaxy/model/store/__init__.py @@ -2257,7 +2257,7 @@ def source_to_import_store( delete = True target_path = source_uri if target_path.endswith(".json"): - with open(target_path, "r") as f: + with open(target_path) as f: store_dict = load(f) assert isinstance(store_dict, dict) model_import_store = get_import_model_store_for_dict( diff --git a/lib/galaxy/model/store/load_objects.py b/lib/galaxy/model/store/load_objects.py index cc1caad9a65..3c3fbed2bc8 100644 --- a/lib/galaxy/model/store/load_objects.py +++ b/lib/galaxy/model/store/load_objects.py @@ -50,7 +50,7 @@ def main(argv=None): data: Dict[str, Any] = {} if is_json: - with open(store_path, "r") as f: + with open(store_path) as f: store_dict = yaml.safe_load(f) data["store_dict"] = store_dict else: diff --git a/lib/galaxy/web/short_term_storage/__init__.py b/lib/galaxy/web/short_term_storage/__init__.py index 6b76bb13a35..2aeef596b01 100644 --- a/lib/galaxy/web/short_term_storage/__init__.py +++ b/lib/galaxy/web/short_term_storage/__init__.py @@ -244,7 +244,7 @@ class ShortTermStorageManager(ShortTermStorageAllocator, ShortTermStorageMonitor def _load_metadata(self, target_directory: Path, meta_name: str): meta_path = target_directory / f"{meta_name}.json" - with open(meta_path, "r") as f: + with open(meta_path) as f: return json.load(f) def _directory(self, target: Union[str, ShortTermStorageTarget]) -> Path: diff --git a/lib/galaxy/web_stack/gunicorn_config.py b/lib/galaxy/web_stack/gunicorn_config.py index 3e48bc005c5..ec63f9e4856 100644 --- a/lib/galaxy/web_stack/gunicorn_config.py +++ b/lib/galaxy/web_stack/gunicorn_config.py @@ -32,7 +32,7 @@ def _next_worker_id(server): if server._worker_id_overload: return server._worker_id_overload.pop() - in_use = set(w._worker_id for w in tuple(server.WORKERS.values()) if w.alive) + in_use = {w._worker_id for w in tuple(server.WORKERS.values()) if w.alive} free = set(range(1, server._worker_id_current_workers + 1)) - in_use return free.pop() diff --git a/test/integration/test_job_files.py b/test/integration/test_job_files.py index 03bbec452fe..2131ca2d9c5 100644 --- a/test/integration/test_job_files.py +++ b/test/integration/test_job_files.py @@ -85,13 +85,13 @@ class JobFilesIntegerationTestCase(integration_util.IntegrationTestCase): post_url = self._api_url(f"jobs/{job_id}/files", use_key=False) response = requests.post(post_url, data=data, files=files()) api_asserts.assert_status_code_is_ok(response) - assert open(path, "r").read() == "some initial text data" + assert open(path).read() == "some initial text data" work_dir_file = os.path.join(working_directory, "work") data = {"path": work_dir_file, "job_key": job_key} response = requests.post(post_url, data=data, files=files()) api_asserts.assert_status_code_is_ok(response) - assert open(work_dir_file, "r").read() == "some initial text data" + assert open(work_dir_file).read() == "some initial text data" # set job state to finished and ensure the file is no longer # readable diff --git a/test/unit/data/test_dataset_materialization.py b/test/unit/data/test_dataset_materialization.py index ed20490e863..f056454b6a9 100644 --- a/test/unit/data/test_dataset_materialization.py +++ b/test/unit/data/test_dataset_materialization.py @@ -337,6 +337,6 @@ def _assert_2_bed_metadata(hda: HistoryDatasetAssociation) -> None: def _assert_path_contains_2_bed(path) -> None: - with open(path, "r") as f: + with open(path) as f: contents = f.read() assert contents == CONTENTS_2_BED