aiida.cmdline

The command line interface of AiiDA.

Package Contents

Classes

AbsolutePathParamType

The ParamType for identifying absolute Paths (derived from click.Path).

CalculationParamType

The ParamType for identifying Calculation entities or its subclasses

CodeParamType

The ParamType for identifying Code entities or its subclasses

ComputerParamType

The ParamType for identifying Computer entities or its subclasses

ConfigOptionParamType

ParamType for configuration options.

DataParamType

The ParamType for identifying Data entities or its subclasses

DynamicEntryPointCommandGroup

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

EmailType

Parameter whose values have to correspond to a valid email address format.

EntryPointType

Parameter whose values have to be valid Python entry point strings.

FileOrUrl

Extension of click’s File-type to include URLs.

GroupParamType

The ParamType for identifying Group entities or its subclasses.

HostnameType

Parameter corresponding to a valid hostname (or empty) string.

IdentifierParamType

An extension of click.ParamType for a generic identifier parameter. In AiiDA, orm entities can often be identified by either their ID, UUID or optionally some LABEL identifier. This parameter type implements the convert method, which attempts to convert a value passed to the command for a parameter with this type, to an orm entity. The actual loading of the entity is delegated to the orm class loader. Subclasses of this parameter type should implement the orm_class_loader method to return the appropriate orm class loader, which should be a subclass of aiida.orm.utils.loaders.OrmEntityLoader for the corresponding orm class.

LabelStringType

Parameter accepting valid label strings.

LazyChoice

This is a delegate of click’s Choice ParamType that evaluates the set of choices lazily. This is useful if the choices set requires an import that is slow. Using the vanilla click.Choice will call this on import which will slow down verdi and its autocomplete. This type will generate the choices set lazily through the choices property

MpirunCommandParamType

Custom click param type for mpirun-command

MultipleValueParamType

An extension of click.ParamType that can parse multiple values for a given ParamType

NodeParamType

The ParamType for identifying Node entities or its subclasses

NonEmptyStringParamType

Parameter whose values have to be string and non-empty.

PathOrUrl

Extension of click’s Path-type to include URLs.

PluginParamType

AiiDA Plugin name parameter type.

ProcessParamType

The ParamType for identifying ProcessNode entities or its subclasses

ProfileParamType

The profile parameter type for click.

ShebangParamType

Custom click param type for shebang line

UserParamType

The user parameter type for click. Can get or create a user.

VerdiCommandGroup

Subclass of click.Group for the verdi CLI.

WorkflowParamType

The ParamType for identifying WorkflowNode entities or its subclasses

Functions

dbenv

Loads the dbenv for a specific region of code, does not unload afterwards

echo_critical

Log a critical error message to the cmdline logger and exit with exit_status.

echo_dictionary

Log the given dictionary to stdout in the given format

echo_error

Log an error message to the cmdline logger.

echo_info

Log an info message to the cmdline logger.

echo_report

Log an report message to the cmdline logger.

echo_success

Log a success message to the cmdline logger.

echo_warning

Log a warning message to the cmdline logger.

format_call_graph

Print a tree like the POSIX tree command for the calculation call graph

is_verbose

Return whether the configured logging verbosity is considered verbose, i.e., equal or lower to INFO level.

only_if_daemon_running

Function decorator for CLI command to print critical error and exit automatically when daemon is not running.

with_dbenv

Function decorator that will load the database environment for the currently loaded profile.

API

class aiida.cmdline.AbsolutePathParamType

Bases: click.Path

The ParamType for identifying absolute Paths (derived from click.Path).

name = 'AbsolutePath'
convert(value, param, ctx)
__repr__()
class aiida.cmdline.CalculationParamType

Bases: aiida.cmdline.params.types.identifier.IdentifierParamType

The ParamType for identifying Calculation entities or its subclasses

name = 'Calculation'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns:

the orm entity loader class for this ParamType

class aiida.cmdline.CodeParamType(sub_classes=None, entry_point=None)

