mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #12774 from nsoranzo/pyupgrade_fixes
New pyupgrade cleanups
This commit is contained in:
@@ -69,7 +69,7 @@ def main():
|
||||
config_sample.set(section, name, value)
|
||||
else:
|
||||
if not config_sample.get(section, name) == value:
|
||||
logging.info("- diff - section [{}] option '{}' has different value ('{}':'{}'). It will be modified.".format(section, name, config_sample.get(section, name), value))
|
||||
logging.info(f"- diff - section [{section}] option '{name}' has different value ('{config_sample.get(section, name)}':'{value}'). It will be modified.")
|
||||
config_sample.set(section, name, value)
|
||||
logging.info("---------- DIFFERENCE ANALYSIS END ----------")
|
||||
|
||||
|
||||
@@ -975,7 +975,7 @@ class GalaxyAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin):
|
||||
log.warning("Sanitize log file explicitly specified as '%s' but does not exist, continuing with no tools allowlisted.", self.sanitize_allowlist_file)
|
||||
else:
|
||||
with open(self.sanitize_allowlist_file) as f:
|
||||
self.sanitize_allowlist = sorted([line.strip() for line in f.readlines() if not line.startswith('#')])
|
||||
self.sanitize_allowlist = sorted(line.strip() for line in f.readlines() if not line.startswith('#'))
|
||||
|
||||
def ensure_tempdir(self):
|
||||
self._ensure_directory(self.new_file_path)
|
||||
|
||||
@@ -44,7 +44,7 @@ class DockerAttributeContainer:
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(tuple(sorted([repr(x) for x in self._members])))
|
||||
return hash(tuple(sorted(repr(x) for x in self._members)))
|
||||
|
||||
def __str__(self):
|
||||
return ', '.join(str(x) for x in self._members) or 'None'
|
||||
|
||||
@@ -1600,7 +1600,7 @@ class H5MLM(H5):
|
||||
|
||||
repr_ = self.get_repr(dataset.file_name)
|
||||
|
||||
return "<pre>{}</pre><pre>{}</pre>".format(repr_, rval)
|
||||
return f"<pre>{repr_}</pre><pre>{rval}</pre>"
|
||||
|
||||
|
||||
class HexrdMaterials(H5):
|
||||
|
||||
@@ -359,7 +359,7 @@ class Gmaj(data.Data):
|
||||
"nobutton": "false",
|
||||
"urlpause": "100",
|
||||
"debug": "false",
|
||||
"posturl": "history_add_to?%s" % "&".join("{}={}".format(x[0], quote_plus(str(x[1]))) for x in [('copy_access_from', dataset.id), ('history_id', dataset.history_id), ('ext', 'maf'), ('name', f'GMAJ Output on data {dataset.hid}'), ('info', 'Added by GMAJ'), ('dbkey', dataset.dbkey)])
|
||||
"posturl": "history_add_to?%s" % "&".join(f"{x[0]}={quote_plus(str(x[1]))}" for x in [('copy_access_from', dataset.id), ('history_id', dataset.history_id), ('ext', 'maf'), ('name', f'GMAJ Output on data {dataset.hid}'), ('info', 'Added by GMAJ'), ('dbkey', dataset.dbkey)])
|
||||
}
|
||||
class_name = "edu.psu.bx.gmaj.MajApplet.class"
|
||||
archive = "/static/gmaj/gmaj.jar"
|
||||
|
||||
@@ -103,7 +103,7 @@ class TabularData(data.Text):
|
||||
else:
|
||||
trans.response.set_content_type("text/html")
|
||||
return trans.stream_template_mako("/dataset/large_file.mako",
|
||||
truncated_data=open(dataset.file_name, mode='r').read(max_peek_size),
|
||||
truncated_data=open(dataset.file_name).read(max_peek_size),
|
||||
data=dataset)
|
||||
else:
|
||||
column_names = 'null'
|
||||
|
||||
@@ -250,13 +250,13 @@ class ProvidesUserFileSourcesUserContext:
|
||||
def role_names(self) -> Set[str]:
|
||||
"""The set of role names of this user."""
|
||||
user = self.trans.user
|
||||
return set(ura.role.name for ura in user.roles) if user else set()
|
||||
return {ura.role.name for ura in user.roles} if user else set()
|
||||
|
||||
@property
|
||||
def group_names(self) -> Set[str]:
|
||||
"""The set of group names to which this user belongs."""
|
||||
user = self.trans.user
|
||||
return set(ugr.group.name for ugr in user.groups) if user else set()
|
||||
return {ugr.group.name for ugr in user.groups} if user else set()
|
||||
|
||||
@property
|
||||
def is_admin(self):
|
||||
|
||||
@@ -539,12 +539,12 @@ class JobConfiguration(ConfiguresHandlers):
|
||||
self.limits.__dict__[limit_type] = types.get(limit_type, str)(limit_value)
|
||||
|
||||
if self.limits.walltime is not None:
|
||||
h, m, s = [int(v) for v in self.limits.walltime.split(':')]
|
||||
h, m, s = (int(v) for v in self.limits.walltime.split(':'))
|
||||
self.limits.walltime_delta = datetime.timedelta(0, s, 0, 0, m, h)
|
||||
|
||||
if "raw" in self.limits.total_walltime:
|
||||
h, m, s = [int(v) for v in
|
||||
self.limits.total_walltime["raw"].split(':')]
|
||||
h, m, s = (int(v) for v in
|
||||
self.limits.total_walltime["raw"].split(':'))
|
||||
self.limits.total_walltime["delta"] = datetime.timedelta(
|
||||
0, s, 0, 0, m, h
|
||||
)
|
||||
|
||||
@@ -110,7 +110,7 @@ class KubernetesJobRunner(AsynchronousJobRunner):
|
||||
volume_claims = dict(volume.split(":") for volume in self.runner_params['k8s_persistent_volume_claims'].split(','))
|
||||
else:
|
||||
volume_claims = {}
|
||||
mountable_volumes = list(set([claim_name if "/" not in claim_name else claim_name.split("/")[0] for claim_name in volume_claims]))
|
||||
mountable_volumes = list({claim_name if "/" not in claim_name else claim_name.split("/")[0] for claim_name in volume_claims})
|
||||
mountable_volumes = [{'name': claim_name, 'persistentVolumeClaim': {'claimName': claim_name}} for claim_name in mountable_volumes]
|
||||
self.runner_params['k8s_mountable_volumes'] = mountable_volumes
|
||||
volume_mounts = [{'name': claim_name, 'mountPath': mount_path} for claim_name, mount_path in volume_claims.items()]
|
||||
@@ -366,7 +366,7 @@ class KubernetesJobRunner(AsynchronousJobRunner):
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [{"name": "job-{}-{}".format(self.__force_label_conformity(ajs.job_wrapper.get_id_tag()), p),
|
||||
"ports": [{"name": f"job-{self.__force_label_conformity(ajs.job_wrapper.get_id_tag())}-{p}",
|
||||
"port": int(p),
|
||||
"protocol": "TCP",
|
||||
"targetPort": int(p)} for p in guest_ports],
|
||||
@@ -426,7 +426,7 @@ class KubernetesJobRunner(AsynchronousJobRunner):
|
||||
}
|
||||
}
|
||||
if self.runner_params.get("k8s_interactivetools_use_ssl"):
|
||||
domains = list(set([e["domain"] for e in entry_points]))
|
||||
domains = list({e["domain"] for e in entry_points})
|
||||
k8s_spec_template["spec"]["tls"] = [{"hosts": [domain],
|
||||
"secretName": re.sub("[^a-z0-9-]", "-", domain)} for domain in domains]
|
||||
if self.runner_params.get("k8s_interactivetools_ingress_annotations"):
|
||||
@@ -809,7 +809,7 @@ class KubernetesJobRunner(AsynchronousJobRunner):
|
||||
|
||||
def __cleanup_k8s_guest_ports(self, job_wrapper, k8s_job):
|
||||
k8s_job_prefix = self.__produce_k8s_job_prefix()
|
||||
k8s_job_name = "{}-{}".format(k8s_job_prefix, self.__force_label_conformity(job_wrapper.get_id_tag()))
|
||||
k8s_job_name = f"{k8s_job_prefix}-{self.__force_label_conformity(job_wrapper.get_id_tag())}"
|
||||
log.debug(f'Deleting service/ingress for job with ID {job_wrapper.get_id_tag()}')
|
||||
job_failed = (k8s_job.obj['status']['failed'] > 0
|
||||
if 'failed' in k8s_job.obj['status'] else False)
|
||||
|
||||
@@ -385,7 +385,7 @@ class PBSJobRunner(AsynchronousJobRunner):
|
||||
pbs_job_state.job_wrapper.change_state(model.Job.states.RUNNING)
|
||||
if status.job_state == "R" and status.get('resources_used', False):
|
||||
# resources_used may not be in the status for new jobs
|
||||
h, m, s = [int(i) for i in status.resources_used.walltime.split(':')]
|
||||
h, m, s = (int(i) for i in status.resources_used.walltime.split(':'))
|
||||
runtime = timedelta(0, s, 0, 0, m, h)
|
||||
if pbs_job_state.check_limits(runtime=runtime):
|
||||
self.work_queue.put((self.fail_job, pbs_job_state))
|
||||
|
||||
@@ -376,7 +376,7 @@ class PulsarJobRunner(AsynchronousJobRunner):
|
||||
remote_pulsar_app_config = dest_params.get("pulsar_app_config", {}).copy()
|
||||
if "pulsar_app_config_path" in dest_params:
|
||||
pulsar_app_config_path = dest_params["pulsar_app_config_path"]
|
||||
with open(pulsar_app_config_path, "r") as fh:
|
||||
with open(pulsar_app_config_path) as fh:
|
||||
remote_pulsar_app_config.update(yaml.safe_load(fh))
|
||||
job_directory_files = []
|
||||
config_files = job_wrapper.extra_filenames
|
||||
|
||||
@@ -305,7 +305,7 @@ class DatasetCollectionManager:
|
||||
try:
|
||||
self.hda_manager.error_unless_owner(dataset, user=trans.get_user(), current_history=trans.history)
|
||||
except HistoryDatasetAssociationNoHistoryException:
|
||||
log.info("Cannot delete HistoryDatasetAssociation {}, HistoryDatasetAssociation has no associated History, cannot verify owner".format(dataset.id))
|
||||
log.info(f"Cannot delete HistoryDatasetAssociation {dataset.id}, HistoryDatasetAssociation has no associated History, cannot verify owner")
|
||||
continue
|
||||
if not dataset.deleted:
|
||||
dataset.deleted = True
|
||||
|
||||
@@ -262,7 +262,7 @@ def gen_rank_fuzzy_counts(collection_type, fuzzy_count=None):
|
||||
return [None for rt in rank_collection_types]
|
||||
else:
|
||||
# This is a list...
|
||||
paired_count = sum([1 if rt == "paired" else 0 for rt in rank_collection_types])
|
||||
paired_count = sum(1 if rt == "paired" else 0 for rt in rank_collection_types)
|
||||
list_count = len(rank_collection_types) - paired_count
|
||||
paired_fuzzy_count_mult = 1 if paired_count == 0 else 2 << (paired_count - 1)
|
||||
list_fuzzy_count_mult = math.floor((fuzzy_count * 1.0) / paired_fuzzy_count_mult)
|
||||
|
||||
@@ -57,7 +57,7 @@ class GenomesManager:
|
||||
ext = index_extensions[index_type]
|
||||
index_filename = self._get_index_filename(id, tbl_entries, ext, index_type)
|
||||
try:
|
||||
with open(index_filename, mode='r') as f:
|
||||
with open(index_filename) as f:
|
||||
return f.read()
|
||||
except OSError:
|
||||
raise ReferenceDataError(f'Failed to load index file for {id}')
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
from operator import itemgetter
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
from pathlib import Path
|
||||
from typing import (
|
||||
Dict,
|
||||
|
||||
@@ -2488,7 +2488,7 @@ class History(Base, HasTags, Dictifiable, UsesAnnotations, HasName, Serializable
|
||||
if optimize:
|
||||
self.__add_datasets_optimized(datasets, genome_build=genome_build)
|
||||
if quota and self.user:
|
||||
disk_usage = sum([d.get_total_size() for d in datasets if is_hda(d)])
|
||||
disk_usage = sum(d.get_total_size() for d in datasets if is_hda(d))
|
||||
self.user.adjust_total_disk_usage(disk_usage)
|
||||
sa_session.add_all(datasets)
|
||||
if flush:
|
||||
@@ -3305,7 +3305,7 @@ class Dataset(StorableObject, Serializable, _HasTable):
|
||||
if rel_path is not None:
|
||||
if self.object_store.exists(self, extra_dir=rel_path, dir_only=True):
|
||||
for root, _, files in os.walk(self.extra_files_path):
|
||||
self.total_size += sum([os.path.getsize(os.path.join(root, file)) for file in files if os.path.exists(os.path.join(root, file))])
|
||||
self.total_size += sum(os.path.getsize(os.path.join(root, file)) for file in files if os.path.exists(os.path.join(root, file)))
|
||||
return self.total_size
|
||||
|
||||
def has_data(self):
|
||||
|
||||
@@ -119,7 +119,7 @@ class Tree(BaseTree):
|
||||
return True
|
||||
|
||||
def __len__(self):
|
||||
return sum([len(c[1]) for c in self.children])
|
||||
return sum(len(c[1]) for c in self.children)
|
||||
|
||||
def multiply(self, other_structure):
|
||||
if other_structure.is_leaf:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""
|
||||
Migration script for adding job_id column to dataset table.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class GalaxySeleniumContextImpl(GalaxySeleniumContext):
|
||||
|
||||
def init(config=None, clazz=GalaxySeleniumContextImpl) -> GalaxySeleniumContext:
|
||||
if os.path.exists("galaxy_selenium_context.yml"):
|
||||
with open("galaxy_selenium_context.yml", "r") as f:
|
||||
with open("galaxy_selenium_context.yml") as f:
|
||||
as_dict = yaml.safe_load(f)
|
||||
context = clazz(as_dict)
|
||||
else:
|
||||
|
||||
@@ -26,7 +26,7 @@ class GitContentBiotoolsMetadataSource(BiotoolsMetadataSource):
|
||||
path = os.path.join(self._content_directory, "data", biotools_reference, f"{biotools_reference}.biotools.json")
|
||||
if not os.path.exists(path):
|
||||
return None
|
||||
with open(path, "r") as f:
|
||||
with open(path) as f:
|
||||
content_json = json.load(f)
|
||||
return BiotoolsEntry.from_json(content_json)
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class CacheDirectory(metaclass=ABCMeta):
|
||||
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])
|
||||
return list(i for i in raw_images if i is not None)
|
||||
|
||||
@abstractmethod
|
||||
def list_cached_mulled_images_from_path(self):
|
||||
|
||||
@@ -217,12 +217,12 @@ def singularity_search(search_string):
|
||||
def readable_output(json, organization='biocontainers', channel='bioconda'):
|
||||
|
||||
# if json is empty:
|
||||
if sum([len(json[destination][results]) for destination in json for results in json[destination]]) == 0:
|
||||
if sum(len(json[destination][results]) for destination in json for results in json[destination]) == 0:
|
||||
sys.stdout.write('No results found for that query.\n')
|
||||
return
|
||||
|
||||
# return results for quay, conda and singularity together
|
||||
if sum([len(json[destination][results]) for destination in ['quay', 'conda', 'singularity', ] for results in json.get(destination, [])]) > 0:
|
||||
if sum(len(json[destination][results]) for destination in ['quay', 'conda', 'singularity', ] for results in json.get(destination, [])) > 0:
|
||||
sys.stdout.write("The query returned the following result(s).\n")
|
||||
# put quay, conda etc results as lists in lines
|
||||
lines = [['LOCATION', 'NAME', 'VERSION', 'COMMAND\n']]
|
||||
@@ -262,7 +262,7 @@ def readable_output(json, organization='biocontainers', channel='bioconda'):
|
||||
sys.stdout.write(
|
||||
"".join((line[0].ljust(col_width0), line[1]))) # output
|
||||
|
||||
if sum([len(json['github'][results]) for results in json.get('github', [])]) > 0:
|
||||
if sum(len(json['github'][results]) for results in json.get('github', [])) > 0:
|
||||
sys.stdout.write('\n' if 'lines' in locals() else '')
|
||||
sys.stdout.write(
|
||||
"Other result(s) on the bioconda-recipes GitHub repository:\n")
|
||||
|
||||
@@ -140,7 +140,7 @@ class ToolRequirements:
|
||||
return len(self.tool_requirements)
|
||||
|
||||
def __hash__(self):
|
||||
return sum([r.__hash__() for r in self.tool_requirements])
|
||||
return sum(r.__hash__() for r in self.tool_requirements)
|
||||
|
||||
def to_dict(self):
|
||||
return [r.to_dict() for r in self.tool_requirements]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import io
|
||||
import os
|
||||
from typing import Dict, Optional, TextIO
|
||||
|
||||
@@ -16,7 +15,7 @@ ROOT_TOPIC = 'topic_0003'
|
||||
def load_edam_tree(path: Optional[str] = None):
|
||||
if path is not None:
|
||||
assert os.path.exists(path), f"Failed to load EDAM tabular data at [{path}] path does not exist."
|
||||
handle = io.open(path, "r")
|
||||
handle = open(path)
|
||||
else:
|
||||
assert tabular_stream is not None, "Failed to load optional import from edam-onotology package, install using [pip install edam-ontology]."
|
||||
handle = tabular_stream()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
"""This module contains a linting functions for tool inputs."""
|
||||
from galaxy.util import string_as_bool
|
||||
from ._util import is_datasource, is_valid_cheetah_placeholder
|
||||
@@ -132,9 +131,9 @@ def lint_inputs(tool_xml, lint_ctx):
|
||||
# lint statically defined options
|
||||
if any(['value' not in option.attrib for option in select_options]):
|
||||
lint_ctx.error(f"Select parameter [{param_name}] has option without value")
|
||||
if len(set([option.text.strip() for option in select_options if option.text is not None])) != len(select_options):
|
||||
if len({option.text.strip() for option in select_options if option.text is not None}) != len(select_options):
|
||||
lint_ctx.error(f"Select parameter [{param_name}] has multiple options with the same text content")
|
||||
if len(set([option.attrib.get("value") for option in select_options])) != len(select_options):
|
||||
if len({option.attrib.get("value") for option in select_options}) != len(select_options):
|
||||
lint_ctx.error(f"Select parameter [{param_name}] has multiple options with the same value")
|
||||
|
||||
if param_attrib.get("display") == "checkboxes":
|
||||
|
||||
@@ -142,8 +142,7 @@ class EdamToolPanelView(ToolPanelView):
|
||||
if self.include_topics:
|
||||
edam.extend(tool.edam_topics)
|
||||
if len(edam) > 0:
|
||||
for term in edam:
|
||||
yield term
|
||||
yield from edam
|
||||
else:
|
||||
yield 'uncategorized'
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ class NotFoundCommand(Command):
|
||||
print('(try running python setup.py develop)')
|
||||
return 2
|
||||
print('Known commands:')
|
||||
longest = max([len(n) for n, c in commands])
|
||||
longest = max(len(n) for n, c in commands)
|
||||
for name, command in commands:
|
||||
print(f' {self.pad(name, length=longest)} {command.load().summary}')
|
||||
return 2
|
||||
|
||||
@@ -987,7 +987,7 @@ class BamDataProvider(GenomeDataProvider, FilterableMixin):
|
||||
seq = read.seq
|
||||
strand = decode_strand(read.flag, 0x0010)
|
||||
if read.cigar is not None:
|
||||
read_len = sum([cig[1] for cig in read.cigar]) # Use cigar to determine length
|
||||
read_len = sum(cig[1] for cig in read.cigar) # Use cigar to determine length
|
||||
else:
|
||||
read_len = len(seq) # If no cigar, just use sequence length
|
||||
|
||||
|
||||
@@ -308,10 +308,11 @@ class Supplement:
|
||||
wsgi_vars[name] = value
|
||||
if self.environ['wsgi.version'] != (1, 0):
|
||||
wsgi_vars['wsgi.version'] = self.environ['wsgi.version']
|
||||
proc_desc = tuple([int(bool(self.environ[key]))
|
||||
for key in ('wsgi.multiprocess',
|
||||
'wsgi.multithread',
|
||||
'wsgi.run_once')])
|
||||
proc_desc = tuple(int(bool(self.environ[key])) for key in (
|
||||
'wsgi.multiprocess',
|
||||
'wsgi.multithread',
|
||||
'wsgi.run_once'
|
||||
))
|
||||
wsgi_vars['wsgi process'] = self.process_combos[proc_desc]
|
||||
wsgi_vars['application'] = self.middleware.application
|
||||
if 'paste.config' in self.environ:
|
||||
|
||||
@@ -1471,7 +1471,7 @@ class UsesExtendedMetadataMixin(SharableItemSecurityMixin):
|
||||
else:
|
||||
# BUG: Everything is cast to string, which can lead to false positives
|
||||
# for cross type comparisions, ie "True" == True
|
||||
yield prefix, (f"{meta}").encode("utf8", errors='replace')
|
||||
yield prefix, (f"{meta}").encode()
|
||||
|
||||
|
||||
def sort_by_attr(seq, attr):
|
||||
|
||||
@@ -375,7 +375,7 @@ class LibraryContentsController(BaseGalaxyAPIController, UsesLibraryMixinItems,
|
||||
else:
|
||||
# BUG: Everything is cast to string, which can lead to false positives
|
||||
# for cross type comparisions, ie "True" == True
|
||||
yield prefix, (f"{meta}").encode("utf8", errors='replace')
|
||||
yield prefix, (f"{meta}").encode()
|
||||
|
||||
@expose_api
|
||||
def update(self, trans, id, library_id, payload, **kwd):
|
||||
|
||||
@@ -456,7 +456,7 @@ class LibraryDatasetsController(BaseGalaxyAPIController, UsesVisualizationMixin,
|
||||
path = os.path.join(full_dir, path)
|
||||
if unsafe_walk(path, allowlist=[full_dir] + trans.app.config.user_library_import_symlink_allowlist, username=username):
|
||||
# the path is a dir and contains files that symlink outside the user dir
|
||||
error = 'User attempted to import a path that resolves to a path outside of their import dir: %s -> %s' % (
|
||||
error = 'User attempted to import a path that resolves to a path outside of their import dir: {} -> {}'.format(
|
||||
path, os.path.realpath(path)
|
||||
)
|
||||
if trans.app.config.user_library_import_check_permissions:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
from typing import (
|
||||
List,
|
||||
Optional,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import logging
|
||||
|
||||
from galaxy import (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import logging
|
||||
|
||||
from galaxy import (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import logging
|
||||
from typing import (
|
||||
Optional,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import logging
|
||||
|
||||
from galaxy.managers.visualizations import (
|
||||
|
||||
@@ -52,7 +52,7 @@ class Tools(BaseUIController):
|
||||
return f"<font color=\"red\">{returned}</font>"
|
||||
return returned
|
||||
else:
|
||||
splited = tuple([float(_) for _ in str(date).split(':')])
|
||||
splited = tuple(float(_) for _ in str(date).split(':'))
|
||||
if splited[0]:
|
||||
returned = '%d h. %d min.' % splited[:2]
|
||||
if colored:
|
||||
|
||||
@@ -201,7 +201,7 @@ class HistoryPanelTestCase(SeleniumTestCase):
|
||||
|
||||
current_tags_size = len(close_tag_buttons)
|
||||
|
||||
errmsg = "there are more tags than expected! current {}, expected {}".format(current_tags_size, expected_tags_size)
|
||||
errmsg = f"there are more tags than expected! current {current_tags_size}, expected {expected_tags_size}"
|
||||
assert expected_tags_size == current_tags_size, errmsg
|
||||
|
||||
for close_btn in reversed(close_tag_buttons):
|
||||
|
||||
@@ -121,7 +121,7 @@ class HistoryGridTestCase(SharedStateSeleniumTestCase):
|
||||
@retry_assertion_during_transitions
|
||||
def assert_grid_histories_sorted_by_owner(self):
|
||||
histories = self.get_histories()
|
||||
index_1, index_2, index_3 = [histories.index(n) for n in self.all_histories]
|
||||
index_1, index_2, index_3 = (histories.index(n) for n in self.all_histories)
|
||||
# 1 and 3 are owned by a owner whose username lexicographically
|
||||
# precedes 2. So verify 1 and 3 come before 2.
|
||||
assert index_1 < index_2
|
||||
|
||||
@@ -162,14 +162,18 @@ class RepositoryMetadataManager(metadata_generator.MetadataGenerator):
|
||||
|
||||
def compare_data_manager(self, ancestor_metadata, current_metadata):
|
||||
"""Determine if ancestor_metadata is the same as or a subset of current_metadata for data_managers."""
|
||||
|
||||
def __data_manager_dict_to_tuple_list(metadata_dict):
|
||||
# we do not check tool_guid or tool conf file name
|
||||
return set(sorted([(name,
|
||||
tuple(sorted(value.get('data_tables', []))),
|
||||
value.get('guid'),
|
||||
value.get('version'),
|
||||
value.get('name'),
|
||||
value.get('id')) for name, value in metadata_dict.items()]))
|
||||
return set(sorted((
|
||||
name,
|
||||
tuple(sorted(value.get('data_tables', []))),
|
||||
value.get('guid'),
|
||||
value.get('version'),
|
||||
value.get('name'),
|
||||
value.get('id')
|
||||
) for name, value in metadata_dict.items()))
|
||||
|
||||
# only compare valid entries, any invalid entries are ignored
|
||||
ancestor_metadata = __data_manager_dict_to_tuple_list(ancestor_metadata.get('data_managers', {}))
|
||||
current_metadata = __data_manager_dict_to_tuple_list(current_metadata.get('data_managers', {}))
|
||||
|
||||
@@ -97,7 +97,7 @@ def display(api_key, url, return_formatted=True):
|
||||
print(' name: %s' % i.pop('name'))
|
||||
try:
|
||||
for k, v in i.items():
|
||||
print(' %s: %s' % (k, v))
|
||||
print(f' {k}: {v}')
|
||||
except AttributeError:
|
||||
for item in i:
|
||||
print(item)
|
||||
|
||||
@@ -131,7 +131,7 @@ class Uploader:
|
||||
# So that we can check if it really needs to be uploaded.
|
||||
already_uploaded = memo_key in self.memo_path.keys()
|
||||
fid = self.memoized_path(basepath, base_folder=self.folder_id)
|
||||
print('[{}/{}] {}/{} uploaded={}'.format(idx + 1, len(all_files), fid, fname, already_uploaded))
|
||||
print(f'[{idx + 1}/{len(all_files)}] {fid}/{fname} uploaded={already_uploaded}')
|
||||
|
||||
if not already_uploaded:
|
||||
if self.non_local:
|
||||
|
||||
@@ -19,7 +19,7 @@ IndexTuple = namedtuple('IndexTuple', 'table column_names')
|
||||
|
||||
|
||||
def tuple_from_index(index):
|
||||
columns = tuple([index.columns[key].name for key in index.columns.keys()])
|
||||
columns = tuple(index.columns[key].name for key in index.columns.keys())
|
||||
if len(columns) == 1:
|
||||
columns = columns[0]
|
||||
return IndexTuple(index.table.name, columns)
|
||||
|
||||
@@ -218,7 +218,7 @@ class Action:
|
||||
for causal, s in zip(self.causals, results[primary]):
|
||||
for r in sorted(s):
|
||||
secondaries = ', '.join('%s: %s' % x for x in zip(causal[1:], r[1:]))
|
||||
self.log.info('{} {} caused {}'.format(causal[0], r[0], secondaries))
|
||||
self.log.info(f'{causal[0]} {r[0]} caused {secondaries}')
|
||||
|
||||
def handle_results(self, cur):
|
||||
results = {}
|
||||
|
||||
@@ -39,7 +39,7 @@ def _dump_option(option, current_section_desc):
|
||||
print((" " * 6) + line)
|
||||
if "=" not in option:
|
||||
print(option)
|
||||
key, default = [s.strip() for s in option.split("=", 1)]
|
||||
key, default = (s.strip() for s in option.split("=", 1))
|
||||
key = key[1:] # strip #
|
||||
if default.strip().lower() in ["true", "false"]:
|
||||
default = default.lower()
|
||||
|
||||
@@ -358,16 +358,16 @@ class SwarmState:
|
||||
# there are no cpu constraints, so no calculation can be done
|
||||
return 0, 0
|
||||
for node in nodes:
|
||||
used += sum([t.cpus for t in node.non_terminal_tasks]) / self._cpus
|
||||
used += sum(t.cpus for t in node.non_terminal_tasks) / self._cpus
|
||||
total += node.cpus / self._cpus
|
||||
# need at least this many slots
|
||||
needed = used + self.get_limit(constraints, 'slots_min_spare')
|
||||
if (len(services) > self._conf.service_wait_count_limit
|
||||
and time.time() - self._waiting_since.get(constraints, time.time()) > self._conf.service_wait_time_limit):
|
||||
# add slots for waiting services that have exceeded limits
|
||||
needed += sum([s.cpus for s in services]) / self._cpus
|
||||
needed += sum(s.cpus for s in services) / self._cpus
|
||||
# subtract slots for spawning nodes
|
||||
needed -= sum([n.get('slots', 0) for n in self._spawning_nodes.get(constraints, {})])
|
||||
needed -= sum(n.get('slots', 0) for n in self._spawning_nodes.get(constraints, {}))
|
||||
# ensure no less than slots_min_limit slots will exist (free or used)
|
||||
needed = max(needed, self.get_limit(constraints, 'slots_min_limit'))
|
||||
# ensure no more than slots_max_limit slots will exist
|
||||
|
||||
@@ -86,7 +86,7 @@ def _get_uwsgi_args(cliargs, kwargs):
|
||||
'pythonpath': 'lib',
|
||||
'threads': '4',
|
||||
'buffer-size': '16384', # https://github.com/galaxyproject/galaxy/issues/1530
|
||||
'http': 'localhost:{port}'.format(port=DEFAULT_PORTS[cliargs.app]),
|
||||
'http': f'localhost:{DEFAULT_PORTS[cliargs.app]}',
|
||||
'static-map': (f'/static={os.getcwd()}/static',
|
||||
f'/favicon.ico={os.getcwd()}/static/favicon.ico'),
|
||||
'die-on-term': True,
|
||||
|
||||
+2
-2
@@ -29,10 +29,10 @@ helper = idencoding.IdEncodingHelper(id_secret=app_properties.get('id_secret'))
|
||||
model = galaxy.config.init_models_from_config(config)
|
||||
|
||||
if args.encode_id:
|
||||
print('Encoded "{}": {}'.format(args.encode_id, helper.encode_id(args.encode_id)))
|
||||
print(f'Encoded "{args.encode_id}": {helper.encode_id(args.encode_id)}')
|
||||
|
||||
if args.decode_id:
|
||||
print('Decoded "{}": {}'.format(args.decode_id, helper.decode_id(args.decode_id)))
|
||||
print(f'Decoded "{args.decode_id}": {helper.decode_id(args.decode_id)}')
|
||||
|
||||
if args.hda_id:
|
||||
try:
|
||||
|
||||
@@ -151,7 +151,7 @@ def process_FASTA(filename, org_num, refseq):
|
||||
|
||||
# Create Chrom Info File:
|
||||
chrom_info_file = open(os.path.join(os.path.split(filename)[0], "%s.info" % refseq), 'wb+')
|
||||
chrom_info_file.write("chromosome={}\nname={}\nlength={}\norganism={}\n".format(refseq, chr_name, len(fasta), org_num))
|
||||
chrom_info_file.write(f"chromosome={refseq}\nname={chr_name}\nlength={len(fasta)}\norganism={org_num}\n")
|
||||
try:
|
||||
chrom_info_file.write("gi=%s\n" % accesions['gi'])
|
||||
except Exception:
|
||||
|
||||
@@ -116,7 +116,7 @@ def get_bed_from_genbank(gb_file, chrom, feature_list):
|
||||
if not name:
|
||||
name = "unknown"
|
||||
|
||||
features[feature_type].append("{}\t{}\t{}\t{}\t{}\t{}".format(chrom, feature.start, feature.end, name, 0, feature.strand)) # append new bed field here
|
||||
features[feature_type].append(f"{chrom}\t{feature.start}\t{feature.end}\t{name}\t{0}\t{feature.strand}") # append new bed field here
|
||||
return features
|
||||
|
||||
|
||||
|
||||
@@ -79,16 +79,16 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
|
||||
return
|
||||
|
||||
# read object_store_info file
|
||||
with open(object_store_info_file, mode="r") as osi:
|
||||
with open(object_store_info_file) as osi:
|
||||
object_store_info = json.load(osi)
|
||||
osi_keys = tuple(object_store_info.keys())
|
||||
|
||||
# read irods_info_file
|
||||
with open(irods_info_file, mode="r") as ii:
|
||||
with open(irods_info_file) as ii:
|
||||
irods_info = json.load(ii)
|
||||
|
||||
# read db_connectin_info file
|
||||
with open(db_connection_info_file, mode="r") as dci:
|
||||
with open(db_connection_info_file) as dci:
|
||||
db_connection_info = json.load(dci)
|
||||
|
||||
try:
|
||||
|
||||
@@ -127,7 +127,7 @@ def _merge_summarizes(raw_data_dicts):
|
||||
|
||||
|
||||
def _prepare_raw_data(path):
|
||||
with open(path, "r") as f:
|
||||
with open(path) as f:
|
||||
inp_dict = json.load(f)
|
||||
environment = dict(raw_data=inp_dict, label=os.path.basename(path))
|
||||
__inject_summary(environment)
|
||||
@@ -261,12 +261,12 @@ def __inject_api_timing_summary_test(test):
|
||||
def __inject_statistics(from_dict):
|
||||
raw_values = from_dict['raw']
|
||||
from_dict['sum'] = sum(raw_values)
|
||||
from_dict['median'] = "{:.2f}".format(statistics.median(raw_values))
|
||||
from_dict['median'] = f"{statistics.median(raw_values):.2f}"
|
||||
if len(raw_values) > 1:
|
||||
from_dict['stdev'] = "{:.4f}".format(statistics.stdev(raw_values))
|
||||
from_dict['stdev'] = f"{statistics.stdev(raw_values):.4f}"
|
||||
else:
|
||||
from_dict['stdev'] = "n/a"
|
||||
from_dict['mean'] = "{:.2f}".format(statistics.mean(raw_values))
|
||||
from_dict['mean'] = f"{statistics.mean(raw_values):.2f}"
|
||||
from_dict['count'] = len(raw_values)
|
||||
return from_dict
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ def __main__():
|
||||
suffix = 're_match_multiline'
|
||||
else:
|
||||
suffix = 're_match'
|
||||
output = open("{}.{}".format(args[0], suffix), 'wb')
|
||||
output = open(f"{args[0]}.{suffix}", 'wb')
|
||||
if options.multiline:
|
||||
lines = [re.escape(input.read())]
|
||||
else:
|
||||
|
||||
@@ -24,10 +24,10 @@ def main(trans, webhook, params):
|
||||
content = urlopen(url).read()
|
||||
soap = BeautifulSoup(content, 'html.parser')
|
||||
pattern = r'(?:http://www\.phdcomics\.com/comics\.php\?f=)(\d+)'
|
||||
webhook.config['latest_id'] = max([
|
||||
webhook.config['latest_id'] = max(
|
||||
int(re.search(pattern, link.text).group(1))
|
||||
for link in soap.find_all('link', text=re.compile(pattern))
|
||||
])
|
||||
)
|
||||
|
||||
random_id = random.randint(1, webhook.config['latest_id'])
|
||||
url = 'http://www.phdcomics.com/comics/archive.php?comicid=%d' % \
|
||||
|
||||
@@ -178,7 +178,7 @@ class ScriptsIntegrationTestCase(integration_util.IntegrationTestCase):
|
||||
return unicodify(subprocess.check_output(cmd, cwd=cwd, env=clean_env))
|
||||
except Exception as e:
|
||||
if isinstance(e, subprocess.CalledProcessError):
|
||||
raise Exception("{}\nOutput was:\n{}".format(unicodify(e), unicodify(e.output)))
|
||||
raise Exception(f"{unicodify(e)}\nOutput was:\n{unicodify(e.output)}")
|
||||
raise
|
||||
|
||||
def write_config_file(self):
|
||||
|
||||
@@ -54,7 +54,7 @@ class AdminToolDataIntegrationTestCase(integration_util.IntegrationTestCase):
|
||||
time.sleep(2)
|
||||
show_response = self._get("tool_data/testbeta")
|
||||
updated_fields = show_response.json()["fields"]
|
||||
self.assertEquals(len(updated_fields), original_count + 1)
|
||||
self.assertEqual(len(updated_fields), original_count + 1)
|
||||
new_field = updated_fields[-1]
|
||||
url = self._api_url(f"tool_data/testbeta?key={self.galaxy_interactor.api_key}")
|
||||
|
||||
|
||||
@@ -124,5 +124,5 @@ input1:
|
||||
name: fasta1
|
||||
text_input: foo
|
||||
""", history_id=history_id)
|
||||
invocation = self._get("/invocations/{}".format(invocation_response.invocation_id)).json()
|
||||
invocation = self._get(f"/invocations/{invocation_response.invocation_id}").json()
|
||||
assert 'wf_output_1' in invocation['output_collections']
|
||||
|
||||
@@ -43,7 +43,7 @@ class TestCommandFactory(TestCase):
|
||||
self.include_work_dir_outputs = False
|
||||
dep_commands = [". /opt/galaxy/tools/bowtie/default/env.sh"]
|
||||
self.job_wrapper.dependency_shell_commands = dep_commands
|
||||
self.__assert_command_is(_surround_command("{}; {}; return_code=$?".format(dep_commands[0], MOCK_COMMAND_LINE)))
|
||||
self.__assert_command_is(_surround_command(f"{dep_commands[0]}; {MOCK_COMMAND_LINE}; return_code=$?"))
|
||||
|
||||
def test_shell_commands_external(self):
|
||||
self.job_wrapper.commands_in_new_shell = True
|
||||
@@ -55,7 +55,7 @@ class TestCommandFactory(TestCase):
|
||||
self.job_wrapper.shell,
|
||||
self.job_wrapper.working_directory,
|
||||
)))
|
||||
self.__assert_tool_script_is("#!/bin/sh\n{}; {}".format(dep_commands[0], MOCK_COMMAND_LINE))
|
||||
self.__assert_tool_script_is(f"#!/bin/sh\n{dep_commands[0]}; {MOCK_COMMAND_LINE}")
|
||||
|
||||
def test_remote_dependency_resolution(self):
|
||||
self.include_work_dir_outputs = False
|
||||
@@ -67,7 +67,7 @@ class TestCommandFactory(TestCase):
|
||||
self.include_work_dir_outputs = False
|
||||
dep_commands = [". /opt/galaxy/tools/bowtie/default/env.sh"]
|
||||
self.job_wrapper.dependency_shell_commands = dep_commands
|
||||
self.__assert_command_is(_surround_command("{}; {}; return_code=$?".format(dep_commands[0], MOCK_COMMAND_LINE)),
|
||||
self.__assert_command_is(_surround_command(f"{dep_commands[0]}; {MOCK_COMMAND_LINE}; return_code=$?"),
|
||||
remote_command_params=dict(dependency_resolution="local"))
|
||||
|
||||
def test_task_prepare_inputs(self):
|
||||
|
||||
@@ -327,7 +327,7 @@ class AdvancedJobConfXmlParserTestCase(BaseJobConfXmlParserTestCase):
|
||||
|
||||
def test_destination_tags(self):
|
||||
self._with_advanced_config()
|
||||
longjob_dests_ids = sorted([j.id for j in self.job_config.destinations["longjobs"]])
|
||||
longjob_dests_ids = sorted(j.id for j in self.job_config.destinations["longjobs"])
|
||||
assert len(longjob_dests_ids) == 2
|
||||
assert longjob_dests_ids[0] == "pbs_longjobs"
|
||||
assert longjob_dests_ids[1] == "remote_cluster"
|
||||
|
||||
@@ -127,7 +127,7 @@ def __assert_mapper_errors_with_message(mapper, message):
|
||||
except Exception as e:
|
||||
exception = e
|
||||
assert exception
|
||||
assert str(exception) == message, "{} != {}".format(str(exception), message)
|
||||
assert str(exception) == message, f"{str(exception)} != {message}"
|
||||
|
||||
|
||||
def __mapper(tool_job_destination=TOOL_JOB_DESTINATION):
|
||||
|
||||
@@ -67,7 +67,7 @@ def assert_realizes_as(file_sources, uri, expected, user_context=None):
|
||||
file_source_path = file_sources.get_file_source_path(uri)
|
||||
with tempfile.NamedTemporaryFile(mode='r') as temp:
|
||||
file_source_path.file_source.realize_to(file_source_path.path, temp.name, user_context=user_context)
|
||||
with open(temp.name, "r") as f:
|
||||
with open(temp.name) as f:
|
||||
realized_contents = f.read()
|
||||
if realized_contents != expected:
|
||||
message = "Expected to realize contents at [{}] as [{}], instead found [{}]".format(
|
||||
|
||||
@@ -257,7 +257,7 @@ def test_posix_user_access_requires_role():
|
||||
user_context = user_context_fixture()
|
||||
_assert_user_access_prohibited(file_sources, user_context)
|
||||
|
||||
user_context = user_context_fixture(role_names=set([allowed_role_name]))
|
||||
user_context = user_context_fixture(role_names={allowed_role_name})
|
||||
_assert_user_access_granted(file_sources, user_context)
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ def test_posix_user_access_requires_group():
|
||||
user_context = user_context_fixture()
|
||||
_assert_user_access_prohibited(file_sources, user_context)
|
||||
|
||||
user_context = user_context_fixture(group_names=set([allowed_group_name]))
|
||||
user_context = user_context_fixture(group_names={allowed_group_name})
|
||||
_assert_user_access_granted(file_sources, user_context)
|
||||
|
||||
|
||||
@@ -298,13 +298,13 @@ def test_posix_user_access_requires_role_and_group():
|
||||
}
|
||||
file_sources = _configured_file_sources(writable=True, plugin_extra_config=plugin_extra_config)
|
||||
|
||||
user_context = user_context_fixture(group_names=set([allowed_group_name]))
|
||||
user_context = user_context_fixture(group_names={allowed_group_name})
|
||||
_assert_user_access_prohibited(file_sources, user_context)
|
||||
|
||||
user_context = user_context_fixture(role_names=set([allowed_role_name]))
|
||||
user_context = user_context_fixture(role_names={allowed_role_name})
|
||||
_assert_user_access_prohibited(file_sources, user_context)
|
||||
|
||||
user_context = user_context_fixture(role_names=set([allowed_role_name]), group_names=set([allowed_group_name]))
|
||||
user_context = user_context_fixture(role_names={allowed_role_name}, group_names={allowed_group_name})
|
||||
_assert_user_access_granted(file_sources, user_context)
|
||||
|
||||
|
||||
@@ -316,32 +316,32 @@ def test_posix_user_access_using_boolean_rules():
|
||||
file_sources = _configured_file_sources(writable=True, plugin_extra_config=plugin_extra_config)
|
||||
|
||||
user_context = user_context_fixture(
|
||||
role_names=set([]),
|
||||
group_names=set([])
|
||||
role_names=set(),
|
||||
group_names=set()
|
||||
)
|
||||
_assert_user_access_prohibited(file_sources, user_context)
|
||||
|
||||
user_context = user_context_fixture(
|
||||
role_names=set(["role1"]),
|
||||
group_names=set(["group1", "group2"])
|
||||
role_names={"role1"},
|
||||
group_names={"group1", "group2"}
|
||||
)
|
||||
_assert_user_access_prohibited(file_sources, user_context)
|
||||
|
||||
user_context = user_context_fixture(
|
||||
role_names=set(["role1", "role3"]),
|
||||
group_names=set(["group1", "group2", "group3"])
|
||||
role_names={"role1", "role3"},
|
||||
group_names={"group1", "group2", "group3"}
|
||||
)
|
||||
_assert_user_access_prohibited(file_sources, user_context)
|
||||
|
||||
user_context = user_context_fixture(
|
||||
role_names=set(["role1", "role2"]),
|
||||
group_names=set(["group3", "group5"])
|
||||
role_names={"role1", "role2"},
|
||||
group_names={"group3", "group5"}
|
||||
)
|
||||
_assert_user_access_prohibited(file_sources, user_context)
|
||||
|
||||
user_context = user_context_fixture(
|
||||
role_names=set(["role1", "role3"]),
|
||||
group_names=set(["group1", "group2"])
|
||||
role_names={"role1", "role3"},
|
||||
group_names={"group1", "group2"}
|
||||
)
|
||||
_assert_user_access_granted(file_sources, user_context)
|
||||
|
||||
|
||||
@@ -796,4 +796,4 @@ def _assert_has_keys(the_dict, keys):
|
||||
|
||||
def _assert_key_has_value(the_dict, key, value):
|
||||
assert key in the_dict, f"dict [{key}] doesn't container expected key [{the_dict}]"
|
||||
assert the_dict[key] == value, "{} != {}".format(the_dict[key], value)
|
||||
assert the_dict[key] == value, f"{the_dict[key]} != {value}"
|
||||
|
||||
Reference in New Issue
Block a user