aiida.cmdline.params.options package

Submodules

class aiida.cmdline.params.options.config.ConfigFileOption(*args, **kwargs)[source]

Bases: aiida.cmdline.params.options.overridable.OverridableOption

Wrapper around click_config_file.configuration_option that increases reusability.

Example:

CONFIG_FILE = ConfigFileOption('--config', help='A configuration file')

@click.command()
@click.option('computer_name')
@CONFIG_FILE(help='Configuration file for computer_setup')
def computer_setup(computer_name):
    click.echo("Setting up computer {}".format(computername))

computer_setup --config config.yml

with config.yml:

---
computer_name: computer1
__call__(**kwargs)[source]

Override the stored kwargs, (ignoring args as we do not allow option name changes) and return the option.

Parameters

kwargs – keyword arguments that will override those set in the construction

Returns

click_config_file.configuration_option constructed with args and kwargs defined during construction and call of this instance

__init__(*args, **kwargs)[source]

Store the default args and kwargs.

Parameters
  • args – default arguments to be used for the option

  • kwargs – default keyword arguments to be used that can be overridden in the call

__module__ = 'aiida.cmdline.params.options.config'
aiida.cmdline.params.options.config.yaml_config_file_provider(file_path, cmd_name)[source]

Read yaml config file.

class aiida.cmdline.params.options.contextualdefault.ContextualDefaultOption(*args, contextual_default=None, **kwargs)[source]

Bases: click.core.Option

A class that extends click.Option allowing to define a default callable that also get the context ctx as a parameter.

__init__(*args, contextual_default=None, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.cmdline.params.options.contextualdefault'
get_default(ctx)[source]

If a contextual default is defined, use it, otherwise behave normally.

Module to define multi value options for click.

class aiida.cmdline.params.options.multivalue.MultipleValueOption(*args, **kwargs)[source]

Bases: click.core.Option

An option that can handle multiple values with a single flag. For example:

@click.option('-n', '--nodes', cls=MultipleValueOption)

Will be able to parse the following:

--nodes 10 15 12

This is better than the builtin multiple=True keyword for click’s option which forces the user to specify the option flag for each value, which gets impractical for long lists of values

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.cmdline.params.options.multivalue'
add_to_parser(parser, ctx)[source]

Override built in click method that allows us to specify a custom parser to eat up parameters until the following flag or ‘endopt’ (i.e. –)

aiida.cmdline.params.options.multivalue.collect_usage_pieces(self, ctx)[source]

Returns all the pieces that go into the usage line and returns it as a list of strings.

class aiida.cmdline.params.options.overridable.OverridableOption(*args, **kwargs)[source]

Bases: object

Wrapper around click option that increases reusability

Click options are reusable already but sometimes it can improve the user interface to for example customize a help message for an option on a per-command basis. Sometimes the option should be prompted for if it is not given On some commands an option might take any folder path, while on another the path only has to exist.

Overridable options store the arguments to click.option and only instantiate the click.Option on call, kwargs given to __call__ override the stored ones.

Example:

FOLDER = OverridableOption('--folder', type=click.Path(file_okay=False), help='A folder')

@click.command()
@FOLDER(help='A folder, will be created if it does not exist')
def ls_or_create(folder):
    click.echo(os.listdir(folder))

@click.command()
@FOLDER(help='An existing folder', type=click.Path(exists=True, file_okay=False, readable=True)
def ls(folder)
    click.echo(os.listdir(folder))
__call__(**kwargs)[source]

Override the stored kwargs, (ignoring args as we do not allow option name changes) and return the option.

Parameters

kwargs – keyword arguments that will override those set in the construction

Returns

click option constructed with args and kwargs defined during construction and call of this instance

__dict__ = mappingproxy({'__module__': 'aiida.cmdline.params.options.overridable', '__doc__': "\n Wrapper around click option that increases reusability\n\n Click options are reusable already but sometimes it can improve the user interface to for example customize a\n help message for an option on a per-command basis. Sometimes the option should be prompted for if it is not given\n On some commands an option might take any folder path, while on another the path only has to exist.\n\n Overridable options store the arguments to click.option and only instantiate the click.Option on call,\n kwargs given to ``__call__`` override the stored ones.\n\n Example::\n\n FOLDER = OverridableOption('--folder', type=click.Path(file_okay=False), help='A folder')\n\n @click.command()\n @FOLDER(help='A folder, will be created if it does not exist')\n def ls_or_create(folder):\n click.echo(os.listdir(folder))\n\n @click.command()\n @FOLDER(help='An existing folder', type=click.Path(exists=True, file_okay=False, readable=True)\n def ls(folder)\n click.echo(os.listdir(folder))\n ", '__init__': <function OverridableOption.__init__>, '__call__': <function OverridableOption.__call__>, 'clone': <function OverridableOption.clone>, '__dict__': <attribute '__dict__' of 'OverridableOption' objects>, '__weakref__': <attribute '__weakref__' of 'OverridableOption' objects>})
__init__(*args, **kwargs)[source]

Store the default args and kwargs.

Parameters
  • args – default arguments to be used for the click option

  • kwargs – default keyword arguments to be used that can be overridden in the call

__module__ = 'aiida.cmdline.params.options.overridable'
__weakref__

list of weak references to the object (if defined)

clone(**kwargs)[source]

Create a new instance of the OverridableOption by cloning it and updating the stored kwargs with those passed.

This can be useful when an already predefined OverridableOption needs to be further specified and reused by a set of sub commands. Example:

LABEL = OverridableOption('-l', '--label', required=False, help='The label of the node'
LABEL_COMPUTER = LABEL.clone(required=True, help='The label of the computer')

If multiple computer related sub commands need the LABEL option, but the default help string and required attribute need to be different, the clone method allows to override these and create a new OverridableOption instance that can then be used as a decorator.

Parameters

kwargs – keyword arguments to update

Returns

OverridableOption instance with stored keyword arguments updated