oasislmf.utils.inputs

Module Contents

Classes

InputValues

Helper class for accessing the input values from either

Functions

update_config(config_data[, config_map])

has_oasis_env(name)

get_oasis_env(name[, dtype, default])

str2bool(v)

Func type for loading strings to boolean values using argparse

oasislmf.utils.inputs.update_config(config_data, config_map=get_config_profile())[source]
oasislmf.utils.inputs.has_oasis_env(name)[source]
oasislmf.utils.inputs.get_oasis_env(name, dtype=None, default=None)[source]
class oasislmf.utils.inputs.InputValues(args, update_keys=True)[source]

Bases: object

Helper class for accessing the input values from either the command line or the configuration file.

internal_update

list_unknown_keys()[source]

List all Unknown keys set in the ‘oasislmf.json’ file

load_config_file()[source]
write_config_file(config_fp)[source]
confirm_action(question_str, no_confirm=False)[source]
get(name, default=None, required=False, is_path=False, dtype=None)[source]
Gets the name parameter until found from:
  • the command line arguments.

  • the configuration file

  • the environment variable (put in uppercase)

If it is not found then default is returned unless required is True in which case an OasisException is raised.

Parameters:
  • name (str) – The name of the parameter to lookup

  • default – The default value to return if the name is not found on the command line or in the configuration file.

  • required (bool) – Flag whether the value is required, if so and the parameter is not found on the command line or in the configuration file an error is raised.

  • is_path (bool) – Flag whether the value should be treated as a path and return an abspath, use config_dir as base dir if value comes from the config

  • dtype – the class <type> of the value, if ‘None’ load as string by default

Type:

class

Raises:

OasisException – If the value is not found and required is True

Returns:

The found value or the default

oasislmf.utils.inputs.str2bool(v)[source]

Func type for loading strings to boolean values using argparse https://stackoverflow.com/a/43357954

step_params:

use: ‘default’: False, ‘type’: str2bool, ‘const’:True, ‘nargs’:’?’, …

CLI:

oasislmf –some-flag oasislmf –some-flag <bool>

oasislmf.json {“some_flag”: true, …}