Faster and cleaner set creation

This commit is contained in:
Nicola Soranzo
2020-02-03 15:42:09 +00:00
parent 3c7c18b7ed
commit f32ece1e8d
32 changed files with 45 additions and 45 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ class ContainerPort(namedtuple('ContainerPort', ('port', 'protocol', 'hostaddr',
class ContainerVolume(with_metaclass(ABCMeta, object)):
valid_modes = frozenset(["ro", "rw"])
valid_modes = frozenset({"ro", "rw"})
def __init__(self, path, host_path=None, mode=None):
self.path = path
+1 -1
View File
@@ -1738,7 +1738,7 @@ class GAFASQLite(SQlite):
def sniff(self, filename):
if super(IdpDB, self).sniff(filename):
table_names = frozenset(['gene', 'gene_family', 'gene_family_member', 'meta', 'transcript'])
table_names = frozenset({'gene', 'gene_family', 'gene_family_member', 'meta', 'transcript'})
return self.sniff_table_names(filename, table_names)
return False
@@ -652,7 +652,7 @@ class SamtoolsDataProvider(line.RegexLineDataProvider):
# strip out any user supplied bash switch formating -> string of option chars
# then compress to single option string of unique, VALID flags with prefixed bash switch char '-'
options_string = options_string.strip('- ')
validated_flag_list = set([flag for flag in options_string if flag in self.FLAGS_WO_ARGS])
validated_flag_list = {flag for flag in options_string if flag in self.FLAGS_WO_ARGS}
# if sam add -S
# TODO: not the best test in the world...
+2 -2
View File
@@ -147,7 +147,7 @@ class CollectlProcessSummarizer(object):
def __init__(self, pid, statistics):
self.pid = pid
self.statistics = statistics
self.columns_of_interest = set([s[1] for s in statistics])
self.columns_of_interest = {s[1] for s in statistics}
self.tree_statistics = collections.defaultdict(stats.StatisticsTracker)
self.process_accum_statistics = collections.defaultdict(stats.StatisticsTracker)
self.interval_count = 0
@@ -206,7 +206,7 @@ class CollectlProcessSummarizer(object):
return process_rows
def __all_child_pids(self, rows, pid):
pids_in_process_tree = set([str(self.pid)])
pids_in_process_tree = {str(self.pid)}
added = True
while added:
added = False
+2 -2
View File
@@ -96,10 +96,10 @@ class JobHandlerQueue(Monitors):
self.__initialize_job_grabbing()
def __initialize_job_grabbing(self):
grabbable_methods = set([
grabbable_methods = {
HANDLER_ASSIGNMENT_METHODS.DB_TRANSACTION_ISOLATION,
HANDLER_ASSIGNMENT_METHODS.DB_SKIP_LOCKED,
])
}
try:
method = [m for m in self.app.job_config.handler_assignment_methods if m in grabbable_methods][0]
except IndexError:
+1 -1
View File
@@ -29,7 +29,7 @@ log = logging.getLogger(__name__)
__all__ = ('DRMAAJobRunner',)
RETRY_EXCEPTIONS_LOWER = frozenset(['invalidjobexception', 'internalexception'])
RETRY_EXCEPTIONS_LOWER = frozenset({'invalidjobexception', 'internalexception'})
class DRMAAJobRunner(AsynchronousJobRunner):
+2 -2
View File
@@ -551,7 +551,7 @@ class ModelSerializer(HasAModelManager):
# this allows us to: 'mention' the key without adding the default serializer
# TODO: we may want to eventually error if a key is requested
# that is in neither serializable_keyset or serializers
self.serializable_keyset = set([])
self.serializable_keyset = set()
# a map of dictionary keys to the functions (often lambdas) that create the values for those keys
self.serializers = {}
# add subclass serializers defined there
@@ -719,7 +719,7 @@ class ModelDeserializer(HasAModelManager):
self.app = app
self.deserializers = {}
self.deserializable_keyset = set([])
self.deserializable_keyset = set()
self.add_deserializers()
# a sub object that can validate incoming values
self.validate = validator or ModelValidator(self.app)
+2 -2
View File
@@ -228,11 +228,11 @@ class PageContentProcessor(HTMLParser, object):
For now, processor renders embedded objects.
"""
bare_ampersand = re.compile(r"&(?!#\d+;|#x[0-9a-fA-F]+;|\w+;)")
elements_no_end_tag = set([
elements_no_end_tag = {
'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame',
'hr', 'img', 'input', 'isindex', 'keygen', 'link', 'meta', 'param',
'source', 'track', 'wbr'
])
}
def __init__(self, trans, render_embed_html_fn):
HTMLParser.__init__(self)
+1 -1
View File
@@ -427,7 +427,7 @@ class SharableModelDeserializer(base.ModelDeserializer,
unencoded_ids = [self.app.security.decode_id(id_) for id_ in val]
new_users_shared_with = set(self.manager.user_manager.by_ids(unencoded_ids))
current_shares = self.manager.get_share_assocs(item)
currently_shared_with = set([share.user for share in current_shares])
currently_shared_with = {share.user for share in current_shares}
needs_adding = new_users_shared_with - currently_shared_with
for user in needs_adding:
+2 -2
View File
@@ -942,7 +942,7 @@ class WorkflowContentsManager(UsesAnnotations):
# Encode input connections as dictionary
input_conn_dict = {}
unique_input_names = set([conn.input_name for conn in input_connections])
unique_input_names = {conn.input_name for conn in input_connections}
for input_name in unique_input_names:
input_conn_dicts = []
for conn in input_connections:
@@ -1133,7 +1133,7 @@ class WorkflowContentsManager(UsesAnnotations):
steps_by_external_id[external_id] = step
if 'workflow_outputs' in step_dict:
workflow_outputs = step_dict['workflow_outputs']
found_output_names = set([])
found_output_names = set()
for workflow_output in workflow_outputs:
# Allow workflow outputs as list of output_names for backward compatibility.
if not isinstance(workflow_output, dict):
+1 -1
View File
@@ -2170,7 +2170,7 @@ class Dataset(StorableObject, RepresentById):
)
ready_states = tuple(set(states.__dict__.values()) - set(non_ready_states))
valid_input_states = tuple(
set(states.__dict__.values()) - set([states.ERROR, states.DISCARDED])
set(states.__dict__.values()) - {states.ERROR, states.DISCARDED}
)
terminal_states = (
states.OK,
+1 -1
View File
@@ -50,7 +50,7 @@ class TagHandler(object):
def remove_tags_from_list(self, user, item, tag_to_remove_list):
tag_to_remove_set = set(tag_to_remove_list)
tags_set = set([_.strip() for _ in self.get_tags_str(item.tags).split(',')])
tags_set = {_.strip() for _ in self.get_tags_str(item.tags).split(',')}
if item.tags:
tags_set -= tag_to_remove_set
return self.set_tags_from_list(user, item, tags_set)
+1 -1
View File
@@ -274,7 +274,7 @@ def reload_tour(app, **kwargs):
def __job_rule_module_names(app):
rules_module_names = set(['galaxy.jobs.rules'])
rules_module_names = {'galaxy.jobs.rules'}
if app.job_config.dynamic_params is not None:
module_name = app.job_config.dynamic_params.get('rules_module')
if module_name:
@@ -925,7 +925,7 @@ class InstallRepositoryManager(object):
self.update_tool_shed_repository_status(tool_shed_repository,
self.install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES)
new_tools = [self.app.toolbox._tools_by_id.get(tool_d['guid'], None) for tool_d in metadata['tools']]
new_requirements = set([tool.requirements.packages for tool in new_tools if tool])
new_requirements = {tool.requirements.packages for tool in new_tools if tool}
[self._view.install_dependencies(r) for r in new_requirements]
dependency_manager = self.app.toolbox.dependency_manager
if dependency_manager.cached:
+1 -1
View File
@@ -109,7 +109,7 @@ def type_representation_from_name(type_representation_name):
def type_descriptions_for_field_types(field_types):
type_representation_names = set([])
type_representation_names = set()
for field_type in field_types:
if isinstance(field_type, dict) and field_type.get("type"):
field_type = field_type.get("type")
@@ -130,7 +130,7 @@ def get_affected_packages(args):
hours = args.diff_hours
cmd = ['git', 'log', '--diff-filter=ACMRTUXB', '--name-only', '--pretty=""', '--since="%s hours ago"' % hours]
changed_files = subprocess.check_output(cmd, cwd=recipes_dir).strip().split('\n')
pkg_list = set([x for x in changed_files if x.startswith('recipes/') and x.endswith('meta.yaml')])
pkg_list = {x for x in changed_files if x.startswith('recipes/') and x.endswith('meta.yaml')}
for pkg in pkg_list:
if pkg and os.path.exists(os.path.join(recipes_dir, pkg)):
yield (get_pkg_name(args, pkg), get_tests(args, pkg))
+1 -1
View File
@@ -151,7 +151,7 @@ class CondaDependencyResolver(DependencyResolver, MultipleDependencyResolver, Li
all_resolved = [r for r in all_resolved if r.dependency_type]
if not all_resolved:
return None
environments = set([os.path.basename(dependency.environment_path) for dependency in all_resolved])
environments = {os.path.basename(dependency.environment_path) for dependency in all_resolved}
return self.uninstall_environments(environments)
def uninstall_environments(self, environments):
+1 -1
View File
@@ -263,7 +263,7 @@ class ToolBox(BaseGalaxyToolBox):
@property
def all_requirements(self):
reqs = set([req for _, tool in self.tools() for req in tool.tool_requirements])
reqs = {req for _, tool in self.tools() for req in tool.tool_requirements}
return [r.to_dict() for r in reqs]
@property
+1 -1
View File
@@ -82,7 +82,7 @@ def validate_url(url, ip_whitelist):
# AF_* family: It will resolve to AF_INET or AF_INET6, getaddrinfo(3) doesn't even mention AF_UNIX,
# socktype: We don't care if a stream/dgram/raw protocol
# protocol: we don't care if it is tcp or udp.
addrinfo_results = set([info[4][0] for info in addrinfo])
addrinfo_results = {info[4][0] for info in addrinfo}
# There may be multiple (e.g. IPv4 + IPv6 or DNS round robin). Any one of these
# could resolve to a local addresses (and could be returned by chance),
# therefore we must check them all.
+2 -2
View File
@@ -921,8 +921,8 @@ def parse_resource_parameters(resource_param_file):
# asbool implementation pulled from PasteDeploy
truthy = frozenset(['true', 'yes', 'on', 'y', 't', '1'])
falsy = frozenset(['false', 'no', 'off', 'n', 'f', '0'])
truthy = frozenset({'true', 'yes', 'on', 'y', 't', '1'})
falsy = frozenset({'false', 'no', 'off', 'n', 'f', '0'})
def asbool(obj):
@@ -28,13 +28,13 @@ from galaxy.util.bunch import Bunch
IS_OS_X = _platform == "darwin"
CONTAINER_NAME_PREFIX = 'gie_'
ENV_OVERRIDE_CAPITALIZE = frozenset([
ENV_OVERRIDE_CAPITALIZE = frozenset({
'notebook_username',
'notebook_password',
'dataset_hid',
'dataset_filename',
'additional_ids',
])
})
log = logging.getLogger(__name__)
+2 -2
View File
@@ -228,10 +228,10 @@ class UWSGIApplicationStack(MessageApplicationStack):
Note that mules will use this as their stack class even though they start with the "webless" loading point.
"""
name = 'uWSGI'
prohibited_middleware = frozenset([
prohibited_middleware = frozenset({
'wrap_in_static',
'EvalException',
])
})
transport_class = UWSGIFarmMessageTransport
log_filter_class = UWSGILogFilter
log_format = '%(name)s %(levelname)s %(asctime)s [p:%(process)s,w:%(worker_id)s,m:%(mule_id)s] [%(threadName)s] %(message)s'
+1 -1
View File
@@ -68,7 +68,7 @@ class DatatypesController(BaseAPIController):
visit_bases(types, base)
for c in classes:
n = c.__module__ + "." + c.__name__
types = set([n])
types = {n}
visit_bases(types, c)
class_to_classes[n] = dict((t, True) for t in types)
return dict(ext_to_class_name=ext_to_class_name, class_to_classes=class_to_classes)
+1 -1
View File
@@ -234,7 +234,7 @@ class HistoriesController(BaseAPIController, ExportsHistoryMixin, ImportsHistory
the history.
"""
history = self.manager.get_accessible(self.decode_id(history_id), trans.user, current_history=trans.history)
tool_ids = set([])
tool_ids = set()
for dataset in history.datasets:
job = dataset.creating_job
if not job:
@@ -246,7 +246,7 @@ class ToolDependenciesAPIController(BaseAPIController):
"""
tools_by_id = trans.app.toolbox.tools_by_id.copy()
tool_ids = payload.get("tool_ids")
requirements = set([tools_by_id[tid].tool_requirements for tid in tool_ids])
requirements = {tools_by_id[tid].tool_requirements for tid in tool_ids}
install_kwds = {}
for source in [payload, kwds]:
if 'include_containers' in source:
@@ -280,7 +280,7 @@ class ToolDependenciesAPIController(BaseAPIController):
"""
tools_by_id = trans.app.toolbox.tools_by_id.copy()
tool_ids = payload.get("tool_ids")
requirements = set([tools_by_id[tid].tool_requirements for tid in tool_ids])
requirements = {tools_by_id[tid].tool_requirements for tid in tool_ids}
install_kwds = {}
for source in [payload, kwds]:
if 'include_containers' in source:
+2 -2
View File
@@ -302,7 +302,7 @@ class WorkflowsAPIController(BaseAPIController, UsesStoredWorkflowMixin, UsesAnn
:param use_cached_job: If set to True galaxy will attempt to find previously executed steps for all workflow steps with the exact same parameter combinations
and will copy the outputs of the previously executed step.
"""
ways_to_create = set([
ways_to_create = {
'archive_source',
'workflow_id',
'installed_repository_file',
@@ -310,7 +310,7 @@ class WorkflowsAPIController(BaseAPIController, UsesStoredWorkflowMixin, UsesAnn
'from_path',
'shared_workflow_id',
'workflow',
])
}
if len(ways_to_create.intersection(payload)) == 0:
message = "One parameter among - %s - must be specified" % ", ".join(ways_to_create)
@@ -1602,7 +1602,7 @@ class AdminGalaxy(controller.JSAppLauncher, AdminActions, UsesQuotaMixin, QuotaP
# install the dependencies for the tools in the selected_tool_ids list
if not isinstance(selected_tool_ids, list):
selected_tool_ids = [selected_tool_ids]
requirements = set([tools_by_id[tid].tool_requirements for tid in selected_tool_ids])
requirements = {tools_by_id[tid].tool_requirements for tid in selected_tool_ids}
if install_dependencies:
[view.install_dependencies(r) for r in requirements]
elif uninstall_dependencies:
@@ -1003,7 +1003,7 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
elif target_history_ids:
if not isinstance(target_history_ids, list):
target_history_ids = target_history_ids.split(",")
target_history_ids = list(set([self.decode_id(h) for h in target_history_ids if h]))
target_history_ids = list({self.decode_id(h) for h in target_history_ids if h})
else:
target_history_ids = []
done_msg = error_msg = ""
+4 -4
View File
@@ -77,22 +77,22 @@ def test_choose_one_unhashed():
rule_helper = __rule_helper()
# Random choices if hash not set.
chosen_ones = set([])
chosen_ones = set()
__do_a_bunch(lambda: chosen_ones.add(rule_helper.choose_one(['a', 'b'])))
assert chosen_ones == set(['a', 'b'])
assert chosen_ones == {'a', 'b'}
def test_choose_one_hashed():
rule_helper = __rule_helper()
# Hashed, so all choosen ones should be the same...
chosen_ones = set([])
chosen_ones = set()
__do_a_bunch(lambda: chosen_ones.add(rule_helper.choose_one(['a', 'b'], hash_value=1234)))
assert len(chosen_ones) == 1
# ... also can verify hashing on strings
chosen_ones = set([])
chosen_ones = set()
__do_a_bunch(lambda: chosen_ones.add(rule_helper.choose_one(['a', 'b'], hash_value="i am a string")))
assert len(chosen_ones) == 1
+1 -1
View File
@@ -5,4 +5,4 @@ def test_dummy():
t = galaxy.containers.parse_containers_config('')
assert t == {'_default_': {'type': 'docker'}}
s = galaxy.containers.docker_model.DockerAttributeContainer()
assert s.members == frozenset([])
assert s.members == frozenset()
+1 -1
View File
@@ -140,7 +140,7 @@ def test_tool_requirements():
assert tool_requirements_ab == ToolRequirements([REQUIREMENT_B, REQUIREMENT_A])
assert tool_requirements_ab == ToolRequirements([REQUIREMENT_B, REQUIREMENT_A, REQUIREMENT_A])
assert tool_requirements_ab != tool_requirements_b
assert len(set([tool_requirements_ab, tool_requirements_ab_dup])) == 1
assert len({tool_requirements_ab, tool_requirements_ab_dup}) == 1
def test_module_dependency_resolver():
+1 -1
View File
@@ -94,7 +94,7 @@ def annotate_locus(input, minorallelefrequency, snpsfile):
genotypes = v.values()
alleles = [y for x in genotypes for y in x]
alleleset = list(set(alleles))
alleleset = list(set(alleles) - set(["N", "X"]))
alleleset = list(set(alleles) - {'N', 'X'})
if len(alleleset) == 2:
genotypevec = ""