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 theentry_point_name_filter
keyword. The actual command for each entry point is defined bycommand
, which should take as a first argument the class that corresponds to the entry point. In addition, it should acceptkwargs
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'#
- 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
.
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 theconfig
andprofile
attributes.This class guarantees that the
config
andprofile
attributes never raise anAttributeError
. When the attributes are accessed when they are not set,config
is initialized by the value returned by the methodaiida.manage.configuration.get_config()
. Theprofile
attribute is initialized toNone
.- _KEY_CONFIG = 'config'#
- _KEY_PROFILE = 'profile'#
- __getattr__(attr: str) Any [source]#
Override of
AttributeDict.__getattr__
to lazily initialize theconfig
andprofile
attributes.- Parameters:
attr – The attribute to return.
- Returns:
The value of the attribute.
- Raises:
AttributeError – If the attribute does not correspond to an existing key.
click.exceptions.UsageError – If loading of the configuration fails.
- __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.VerdiCommand(name: str | None, context_settings: MutableMapping[str, Any] | None = None, callback: Callable[[...], Any] | None = None, params: List[Parameter] | None = None, help: str | None = None, epilog: str | None = None, short_help: str | None = None, options_metavar: str | None = '[OPTIONS]', add_help_option: bool = True, no_args_is_help: bool = False, hidden: bool = False, deprecated: bool = False)[source]#
Bases:
Command
Custom command implementation to customize the logic of printing deprecation messages.
If a command is deprecated, the
click.Command
adds a deprecation marker in the short help and the full help text, and prints a deprecation warning when the command is invoked. The problem is that the deprecation warning is printed after the prompting for parameters, which for interactive commands mean the deprecation warning comes too late, when the user has already provided all prompts.Here, the
click.Command.parse_args()
method is overridden, which is called before the interactive options start to prompt, such that the deprecation warning can be printed. Theclick.Command.invoke()
method is also overridden in order to skip the printing of the deprecation message handled byclick
as that would result in the deprecation message being printed twice.- __annotations__ = {}#
- __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 theverdi
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 allverdi
commands.
- command_class#
alias of
VerdiCommand
- 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.