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)[源代码]#

基类: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)[源代码]#
__module__ = 'aiida.cmdline.groups.dynamic'#
call_command(ctx, cls, **kwargs)[源代码]#

Call the command after validating the provided inputs.

create_command(ctx: Context, entry_point: str) Command[源代码]#

Create a subcommand for the given entry_point.

static create_option(name, spec: dict) Callable[[Any], Any][源代码]#

Create a click option from a name and a specification.

create_options(entry_point: str) Callable[源代码]#

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

参数:

entry_point – The entry point.

get_command(ctx: Context, cmd_name: str) Command | None[源代码]#

Return the command with the given name.

参数:
  • ctx – The click.Context.

  • cmd_name – The name of the command.

返回:

The click.Command.

list_commands(ctx: Context) list[str][源代码]#

Return the sorted list of subcommands for this group.

参数:

ctx – The click.Context.

list_options(entry_point: str) list[源代码]#

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

参数:

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)[源代码]#

基类: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[源代码]#

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

参数:

attr – The attribute to return.

返回:

The value of the attribute.

抛出:
__init__(ctx: Context, dictionary: dict[str, Any] | None = None)[源代码]#

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)[源代码]#

基类: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[源代码]#

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

context_class#

VerdiContext 的别名

fail_with_suggestions(ctx: Context, cmd_name: str) None[源代码]#

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

get_command(ctx: Context, cmd_name: str) Command | None[源代码]#

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[源代码]#

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)[源代码]#

基类:Context

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

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