Bases: aiida.cmdline.params.types.identifier.IdentifierParamType

The ParamType for identifying Code entities or its subclasses

Initialization

Construct the param type

Parameters:
  • sub_classes – specify a tuple of Code sub classes to narrow the query set

  • entry_point – specify an optional calculation entry point that the Code’s input plugin should match

name = 'Code'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns:

the orm entity loader class for this ParamType

shell_complete(ctx, param, incomplete)

Return possible completions based on an incomplete value.

Returns:

list of tuples of valid entry points (matching incomplete) and a description

convert(value, param, ctx)
class aiida.cmdline.ComputerParamType

Bases: aiida.cmdline.params.types.identifier.IdentifierParamType

The ParamType for identifying Computer entities or its subclasses

name = 'Computer'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns:

the orm entity loader class for this ParamType

shell_complete(ctx, param, incomplete)

Return possible completions based on an incomplete value.

Returns:

list of tuples of valid entry points (matching incomplete) and a description

class aiida.cmdline.ConfigOptionParamType

Bases: click.types.StringParamType

ParamType for configuration options.

name = 'config option'
convert(value, param, ctx)
shell_complete(ctx, param, incomplete)

Return possible completions based on an incomplete value

Returns:

list of tuples of valid entry points (matching incomplete) and a description

class aiida.cmdline.DataParamType(sub_classes=None)

Bases: aiida.cmdline.params.types.identifier.IdentifierParamType

The ParamType for identifying Data entities or its subclasses

Initialization

Construct the parameter type, optionally specifying a tuple of entry points that reference classes that should be a sub class of the base orm class of the orm class loader. The classes pointed to by these entry points will be passed to the OrmEntityLoader when converting an identifier and they will restrict the query set by demanding that the class of the corresponding entity matches these sub classes.

To prevent having to load the database environment at import time, the actual loading of the entry points is deferred until the call to convert is made. This is to keep the command line autocompletion light and responsive. The entry point strings will be validated, however, to see if the correspond to known entry points.

Parameters:

sub_classes – a tuple of entry point strings that can narrow the set of orm classes that values will be mapped upon. These classes have to be strict sub classes of the base orm class defined by the orm class loader

name = 'Data'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns:

the orm entity loader class for this ParamType

class aiida.cmdline.DynamicEntryPointCommandGroup(command, entry_point_group: str, entry_point_name_filter='.*', **kwargs)

Bases: aiida.cmdline.groups.verdi.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

Initialization

list_commands(ctx) list[str]

Return the sorted list of subcommands for this group.

Parameters:

ctx – The click.Context.

get_command(ctx, cmd_name)

Return the command with the given name.

Parameters:
  • ctx – The click.Context.

  • cmd_name – The name of the command.

Returns:

The click.Command.

create_command(entry_point)

Create a subcommand for the given entry_point.

create_options(entry_point)

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

Parameters:

entry_point – The entry point.

list_options(entry_point)

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

Parameters:

entry_point – The entry point.

static create_option(name, spec)

Create a click option from a name and a specification.

class aiida.cmdline.EmailType

Bases: click.types.StringParamType

Parameter whose values have to correspond to a valid email address format.

Note

For the moment, we do not require the domain suffix, i.e. ‘aiida@localhost’ is still valid.

name = 'email'
convert(value, param, ctx)
__repr__()
class aiida.cmdline.EntryPointType

Bases: aiida.cmdline.params.types.strings.NonEmptyStringParamType

Parameter whose values have to be valid Python entry point strings.

See https://packaging.python.org/en/latest/specifications/entry-points/

name = 'entrypoint'
convert(value, param, ctx)
__repr__()
class aiida.cmdline.FileOrUrl(timeout_seconds=URL_TIMEOUT_SECONDS, **kwargs)

Bases: click.File

Extension of click’s File-type to include URLs.

Returns handle either to local file or to remote file fetched from URL.

Parameters:

