def get_node_namespace(): """Return the full namespace of all available nodes in the current database. :return: complete node `Namespace` """ from aiida import orm from aiida.plugins.entry_point import is_valid_entry_point_string, parse_entry_point_string builder = orm.QueryBuilder().append(orm.Node, project=['node_type', 'process_type']).distinct() unique_types = {(node_type, process_type if process_type else '') for node_type, process_type in builder.all()} # First we create a flat list of all "leaf" node types. namespaces = [] for node_type, process_type in unique_types: label = None namespace = None if process_type: # Process nodes parts = node_type.rsplit('.', 2) if is_valid_entry_point_string(process_type): _, entry_point_name = parse_entry_point_string(process_type) label = entry_point_name.rpartition('.')[-1] namespace = '.'.join(parts[:-2] + [entry_point_name]) else: label = process_type.rsplit('.', 1)[-1] namespace = '.'.join(parts[:-2] + [DEFAULT_NAMESPACE_LABEL, label]) else: # Data nodes parts = node_type.rsplit('.', 2) try: label = parts[-2] namespace = '.'.join(parts[:-2]) except IndexError: continue full_type = construct_full_type(node_type, process_type) namespaces.append((namespace, label, full_type)) node_namespace = Namespace('node') for namespace, label, full_type in sorted(namespaces, key=lambda x: x[0], reverse=False): node_namespace.create_namespace(namespace, label=label, full_type=full_type) return node_namespace
def test_plugin_list_detail(run_cli_command, entry_point_string): """Test the `verdi plugin list` command for specific entry points.""" from aiida.plugins.entry_point import parse_entry_point_string entry_point_group, entry_point_name = parse_entry_point_string( entry_point_string) factory = CalculationFactory if entry_point_group == 'aiida.calculations' else WorkflowFactory entry_point = factory(entry_point_name) result = run_cli_command(cmd_plugin.plugin_list, [entry_point_group, entry_point_name]) assert entry_point.__doc__ in result.output
def get_node_namespace(user_pk=None, count_nodes=False): """Return the full namespace of all available nodes in the current database. :return: complete node `Namespace` """ # pylint: disable=too-many-branches from aiida import orm from aiida.plugins.entry_point import is_valid_entry_point_string, parse_entry_point_string filters = {} if user_pk is not None: filters['user_id'] = user_pk builder = orm.QueryBuilder().append(orm.Node, filters=filters, project=['node_type', 'process_type']).distinct() # All None instances of process_type are turned into '' unique_types = {(node_type, process_type if process_type else '') for node_type, process_type in builder.all()} # First we create a flat list of all "leaf" node types. namespaces = [] for node_type, process_type in unique_types: label = None counter = None namespace = None if process_type: # Only process nodes parts = node_type.rsplit('.', 2) if is_valid_entry_point_string(process_type): _, entry_point_name = parse_entry_point_string(process_type) label = entry_point_name.rpartition('.')[-1] namespace = '.'.join(parts[:-2] + [entry_point_name]) else: label = process_type.rsplit('.', 1)[-1] namespace = '.'.join(parts[:-2] + [DEFAULT_NAMESPACE_LABEL, process_type]) else: # Data nodes and process nodes without process type (='' or =None) parts = node_type.rsplit('.', 2) try: label = parts[-2] namespace = '.'.join(parts[:-2]) except IndexError: continue if count_nodes: builder = orm.QueryBuilder() concat_filters = [{'node_type': {'==': node_type}}] if node_type.startswith('process.'): if process_type: concat_filters.append({'process_type': {'==': process_type}}) else: concat_filters.append({'process_type': {'or': [{'==': ''}, {'==': None}]}}) if user_pk: concat_filters.append({'user_id': {'==': user_pk}}) if len(concat_filters) == 1: builder.append(orm.Node, filters=concat_filters[0]) else: builder.append(orm.Node, filters={'and': concat_filters}) counter = builder.count() full_type = construct_full_type(node_type, process_type) namespaces.append((namespace, label, full_type, counter)) node_namespace = Namespace('node') for namespace, label, full_type, counter in sorted(namespaces, key=lambda x: x[0], reverse=False): node_namespace.create_namespace(namespace, label=label, full_type=full_type, counter=counter) return node_namespace