aiida.cmdline.utils package¶
Subpackages¶
Submodules¶
Utility functions to draw ASCII diagrams to the command line.
-
aiida.cmdline.utils.ascii_vis.
draw_children
(node, node_label=None, show_pk=True, dist=2, follow_links_of_type=None)[source]¶ Print an ASCII tree of the parents of the given node.
Parameters: - node (
aiida.orm.nodes.data.Data
) – The node to draw for - node_label (str) – The label to use for the nodes
- show_pk (bool) – Show the PK of nodes alongside the label
- dist (int) – The number of steps away from this node to branch out
- follow_links_of_type (str) – Follow links of this type when making steps, if None then it will follow CREATE and INPUT links
- node (
-
aiida.cmdline.utils.ascii_vis.
draw_parents
(node, node_label=None, show_pk=True, dist=2, follow_links_of_type=None)[source]¶ Print an ASCII tree of the parents of the given node.
Parameters: - node (
aiida.orm.nodes.data.Data
) – The node to draw for - node_label (str) – The label to use for the nodes
- show_pk (bool) – Show the PK of nodes alongside the label
- dist (int) – The number of steps away from this node to branch out
- follow_links_of_type (str) – Follow links of this type when making steps, if None then it will follow CREATE and INPUT links
- node (
-
aiida.cmdline.utils.ascii_vis.
format_call_graph
(calc_node, info_fn=<function calc_info>)[source]¶ Print a tree like the POSIX tree command for the calculation call graph
Parameters: - calc_node – The calculation node
- info_fn – An optional function that takes the node and returns a string of information to be displayed for each node.
Common utility functions for command line commands.
-
aiida.cmdline.utils.common.
format_local_time
(timestamp, format_str='%Y-%m-%d %H:%M:%S')[source]¶ Format a datetime object or UNIX timestamp in a human readable format
Parameters: - timestamp – a datetime object or a float representing a UNIX timestamp
- format_str – optional string format to pass to strftime
-
aiida.cmdline.utils.common.
get_calcjob_report
(calcjob)[source]¶ Return a multi line string representation of the log messages and output of a given calcjob
Parameters: calcjob – the calcjob node Returns: a string representation of the log messages and scheduler output
-
aiida.cmdline.utils.common.
get_env_with_venv_bin
()[source]¶ Create a clone of the current running environment with the AIIDA_PATH variable set directory of the config.
-
aiida.cmdline.utils.common.
get_node_info
(node, include_summary=True)[source]¶ Return a multi line string of information about the given node, such as the incoming and outcoming links
Parameters: include_summary – also include a summary of node properties Returns: a string summary of the node including a description of all its links and log messages
-
aiida.cmdline.utils.common.
get_node_summary
(node)[source]¶ Return a multi line string with a pretty formatted summary of a Node
Parameters: node – a Node instance Returns: a string summary of the node
-
aiida.cmdline.utils.common.
get_process_function_report
(node)[source]¶ Return a multi line string representation of the log messages and output of a given process function node
Parameters: node – the node Returns: a string representation of the log messages
-
aiida.cmdline.utils.common.
get_workchain_report
(node, levelname, indent_size=4, max_depth=None)[source]¶ Return a multi line string representation of the log messages and output of a given workchain
Parameters: node – the workchain node Returns: a nested string representation of the log messages
-
aiida.cmdline.utils.common.
print_last_process_state_change
(process_type=None)[source]¶ Print the last time that a process of the specified type has changed its state. This function will also print a warning if the daemon is not running.
Parameters: process_type – optional process type for which to get the latest state change timestamp. Valid process types are either ‘calculation’ or ‘work’.
Utility functions for command line commands related to the daemon.
-
aiida.cmdline.utils.daemon.
get_daemon_status
(client)[source]¶ Print the status information of the daemon for a given profile through its DaemonClient
Parameters: client – the DaemonClient
-
aiida.cmdline.utils.daemon.
print_client_response_status
(response)[source]¶ Print the response status of a call to the CircusClient through the DaemonClient
Parameters: response – the response object
Various decorators useful for creating verdi commands, for example loading the dbenv lazily.
Always avoids trying to load the dbenv twice. When it has to be loaded, a spinner ASCII widget is displayed.
- Provides:
- with_dbenv, a decorator to frontload the dbenv for functions
- dbenv, a contextmanager to load the dbenv only if a specific
- code branch gets visited and possibly avoiding the overhead if not
-
aiida.cmdline.utils.decorators.
with_dbenv
(*load_dbenv_args, **load_dbenv_kwargs)[source]¶ Function decorator that will load the database environment only when the function is called.
-
aiida.cmdline.utils.decorators.
dbenv
(*args, **kwds)[source]¶ 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.utils.decorators.
only_if_daemon_running
(echo_function=<function echo_critical>, message=None)[source]¶ 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_my_calculation(): 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
Default values and lazy default get methods for command line options.
-
aiida.cmdline.utils.defaults.
get_default_profile
(ctx, param, value)[source]¶ Try to get the default profile.
This should be used if the default profile should be returned lazily, at a point for example when the config is not created at import time. Otherwise, the preference should go to calling get_config to load the actual config and using config.default_profile_name to get the default profile name
Raises: click.UsageError – if the config could not be loaded or no default profile exists Returns: the default profile
Convenience functions for printing output from verdi commands
-
aiida.cmdline.utils.echo.
echo
(message, bold=False, nl=True, err=False)[source]¶ Print a normal message through click’s echo function to stdout
Parameters: - message – the string representing the message to print
- bold – whether to print the message in bold
- nl – whether to print a newline at the end of the message
- err – whether to print to stderr
-
aiida.cmdline.utils.echo.
echo_info
(message, bold=False, nl=True, err=False)[source]¶ Print an info message through click’s echo function to stdout, prefixed with ‘Info:’
Parameters: - message – the string representing the message to print
- bold – whether to print the message in bold
- nl – whether to print a newline at the end of the message
- err – whether to print to stderr
-
aiida.cmdline.utils.echo.
echo_success
(message, bold=False, nl=True, err=False)[source]¶ Print a success message through click’s echo function to stdout, prefixed with ‘Success:’
Parameters: - message – the string representing the message to print
- bold – whether to print the message in bold include a newline character
- nl – whether to print a newline at the end of the message
- err – whether to print to stderr
-
aiida.cmdline.utils.echo.
echo_warning
(message, bold=False, nl=True, err=False)[source]¶ Print a warning message through click’s echo function to stdout, prefixed with ‘Warning:’
Parameters: - message – the string representing the message to print
- bold – whether to print the message in bold
- nl – whether to print a newline at the end of the message
- err – whether to print to stderr
-
aiida.cmdline.utils.echo.
echo_error
(message, bold=False, nl=True, err=True)[source]¶ Print an error message through click’s echo function to stdout, prefixed with ‘Error:’
Parameters: - message – the string representing the message to print
- bold – whether to print the message in bold
- nl – whether to print a newline at the end of the message
- err – whether to print to stderr
-
aiida.cmdline.utils.echo.
echo_critical
(message, bold=False, nl=True, err=True)[source]¶ Print an error message through click’s echo function to stdout, prefixed with ‘Critical:’ and then calls sys.exit with the given 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 string representing the message to print
- bold – whether to print the message in bold
- nl – whether to print a newline at the end of the message
- err – whether to print to stderr
-
aiida.cmdline.utils.echo.
echo_dictionary
(dictionary, fmt='json+date')[source]¶ Print the given dictionary to stdout in the given format
Parameters: - dictionary – the dictionary
- fmt – the format to use for printing, valid options: [‘json+data’]
utilities for getting multi line input from the commandline
-
aiida.cmdline.utils.multi_line_input.
edit_comment
(old_cmt='')[source]¶ call up an editor to edit comments to nodes in the database
-
aiida.cmdline.utils.multi_line_input.
edit_pre_post
(pre=None, post=None, summary=None)[source]¶ use click to call up an editor to write or edit pre / post execution scripts for both codes and computers
-
aiida.cmdline.utils.multi_line_input.
ensure_scripts
(pre, post, summary)[source]¶ A function to check if the prepend and append scripts were specified, and if needed ask to edit them.
Parameters: - pre – prepend-text
- post – append-text
- summary – summary for click template
Returns:
Plugin aware click command Group.
-
class
aiida.cmdline.utils.pluginable.
Pluginable
(*args, **kwargs)[source]¶ Bases:
click.core.Group
A click command group that finds and loads plugin commands lazily.
-
__module__
= 'aiida.cmdline.utils.pluginable'¶
-
Utility functions for command line commands operating on the repository.
-
aiida.cmdline.utils.repository.
list_repository_contents
(node, path, color)[source]¶ Print the contents of the directory path in the repository of the given node to stdout.
Parameters: - node – the node
- path – directory path
Definition of modules that are to be automatically loaded for verdi shell.
Templates for input/output of verdi commands.
Unit tests for editing pre and post bash scripts, comments, etc.
-
class
aiida.cmdline.utils.test_multiline.
TestMultilineInput
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Test functions for editing pre and post bash scripts, comments, etc.
-
__module__
= 'aiida.cmdline.utils.test_multiline'¶
-