timeout_seconds (int) – Maximum timeout accepted for URL response. Must be an integer in the range [0;60].

Initialization

name = 'FileOrUrl'
convert(value, param, ctx)

Return file handle.

get_url(url, param, ctx)

Retrieve file from URL.

class aiida.cmdline.GroupParamType(create_if_not_exist=False, sub_classes=('aiida.groups:core',))

Bases: aiida.cmdline.params.types.identifier.IdentifierParamType

The ParamType for identifying Group entities or its subclasses.

Initialization

Construct the parameter type.

The sub_classes argument can be used to narrow the set of subclasses of Group that should be matched. By default all subclasses of Group will be matched, otherwise it is restricted to the subclasses that correspond to the entry point names in the tuple of sub_classes.

To prevent having to load the database environment at import time, the actual loading of the entry points is deferred until the call to convert is made. This is to keep the command line autocompletion light and responsive. The entry point strings will be validated, however, to see if they correspond to known entry points.

Parameters:
  • create_if_not_exist – boolean, if True, will create the group if it does not yet exist. By default the group created will be of class Group, unless another subclass is specified through sub_classes. Note that in this case, only a single entry point name can be specified

  • sub_classes – a tuple of entry point strings from the aiida.groups entry point group.

name = 'Group'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader.

This class is supposed to be used to load the entity for a given identifier.

Returns:

the orm entity loader class for this ParamType

shell_complete(ctx, param, incomplete)

Return possible completions based on an incomplete value.

Returns:

list of tuples of valid entry points (matching incomplete) and a description

convert(value, param, ctx)
class aiida.cmdline.HostnameType

Bases: click.types.StringParamType

Parameter corresponding to a valid hostname (or empty) string.

Regex according to https://stackoverflow.com/a/3824105/1069467

name = 'hostname'
convert(value, param, ctx)
__repr__()
class aiida.cmdline.IdentifierParamType(sub_classes=None)

Bases: click.ParamType, abc.ABC

An extension of click.ParamType for a generic identifier parameter. In AiiDA, orm entities can often be identified by either their ID, UUID or optionally some LABEL identifier. This parameter type implements the convert method, which attempts to convert a value passed to the command for a parameter with this type, to an orm entity. The actual loading of the entity is delegated to the orm class loader. Subclasses of this parameter type should implement the orm_class_loader method to return the appropriate orm class loader, which should be a subclass of aiida.orm.utils.loaders.OrmEntityLoader for the corresponding orm class.

Initialization

Construct the parameter type, optionally specifying a tuple of entry points that reference classes that should be a sub class of the base orm class of the orm class loader. The classes pointed to by these entry points will be passed to the OrmEntityLoader when converting an identifier and they will restrict the query set by demanding that the class of the corresponding entity matches these sub classes.

To prevent having to load the database environment at import time, the actual loading of the entry points is deferred until the call to convert is made. This is to keep the command line autocompletion light and responsive. The entry point strings will be validated, however, to see if the correspond to known entry points.

Parameters:

sub_classes – a tuple of entry point strings that can narrow the set of orm classes that values will be mapped upon. These classes have to be strict sub classes of the base orm class defined by the orm class loader

abstract property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns:

the orm entity loader class for this ParamType

convert(value, param, ctx)

Attempt to convert the given value to an instance of the orm class using the orm class loader.

Returns:

the loaded orm entity

Raises:
  • click.BadParameter – if the value is ambiguous and leads to multiple entities

  • click.BadParameter – if the value cannot be mapped onto any existing instance

  • RuntimeError – if the defined orm class loader is not a subclass of the OrmEntityLoader class

class aiida.cmdline.LabelStringType

Bases: aiida.cmdline.params.types.strings.NonEmptyStringParamType

Parameter accepting valid label strings.

Non-empty string, made up of word characters (includes underscores [1]), dashes, and dots.

[1] See https://docs.python.org/3/library/re.html

name = 'labelstring'
ALPHABET = '\\w\\.\\-'
convert(value, param, ctx)
__repr__()
class aiida.cmdline.LazyChoice(get_choices)

