aiida.cmdline.groups package#

Module with custom implementations of click.Group.

Submodules#

Subclass of click.Group that loads subcommands dynamically from entry points.

class aiida.cmdline.groups.dynamic.DynamicEntryPointCommandGroup(command: Callable, entry_point_group: str, entry_point_name_filter: str = '.*', shared_options: list[Option] | None = None, **kwargs)[source]#

Bases: VerdiCommandGroup

Subclass of click.Group that loads subcommands dynamically from entry points.

A command group using this class will automatically generate the sub commands from the entry points registered in the given entry_point_group. The entry points can be additionally filtered using a regex defined for the entry_point_name_filter keyword. The actual command for each entry point is defined by command, which should take as a first argument the class that corresponds to the entry point. In addition, it should accept kwargs which will be the values for the options passed when the command is invoked. The help string of the command will be provided by the docstring of the class registered at the respective entry point. Example usage:

def create_instance(cls, **kwargs):
    instance = cls(**kwargs)
    instance.store()
    echo.echo_success(f'Created {cls.__name__}<{instance.pk}>')

@click.group('create', cls=DynamicEntryPointCommandGroup, command=create_instance,)
def cmd_create():
    pass
__annotations__ = {}#
__init__(command: Callable, entry_point_group: str, entry_point_name_filter: str = '.*', shared_options: list[Option] | None = None, **kwargs)[source]#
__module__ = 'aiida.cmdline.groups.dynamic'#
call_command(ctx, cls, **kwargs)[source]#

Call the command after validating the provided inputs.

create_command(ctx: Context, entry_point: str) Command[source]#

Create a subcommand for the given entry_point.

static create_option(name, spec: dict) Callable[[Any], Any][source]#

Create a click option from a name and a specification.

create_options(entry_point: str) Callable[source]#

Create the option decorators for the command function for the given entry point.

Parameters:

entry_point – The entry point.

get_command(ctx: Context, cmd_name: str) Command | None[source]#

Return the command with the given name.

Parameters:
  • ctx – The click.Context.

  • cmd_name – The name of the command.

Returns:

The click.Command.

list_commands(ctx: Context) list[str][source]#

Return the sorted list of subcommands for this group.

Parameters:

ctx – The click.Context.

list_options(entry_point: str) list[source]#

Return the list of options that should be applied to the command for the given entry point.

Parameters:

entry_point – The entry point.

Subclass of click.Group for the verdi CLI.

class aiida.cmdline.groups.verdi.LazyVerdiObjAttributeDict(ctx: Context, dictionary: dict[str, Any] | None = None)[source]#

Bases: AttributeDict

Subclass of AttributeDict that lazily initializes the config and profile attributes.

This class guarantees that the config and profile attributes never raise an AttributeError. When the attributes are accessed when they are not set, config is initialized by the value returned by the method aiida.manage.configuration.get_config(). The profile attribute is initialized to None.

_KEY_CONFIG = 'config'#
_KEY_PROFILE = 'profile'#
__getattr__(attr: str) Any[source]#

Override of AttributeDict.__getattr__ to lazily initialize the config and profile attributes.

Parameters:

attr – The attribute to return.

Returns:

The value of the attribute.

Raises:
__init__(ctx: Context, dictionary: dict[str, Any] | None = None)[source]#

Recursively turn the dict and all its nested dictionaries into AttributeDict instance.

__module__ = 'aiida.cmdline.groups.verdi'#
class aiida.cmdline.groups.verdi.VerdiCommandGroup(name: str | None = None, commands: MutableMapping[str, Command] | Sequence[Command] | None = None, **attrs: Any)[source]#

Bases: Group

Subclass of click.Group for the verdi CLI.

The class automatically adds the verbosity option to all commands in the interface. It also adds some functionality to provide suggestions of commands in case the user provided command name does not exist.

__annotations__ = {}#
__module__ = 'aiida.cmdline.groups.verdi'#
static add_verbosity_option(cmd: Command) Command[source]#

Apply the verbosity option to the command, which is common to all verdi commands.

context_class#

alias of VerdiContext

fail_with_suggestions(ctx: Context, cmd_name: str) None[source]#

Fail the command while trying to suggest commands to resemble the requested cmd_name.

get_command(ctx: Context, cmd_name: str) Command | None[source]#

Return the command that corresponds to the requested cmd_name.

This method is overridden from the base class in order to two functionalities:

  • If the command is found, automatically add the verbosity option.

  • If the command is not found, attempt to provide a list of suggestions with existing commands that resemble the requested command name.

Note that if the command is not found and resilient_parsing is set to True on the context, then the latter feature is disabled because most likely we are operating in tab-completion mode.

group(*args, **kwargs) Group[source]#

Ensure that sub command groups use the same class but do not override an explicitly set value.

class aiida.cmdline.groups.verdi.VerdiContext(*args, **kwargs)[source]#

Bases: Context

Custom context implementation that defines the obj user object and adds the Config instance.

__annotations__ = {}#
__init__(*args, **kwargs)[source]#
__module__ = 'aiida.cmdline.groups.verdi'#