Merge pull request #10751 from nsoranzo/py36_again

Upgrade syntax using `pyupgrade --py36-plus`
This commit is contained in:
Dannon
2020-11-18 13:47:41 -05:00
committed by GitHub
32 changed files with 35 additions and 66 deletions
+1 -1
View File
@@ -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:
+2 -2
View File
@@ -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 = []
+1 -1
View File
@@ -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():
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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:
+7 -7
View File
@@ -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
+1 -1
View File
@@ -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"]
+1 -1
View File
@@ -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}")
+1 -1
View File
@@ -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
@@ -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:
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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:
+3 -8
View File
@@ -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
+1 -1
View File
@@ -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:
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-app"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-auth"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-data"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-job-execution"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-job-metrics"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-objectstore"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-selenium"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-test-api"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-test-base"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-test-driver"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-test-selenium"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '21.1.0.dev3'
PROJECT_NAME = "galaxy-tool-util"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.2.dev0'
PROJECT_NAME = "galaxy-util"
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '20.9.1.dev0'
PROJECT_NAME = "galaxy-web-framework"
+1 -1
View File
@@ -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()
+5 -3
View File
@@ -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
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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)