Bases: click.ParamType

This is a delegate of click’s Choice ParamType that evaluates the set of choices lazily. This is useful if the choices set requires an import that is slow. Using the vanilla click.Choice will call this on import which will slow down verdi and its autocomplete. This type will generate the choices set lazily through the choices property

Initialization

name = 'choice'
property _click_choice

Get the internal click Choice object that we delegate functionality to. Will construct it lazily if necessary.

Returns:

The click Choice

Return type:

click.Choice

property choices
get_metavar(param)
get_missing_message(param)
convert(value, param, ctx)
__repr__()
class aiida.cmdline.MpirunCommandParamType

Bases: click.types.StringParamType

Custom click param type for mpirun-command

Note

requires also a scheduler to be provided, and the scheduler must be called first!

Validate that the provided ‘mpirun’ command only contains replacement fields (e.g. {tot_num_mpiprocs}) that are known.

Return a list of arguments (by using ‘value.strip().split(” “) on the input string)

name = 'mpiruncommandstring'
__repr__()
convert(value, param, ctx)
class aiida.cmdline.MultipleValueParamType(param_type)

Bases: click.ParamType

An extension of click.ParamType that can parse multiple values for a given ParamType

Initialization

get_metavar(param)
convert(value, param, ctx)
class aiida.cmdline.NodeParamType

Bases: aiida.cmdline.params.types.identifier.IdentifierParamType

The ParamType for identifying Node entities or its subclasses

name = 'Node'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns:

the orm entity loader class for this ParamType

class aiida.cmdline.NonEmptyStringParamType

Bases: click.types.StringParamType

Parameter whose values have to be string and non-empty.

name = 'nonemptystring'
convert(value, param, ctx)
__repr__()
class aiida.cmdline.PathOrUrl(timeout_seconds=URL_TIMEOUT_SECONDS, **kwargs)

Bases: click.Path

Extension of click’s Path-type to include URLs.

A PathOrUrl can either be a click.Path-type or a URL.

Parameters:

timeout_seconds (int) – Maximum timeout accepted for URL response. Must be an integer in the range [0;60].

Initialization

name = 'PathOrUrl'
convert(value, param, ctx)

Overwrite convert Check first if click.Path-type, then check if URL.

checks_url(url, param, ctx)

Check whether URL is reachable within timeout.

class aiida.cmdline.PluginParamType(group=None, load=False, *args, **kwargs)

Bases: aiida.cmdline.params.types.strings.EntryPointType

AiiDA Plugin name parameter type.

Parameters:
  • group – string or tuple of strings, where each is a valid entry point group. Adding the aiida. prefix is optional. If it is not detected it will be prepended internally.

  • load – when set to True, convert will not return the entry point, but the loaded entry point

Usage:

