diff --git a/lib/galaxy/config/__init__.py b/lib/galaxy/config/__init__.py index 13a6df6eb4a..777ee0755b4 100644 --- a/lib/galaxy/config/__init__.py +++ b/lib/galaxy/config/__init__.py @@ -871,7 +871,7 @@ class GalaxyAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin): self._set_alt_paths('file_path', self._in_data_dir('files')) # this is called BEFORE guessing id/uuid ID, UUID = 'id', 'uuid' if self.is_set('object_store_store_by'): - assert self.object_store_store_by in [ID, UUID], "Invalid value for object_store_store_by [{}]".format(self.object_store_store_by) + assert self.object_store_store_by in [ID, UUID], f"Invalid value for object_store_store_by [{self.object_store_store_by}]" elif os.path.basename(self.file_path) == 'objects': self.object_store_store_by = UUID else: diff --git a/lib/galaxy/dependencies/__init__.py b/lib/galaxy/dependencies/__init__.py index 90ed795d4be..95360b10c50 100644 --- a/lib/galaxy/dependencies/__init__.py +++ b/lib/galaxy/dependencies/__init__.py @@ -90,7 +90,7 @@ class ConditionalDependencies: if 'type' in store.attrib: self.object_stores.append(store.attrib['type']) else: - with open(object_store_conf_path, "r") as f: + with open(object_store_conf_path) as f: job_conf_dict = yaml.safe_load(f) def collect_types(from_dict): @@ -147,7 +147,7 @@ class ConditionalDependencies: "file_sources_config_file", join(dirname(self.config_file), 'file_sources_conf.yml')) if exists(file_sources_conf_yml): - with open(file_sources_conf_yml, "r") as f: + with open(file_sources_conf_yml) as f: file_sources_conf = yaml.safe_load(f) else: file_sources_conf = [] diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 0964756d528..bc679123ca6 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -1942,7 +1942,7 @@ class JobWrapper(HasResourceParameters): def get_output_path(self, dataset): if getattr(dataset, "fake_dataset_association", False): return dataset.file_name - assert dataset.id is not None, "{} needs to be flushed to find output path".format(dataset) + assert dataset.id is not None, f"{dataset} needs to be flushed to find output path" if self.output_paths is None: self.compute_outputs() for (hda, dataset_path) in self.output_hdas_and_paths.values(): diff --git a/lib/galaxy/tool_util/cwl/runnable.py b/lib/galaxy/tool_util/cwl/runnable.py index eefd5deda1c..d60853ef0ca 100644 --- a/lib/galaxy/tool_util/cwl/runnable.py +++ b/lib/galaxy/tool_util/cwl/runnable.py @@ -16,7 +16,7 @@ def get_outputs(path): return [CwlWorkflowOutput(label) for label in workflow.output_labels] -class CwlWorkflowOutput(object): +class CwlWorkflowOutput: def __init__(self, label): self._label = label @@ -25,7 +25,7 @@ class CwlWorkflowOutput(object): return self._label -class ToolOutput(object): +class ToolOutput: def __init__(self, tool_output): self._tool_output = tool_output diff --git a/lib/galaxy/tool_util/verify/interactor.py b/lib/galaxy/tool_util/verify/interactor.py index 64a00980d3c..d82fc8186e2 100644 --- a/lib/galaxy/tool_util/verify/interactor.py +++ b/lib/galaxy/tool_util/verify/interactor.py @@ -845,7 +845,7 @@ class DictClientTestConfig: if tool_id in self._tools: tool_test_config = self._tools[tool_id] if tool_test_config is None: - tool_id = "%s/%s" % (tool_id, tool_version) + tool_id = f"{tool_id}/{tool_version}" if tool_id in self._tools: tool_version_test_config = self._tools[tool_id] else: diff --git a/lib/galaxy/tool_util/verify/script.py b/lib/galaxy/tool_util/verify/script.py index 972622f4f40..6e5db481b93 100644 --- a/lib/galaxy/tool_util/verify/script.py +++ b/lib/galaxy/tool_util/verify/script.py @@ -107,22 +107,22 @@ class Results: def info_message(self): messages = [] passed_tests = self._tests_with_status('success') - messages.append("Passed tool tests ({0}): {1}".format( + messages.append("Passed tool tests ({}): {}".format( len(passed_tests), [t["id"] for t in passed_tests] )) failed_tests = self._tests_with_status('failure') - messages.append("Failed tool tests ({0}): {1}".format( + messages.append("Failed tool tests ({}): {}".format( len(failed_tests), [t["id"] for t in failed_tests] )) skiped_tests = self._tests_with_status('skip') - messages.append("Skipped tool tests ({0}): {1}".format( + messages.append("Skipped tool tests ({}): {}".format( len(skiped_tests), [t["id"] for t in skiped_tests] )) errored_tests = self._tests_with_status('error') - messages.append("Errored tool tests ({0}): {1}".format( + messages.append("Errored tool tests ({}): {}".format( len(errored_tests), [t["id"] for t in errored_tests] )) @@ -198,7 +198,7 @@ def test_tools( if log: log.info("Report written to '%s'", os.path.abspath(results.test_json)) log.info(results.info_message()) - log.info("Total tool test time: {0}".format(dt.datetime.now() - tool_test_start)) + log.info("Total tool test time: {}".format(dt.datetime.now() - tool_test_start)) if history_created and not no_history_cleanup: galaxy_interactor.delete_history(test_history) @@ -337,7 +337,7 @@ def main(argv=None): client_test_config_path = args.client_test_config if client_test_config_path is not None: log.debug(f"Reading client config path {client_test_config_path}") - with open(client_test_config_path, "r") as f: + with open(client_test_config_path) as f: client_test_config = yaml.full_load(f) else: client_test_config = {} @@ -417,7 +417,7 @@ def setup_global_logger(name, log_file=None, verbose=False): log_file = temp.name file_handler = logging.FileHandler(log_file) logger.addHandler(file_handler) - logger.info("Storing log file in: {0}".format(log_file)) + logger.info(f"Storing log file in: {log_file}") return logger diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index fce5a2d90a5..02a8a34db40 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -2494,7 +2494,7 @@ class ExpressionTool(Tool): continue if val.output_type == "data": - with open(out_data[key].file_name, "r") as f: + with open(out_data[key].file_name) as f: src = json.load(f) assert isinstance(src, dict), f"Expected dataset 'src' to be a dictionary - actual type is {type(src)}" dataset_id = src["id"] diff --git a/lib/galaxy/tools/actions/__init__.py b/lib/galaxy/tools/actions/__init__.py index acbe2ccd7b0..70e16637598 100644 --- a/lib/galaxy/tools/actions/__init__.py +++ b/lib/galaxy/tools/actions/__init__.py @@ -517,7 +517,7 @@ class DefaultToolAction: completed_job=completed_job, **element_kwds ) - log.info("Handled collection output named {} for tool {} {}".format(name, tool.id, handle_output_timer)) + log.info(f"Handled collection output named {name} for tool {tool.id} {handle_output_timer}") else: handle_output(name, output) log.info(f"Handled output named {name} for tool {tool.id} {handle_output_timer}") diff --git a/lib/galaxy/tools/data_fetch.py b/lib/galaxy/tools/data_fetch.py index 12a1c6308db..9ecfc29f010 100644 --- a/lib/galaxy/tools/data_fetch.py +++ b/lib/galaxy/tools/data_fetch.py @@ -384,7 +384,7 @@ def _has_src_to_path(upload_config, item, is_dataset=False): try: path = sniff.stream_url_to_file(url, file_sources=get_file_sources(upload_config.working_directory)) except Exception as e: - raise Exception("Failed to fetch url %s. %s" % (url, str(e))) + raise Exception("Failed to fetch url {}. {}".format(url, str(e))) if not is_dataset: # Actual target dataset will validate and put results in dict diff --git a/lib/galaxy/tools/parameters/dynamic_options.py b/lib/galaxy/tools/parameters/dynamic_options.py index d2e0122681f..67bcc3fd8c8 100644 --- a/lib/galaxy/tools/parameters/dynamic_options.py +++ b/lib/galaxy/tools/parameters/dynamic_options.py @@ -165,7 +165,7 @@ class DataMetaFilter(Filter): if isinstance(m, list): meta_value |= set(m) elif isinstance(m, dict): - meta_value |= set(["%s,%s" % (k, v) for k, v in m.items()]) + meta_value |= {f"{k},{v}" for k, v in m.items()} elif isinstance(m, str) and os.path.isfile(m): with open(m) as fh: for line in fh: @@ -679,7 +679,7 @@ class DynamicOptions: else: # Pass just the first megabyte to parse_file_fields. log.warning("Attempting to load options from large file, reading just first megabyte") - with open(path, 'r') as fh: + with open(path) as fh: contents = fh.read(1048576) options += self.parse_file_fields(StringIO(contents)) elif self.tool_data_table: diff --git a/lib/galaxy/tools/toolbox/watcher.py b/lib/galaxy/tools/toolbox/watcher.py index e66956e7ee3..8a374971487 100644 --- a/lib/galaxy/tools/toolbox/watcher.py +++ b/lib/galaxy/tools/toolbox/watcher.py @@ -90,7 +90,7 @@ class ToolConfWatcher: def shutdown(self): if self._active: self._active = False - if self.thread.isAlive(): + if self.thread.is_alive(): self.exit.set() self.thread.join() self.thread = None diff --git a/lib/galaxy/util/checkers.py b/lib/galaxy/util/checkers.py index 1a5ba726273..140c53ac75b 100644 --- a/lib/galaxy/util/checkers.py +++ b/lib/galaxy/util/checkers.py @@ -28,7 +28,7 @@ def check_html(name, file_path=True): """ # Handles files if file_path is True or text if file_path is False if file_path: - temp = open(name, "r", encoding='utf-8') + temp = open(name, encoding='utf-8') else: temp = StringIO(util.unicodify(name)) try: diff --git a/lib/galaxy/web/framework/base.py b/lib/galaxy/web/framework/base.py index da528e1f9e9..461a7ea7f41 100644 --- a/lib/galaxy/web/framework/base.py +++ b/lib/galaxy/web/framework/base.py @@ -20,11 +20,6 @@ from paste.response import HeaderDict from galaxy.util import smart_str -try: - file_types = (file, io.IOBase) -except NameError: - file_types = (io.IOBase, ) - log = logging.getLogger(__name__) #: time of the most recent server startup @@ -237,7 +232,7 @@ class WebApplication: start_response(trans.response.wsgi_status(), trans.response.wsgi_headeritems()) return body - elif isinstance(body, file_types): + elif isinstance(body, io.IOBase): # Stream the file back to the browser return send_file(start_response, trans, body) else: @@ -344,7 +339,7 @@ def _read_lines(self): # Adapt `self.__file = None` to Python name mangling of class-private attributes. # We need to patch the original FieldStorage class attribute, not the cgi_FieldStorage # class. - setattr(self, '_FieldStorage__file', None) + self._FieldStorage__file = None if self.outerboundary: self.read_lines_to_outerboundary() else: @@ -464,7 +459,7 @@ class Response: """ result = self.headers.headeritems() # Add cookie to header - for name, crumb in self.cookies.items(): + for crumb in self.cookies.values(): header, value = str(crumb).split(': ', 1) result.append((header, value)) return result diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index 9005470f997..0626f5cf8d5 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -284,7 +284,7 @@ class GalaxyWebTransaction(base.DefaultWebTransaction, if key.startswith(acr): self.set_cors_allow(name=key[len(acr):], value=value) else: - resp_name = 'Access-Control-Allow-{}'.format(name) + resp_name = f'Access-Control-Allow-{name}' if value is None: value = self.request.headers.get(acr + name, None) if value: diff --git a/packages/app/galaxy/project_galaxy_app.py b/packages/app/galaxy/project_galaxy_app.py index 95ba0d02e25..76d355d50a9 100644 --- a/packages/app/galaxy/project_galaxy_app.py +++ b/packages/app/galaxy/project_galaxy_app.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-app" diff --git a/packages/auth/galaxy/project_galaxy_auth.py b/packages/auth/galaxy/project_galaxy_auth.py index 871f2a8a1a3..4d206925783 100644 --- a/packages/auth/galaxy/project_galaxy_auth.py +++ b/packages/auth/galaxy/project_galaxy_auth.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-auth" diff --git a/packages/data/galaxy/project_galaxy_data.py b/packages/data/galaxy/project_galaxy_data.py index 4b02e611c68..b0dfc84d443 100644 --- a/packages/data/galaxy/project_galaxy_data.py +++ b/packages/data/galaxy/project_galaxy_data.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-data" diff --git a/packages/job_execution/galaxy/project_galaxy_job_execution.py b/packages/job_execution/galaxy/project_galaxy_job_execution.py index 0f550a86ba5..990327dcdc7 100644 --- a/packages/job_execution/galaxy/project_galaxy_job_execution.py +++ b/packages/job_execution/galaxy/project_galaxy_job_execution.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-job-execution" diff --git a/packages/job_metrics/galaxy/project_galaxy_job_metrics.py b/packages/job_metrics/galaxy/project_galaxy_job_metrics.py index 53b6d10f091..cbb2c245010 100644 --- a/packages/job_metrics/galaxy/project_galaxy_job_metrics.py +++ b/packages/job_metrics/galaxy/project_galaxy_job_metrics.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-job-metrics" diff --git a/packages/objectstore/galaxy/project_galaxy_objectstore.py b/packages/objectstore/galaxy/project_galaxy_objectstore.py index 38b63150b72..0ba6a66904f 100644 --- a/packages/objectstore/galaxy/project_galaxy_objectstore.py +++ b/packages/objectstore/galaxy/project_galaxy_objectstore.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-objectstore" diff --git a/packages/selenium/galaxy/project_galaxy_selenium.py b/packages/selenium/galaxy/project_galaxy_selenium.py index 7951b3154ff..4a7569f3fe2 100644 --- a/packages/selenium/galaxy/project_galaxy_selenium.py +++ b/packages/selenium/galaxy/project_galaxy_selenium.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-selenium" diff --git a/packages/test_api/galaxy/project_galaxy_test_api.py b/packages/test_api/galaxy/project_galaxy_test_api.py index 4bf45a21246..d33384cf448 100644 --- a/packages/test_api/galaxy/project_galaxy_test_api.py +++ b/packages/test_api/galaxy/project_galaxy_test_api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-test-api" diff --git a/packages/test_base/galaxy/project_galaxy_test_base.py b/packages/test_base/galaxy/project_galaxy_test_base.py index a097ea2ee86..7840cfbc934 100644 --- a/packages/test_base/galaxy/project_galaxy_test_base.py +++ b/packages/test_base/galaxy/project_galaxy_test_base.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-test-base" diff --git a/packages/test_driver/galaxy/project_galaxy_test_driver.py b/packages/test_driver/galaxy/project_galaxy_test_driver.py index ae493cf5a6f..0efae8ff6b6 100644 --- a/packages/test_driver/galaxy/project_galaxy_test_driver.py +++ b/packages/test_driver/galaxy/project_galaxy_test_driver.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-test-driver" diff --git a/packages/test_selenium/galaxy/project_galaxy_test_selenium.py b/packages/test_selenium/galaxy/project_galaxy_test_selenium.py index a93c6364399..6b7d01bda25 100644 --- a/packages/test_selenium/galaxy/project_galaxy_test_selenium.py +++ b/packages/test_selenium/galaxy/project_galaxy_test_selenium.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-test-selenium" diff --git a/packages/tool_util/galaxy/project_galaxy_tool_util.py b/packages/tool_util/galaxy/project_galaxy_tool_util.py index 17d8b6aefee..9ebd2883b36 100644 --- a/packages/tool_util/galaxy/project_galaxy_tool_util.py +++ b/packages/tool_util/galaxy/project_galaxy_tool_util.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '21.1.0.dev3' PROJECT_NAME = "galaxy-tool-util" diff --git a/packages/util/galaxy/project_galaxy_util.py b/packages/util/galaxy/project_galaxy_util.py index ad0bc24ba64..74d97f8c6ff 100644 --- a/packages/util/galaxy/project_galaxy_util.py +++ b/packages/util/galaxy/project_galaxy_util.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.2.dev0' PROJECT_NAME = "galaxy-util" diff --git a/packages/web_framework/galaxy/project_galaxy_web_framework.py b/packages/web_framework/galaxy/project_galaxy_web_framework.py index d54f2c6cf71..6c4d1d169ef 100644 --- a/packages/web_framework/galaxy/project_galaxy_web_framework.py +++ b/packages/web_framework/galaxy/project_galaxy_web_framework.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __version__ = '20.9.1.dev0' PROJECT_NAME = "galaxy-web-framework" diff --git a/scripts/release-diff.py b/scripts/release-diff.py index 51b526c3338..7e28f80beea 100644 --- a/scripts/release-diff.py +++ b/scripts/release-diff.py @@ -115,7 +115,7 @@ def load_at_time(path, revision=None): ["git", "show", f"{revision}:{path}"], stderr=subprocess.STDOUT ) else: - with open(path, "r") as handle: + with open(path) as handle: return handle.read() diff --git a/test/integration/test_kubernetes_staging.py b/test/integration/test_kubernetes_staging.py index a7f5bd8e40c..e255b60c51d 100644 --- a/test/integration/test_kubernetes_staging.py +++ b/test/integration/test_kubernetes_staging.py @@ -15,6 +15,9 @@ import os import random import string import tempfile +import time + +import yaml from galaxy.jobs.runners.util.pykube_util import ( Job, @@ -146,8 +149,8 @@ class KubernetesStagingContainerIntegrationTestCase(CancelsJob, BaseKubernetesSt @property def instance_id(self): - import yaml - config = yaml.load(open(self.job_config_file)) + with open(self.job_config_file) as fh: + config = yaml.safe_load(fh) return config["execution"]["environments"]["pulsar_k8s_environment"]["k8s_galaxy_instance_id"] @skip_without_tool("cat_data_and_sleep") @@ -161,7 +164,6 @@ class KubernetesStagingContainerIntegrationTestCase(CancelsJob, BaseKubernetesSt delete_response = self.dataset_populator.cancel_job(job_id) assert delete_response.json() is True - import time time.sleep(5) assert self._active_kubernetes_jobs == 0 diff --git a/test/unit/app/tools/test_data_fetch.py b/test/unit/app/tools/test_data_fetch.py index 233825f863f..c5b75e3b508 100644 --- a/test/unit/app/tools/test_data_fetch.py +++ b/test/unit/app/tools/test_data_fetch.py @@ -246,5 +246,5 @@ class ExecuteContext: @property def galaxy_json(self): assert os.path.exists(self.galaxy_json_path) - with open(self.galaxy_json_path, "r") as f: + with open(self.galaxy_json_path) as f: return json.load(f) diff --git a/test/unit/tool_util/test_verify_script.py b/test/unit/tool_util/test_verify_script.py index 5c97c364286..853981ebb35 100644 --- a/test/unit/tool_util/test_verify_script.py +++ b/test/unit/tool_util/test_verify_script.py @@ -178,7 +178,7 @@ def test_results(): results.write() message = results.info_message() - with open(f.name, "r") as f: + with open(f.name) as f: report_obj = json.load(f) assert "tests" in report_obj assert len(report_obj["tests"]) == 1 @@ -193,7 +193,7 @@ def test_results(): results.write() message = results.info_message() - with open(f.name, "r") as f: + with open(f.name) as f: report_obj = json.load(f) assert len(report_obj["tests"]) == 2 assert report_obj["results"]["skips"] == 1 @@ -245,7 +245,7 @@ def assert_results_not_written(results): def assert_results_written(results): assert os.stat(results.test_json).st_size > 0 - with open(results.test_json, "r") as f: + with open(results.test_json) as f: json.load(f)