Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroupPaths: A class to provide attribute/key access to Groups, with delimited labels. #3613

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci/workchains.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
# pylint: disable=invalid-name
from aiida.common import AttributeDict
from aiida.engine import calcfunction, workfunction, WorkChain, ToContext, append_, while_, ExitCode
from aiida.engine import BaseRestartWorkChain, process_handler, ProcessHandlerReport
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=bad-continuation,locally-disabled,useless-suppression,django-not-available,bad-option-value,logging-format-interpolation,no-else-raise,import-outside-toplevel
disable=bad-continuation,locally-disabled,useless-suppression,django-not-available,bad-option-value,logging-format-interpolation,no-else-raise,import-outside-toplevel,cyclic-import

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
69 changes: 69 additions & 0 deletions aiida/cmdline/commands/cmd_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,72 @@ def group_copy(source_group, destination_group):
# Copy nodes
dest_group.add_nodes(list(source_group.nodes))
echo.echo_success('Nodes copied from group<{}> to group<{}>'.format(source_group.label, dest_group.label))


@verdi_group.group('path')
def verdi_group_path():
"""Inspect groups of nodes, with delimited label paths."""


@verdi_group_path.command('ls')
@click.argument('path', type=click.STRING, required=False)
@click.option('-R', '--recursive', is_flag=True, default=False, help='Recursively list sub-paths encountered')
@click.option('-l', '--long', 'as_table', is_flag=True, default=False, help='List as a table, with sub-group count')
@click.option(
'-d', '--with-description', 'with_description', is_flag=True, default=False, help='Show also the group description'
)
@click.option(
'--no-virtual',
'no_virtual',
is_flag=True,
default=False,
help='Only show paths that fully correspond to an existing group'
)
@click.option(
'-t',
'--type',
'group_type',
type=types.LazyChoice(valid_group_type_strings),
default=user_defined_group,
help='Show groups of a specific type, instead of user-defined groups. Start with semicolumn if you want to '
'specify aiida-internal type'
)
chrisjsewell marked this conversation as resolved.
Show resolved Hide resolved
@click.option('--no-warn', is_flag=True, default=False, help='Do not issue a warning if any paths are invalid.')
@with_dbenv()
def group_path_ls(path, recursive, as_table, no_virtual, group_type, with_description, no_warn):
# pylint: disable=too-many-arguments
"""Show a list of existing group paths."""
from aiida.tools.groups.paths import GroupPath, InvalidPath

try:
path = GroupPath(path or '', type_string=group_type, warn_invalid_child=not no_warn)
except InvalidPath as err:
echo.echo_critical(str(err))

if recursive:
children = path.walk()
else:
children = path.children

if as_table or with_description:
from tabulate import tabulate
headers = ['Path', 'Sub-Groups']
if with_description:
headers.append('Description')
rows = []
for child in sorted(children):
if no_virtual and child.is_virtual:
continue
row = [
child.path if child.is_virtual else click.style(child.path, bold=True),
len([c for c in child.walk() if not c.is_virtual])
]
if with_description:
row.append('-' if child.is_virtual else child.get_group().description)
rows.append(row)
echo.echo(tabulate(rows, headers=headers))
else:
for child in sorted(children):
if no_virtual and child.is_virtual:
continue
echo.echo(child.path, bold=not child.is_virtual)
11 changes: 11 additions & 0 deletions aiida/tools/groups/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is part of the AiiDA code. #
ramirezfranciscof marked this conversation as resolved.
Show resolved Hide resolved
# #
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core #
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
# pylint: disable=wildcard-import,undefined-variable
"""Provides tools for interacting with AiiDA Groups."""
from .paths import *

__all__ = paths.__all__
Loading