click.option(... type=PluginParamType(group='aiida.calculations')

or:

click.option(... type=PluginParamType(group=('calculations', 'data'))

Initialization

Validate that group is either a string or a tuple of valid entry point groups, or if it is not specified use the tuple of all recognized entry point groups.

name = 'plugin'
_factory_mapping = None
_init_entry_points()

Populate entry point information that will be used later on. This should only be called once in the constructor after setting self.groups because the groups should not be changed after instantiation

property groups
property has_potential_ambiguity

Returns whether the set of supported entry point groups can lead to ambiguity when only an entry point name is specified. This will happen if one ore more groups share an entry point with a common name

get_valid_arguments()

Return a list of all available plugins for the groups configured for this PluginParamType instance. If the entry point names are not unique, because there are multiple groups that contain an entry point that has an identical name, we need to prefix the names with the full group name

Returns:

list of valid entry point strings

get_possibilities(incomplete='')

Return a list of plugins starting with incomplete

shell_complete(ctx, param, incomplete)

Return possible completions based on an incomplete value

Returns:

list of tuples of valid entry points (matching incomplete) and a description

get_missing_message(param)
get_entry_point_from_string(entry_point_string)

Validate a given entry point string, which means that it should have a valid entry point string format and that the entry point unambiguously corresponds to an entry point in the groups configured for this instance of PluginParameterType.

Returns:

the entry point if valid

Raises:

ValueError if the entry point string is invalid

validate_entry_point_group(group)
convert(value, param, ctx)

Convert the string value to an entry point instance, if the value can be successfully parsed into an actual entry point. Will raise click.BadParameter if validation fails.

class aiida.cmdline.ProcessParamType

Bases: aiida.cmdline.params.types.identifier.IdentifierParamType

The ParamType for identifying ProcessNode entities or its subclasses

name = 'Process'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns:

the orm entity loader class for this ParamType

class aiida.cmdline.ProfileParamType(*args, **kwargs)

Bases: aiida.cmdline.params.types.strings.LabelStringType

The profile parameter type for click.

This parameter type requires the command that uses it to define the context_class class attribute to be the aiida.cmdline.groups.verdi.VerdiContext class, as that is responsible for creating the user defined object obj on the context and loads the instance config.

Initialization

name = 'profile'
static deconvert_default(value)
convert(value, param, ctx)

Attempt to match the given value to a valid profile.

shell_complete(ctx, param, incomplete)

Return possible completions based on an incomplete value

Returns:

list of tuples of valid entry points (matching incomplete) and a description

class aiida.cmdline.ShebangParamType

Bases: click.types.StringParamType

Custom click param type for shebang line

name = 'shebangline'
convert(value, param, ctx)
__repr__()
class aiida.cmdline.UserParamType(create=False)

Bases: click.ParamType

The user parameter type for click. Can get or create a user.

Initialization

Parameters:

create – If the user does not exist, create a new instance (unstored).

name = 'user'
convert(value, param, ctx)
shell_complete(ctx, param, incomplete)

Return possible completions based on an incomplete value

Returns:

list of tuples of valid entry points (matching incomplete) and a description

class aiida.cmdline.VerdiCommandGroup

Bases: click.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.

context_class = None
static add_verbosity_option(cmd)

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

fail_with_suggestions(ctx, cmd_name)

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

get_command(ctx, cmd_name)

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)

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

class aiida.cmdline.WorkflowParamType

Bases: aiida.cmdline.params.types.identifier.IdentifierParamType

The ParamType for identifying WorkflowNode entities or its subclasses

name = 'WorkflowNode'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns:

the orm entity loader class for this ParamType

aiida.cmdline.dbenv()

Loads the dbenv for a specific region of code, does not unload afterwards

Only use when it makes it possible to avoid loading the dbenv for certain code paths

Good Example:

# do this
@click.command()
@click.option('--with-db', is_flag=True)
def profile_info(with_db):
    # read the config file
    click.echo(profile_config)

    # load the db only if necessary
    if with_db:
        with dbenv():
            # gather db statistics for the profile
            click.echo(db_statistics)

This will run very fast without the –with-db flag and slow only if database info is requested

Do not use if you will end up loading the dbenv anyway

Bad Example:

# don't do this
def my_function():
    with dbenv():
        # read from db

    # do db unrelated stuff
aiida.cmdline.echo_critical(message: str, bold: bool = False, nl: bool = True, err: bool = True, prefix: bool = True) None

Log a critical error message to the cmdline logger and exit with exit_status.

This should be used to print messages for errors that cannot be recovered from and so the script should be directly terminated with a non-zero exit status to indicate that the command failed.

Parameters:
  • message – the message to log.

  • bold – whether to format the message in bold.

  • nl – whether to add a newline at the end of the message.

  • err – whether to log to stderr.

  • prefix – whether the message should be prefixed with a colored version of the log level.

aiida.cmdline.echo_dictionary(dictionary, fmt='json+date', sort_keys=True)

Log the given dictionary to stdout in the given format

Parameters:
  • dictionary – the dictionary

  • fmt – the format to use for printing

  • sort_keys – Whether to automatically sort keys

aiida.cmdline.echo_error(message: str, bold: bool = False, nl: bool = True, err: bool = True, prefix: bool = True) None

Log an error message to the cmdline logger.

Parameters:
  • message – the message to log.

  • bold – whether to format the message in bold.

  • nl – whether to add a newline at the end of the message.

  • err – whether to log to stderr.

  • prefix – whether the message should be prefixed with a colored version of the log level.

aiida.cmdline.echo_info(message: str, bold: bool = False, nl: bool = True, err: bool = False, prefix: bool = True) None

Log an info message to the cmdline logger.

Parameters:
  • message – the message to log.

  • bold – whether to format the message in bold.

  • nl – whether to add a newline at the end of the message.

  • err – whether to log to stderr.

  • prefix – whether the message should be prefixed with a colored version of the log level.

aiida.cmdline.echo_report(message: str, bold: bool = False, nl: bool = True, err: bool = False, prefix: bool = True) None

Log an report message to the cmdline logger.

Parameters:
  • message – the message to log.

  • bold – whether to format the message in bold.

  • nl – whether to add a newline at the end of the message.

  • err – whether to log to stderr.

  • prefix – whether the message should be prefixed with a colored version of the log level.

aiida.cmdline.echo_success(message: str, bold: bool = False, nl: bool = True, err: bool = False, prefix: bool = True) None

Log a success message to the cmdline logger.

Note

The message will be logged at the REPORT level and always with the Success: prefix.

Parameters:
  • message – the message to log.

  • bold – whether to format the message in bold.

  • nl – whether to add a newline at the end of the message.

  • err – whether to log to stderr.

  • prefix – whether the message should be prefixed with a colored version of the log level.

aiida.cmdline.echo_warning(message: str, bold: bool = False, nl: bool = True, err: bool = False, prefix: bool = True) None

Log a warning message to the cmdline logger.

Parameters:
  • message – the message to log.

  • bold – whether to format the message in bold.

  • nl – whether to add a newline at the end of the message.

  • err – whether to log to stderr.

  • prefix – whether the message should be prefixed with a colored version of the log level.

aiida.cmdline.format_call_graph(calc_node, max_depth: int = None, info_fn=calc_info)

Print a tree like the POSIX tree command for the calculation call graph

Parameters:
  • calc_node – The calculation node

  • max_depth – Maximum depth of the call graph to print

  • info_fn – An optional function that takes the node and returns a string of information to be displayed for each node.

aiida.cmdline.is_verbose()

Return whether the configured logging verbosity is considered verbose, i.e., equal or lower to INFO level.

Note

This checks the effective logging level that is set on the CMDLINE_LOGGER. This means that it will consider the logging level set on the parent AIIDA_LOGGER if not explicitly set on itself. The level of the main logger can be manipulated from the command line through the VERBOSITY option that is available for all commands.

aiida.cmdline.only_if_daemon_running(echo_function=echo.echo_critical, message=None)

Function decorator for CLI command to print critical error and exit automatically when daemon is not running.

The error printing and exit behavior can be controlled with the decorator keyword arguments. The default message that is printed can be overridden as well as the echo function that is to be used. By default it uses the aiida.cmdline.utils.echo.echo_critical function which automatically aborts the command. The function can be substituted by for example aiida.cmdline.utils.echo.echo_warning to instead print just a warning and continue.

Example:

@only_if_daemon_running(echo_function=echo.echo_warning, message='beware that the daemon is not running')
def create_node():
    pass
Parameters:
  • echo_function – echo function to issue the message, should be from aiida.cmdline.utils.echo

  • message – optional message to override the default message

aiida.cmdline.with_dbenv()

Function decorator that will load the database environment for the currently loaded profile.

Note

if no profile has been loaded yet, the default profile will be loaded first.

Example:

@with_dbenv()
def create_node():
    from aiida.orm import Int  # note the local import
    node = Int(1).store()