neon.util.argparser.NeonArgparser

class neon.util.argparser.NeonArgparser(*args, **kwargs)[source]

Bases: configargparse.ArgumentParser

Setup the command line arg parser and parse the arguments in sys.arg (or from configuration file). Use the parsed options to configure the logging module.

Parameters:desc (String) – Docstring from the calling function. This will be used for the description of the command receiving the arguments.
__init__(*args, **kwargs)[source]

Methods

__init__(*args, **kwargs)
add() Ignored.
add_arg() Ignored.
add_argument(*args, **kwargs) Method by which command line arguments are added to the parser.
add_argument_group(*args, **kwargs)
add_mutually_exclusive_group(**kwargs)
add_subparsers(**kwargs)
add_yaml_arg() Add the yaml file argument, this is needed for scripts that
convert_arg_line_to_args(arg_line)
convert_setting_to_command_line_arg(action, …) Converts a config file or env var key/value to a list of commandline args to append to the commandline.
error(message: string) Prints a usage message incorporating the message to stderr and exits.
exit([status, message])
format_help()
format_usage()
format_values() Returns a string with all args and settings and where they came from (eg.
get_command_line_key_for_unknown_config_file_setting(key) Compute a commandline arg key to be used for a config file setting that doesn’t correspond to any defined configargparse arg (and so doesn’t have a user-specified commandline arg key).
get_default(dest)
get_items_for_config_file_output(…) Does the inverse of config parsing by taking parsed values and converting them back to a string representing config file contents.
get_possible_config_keys(action) This method decides which actions can be set in a config file and what their keys will be.
original_add_argument_method(*args, **kwargs) add_argument(dest, …, name=value, …)
parse([args, namespace, …]) Supports all the same args as the ArgumentParser.parse_args(..), as well as the following additional args.
parse_args([gen_be]) Parse the command line arguments and setup neon
parse_known([args, namespace, …]) Supports all the same args as the ArgumentParser.parse_args(..), as well as the following additional args.
parse_known_args([args, namespace, …]) Supports all the same args as the ArgumentParser.parse_args(..), as well as the following additional args.
print_help([file])
print_usage([file])
print_values([file]) Prints the format_values() string (to sys.stdout or another file).
register(registry_name, value, object)
set_defaults(**kwargs)
setup_default_args() Setup the default arguments used by neon
add()[source]

Ignored.

add_arg()[source]

Ignored.

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

Method by which command line arguments are added to the parser. Passed straight through to parent add_argument method.

Parameters:
  • *args
  • **kwargs
add_argument_group(*args, **kwargs)
add_mutually_exclusive_group(**kwargs)
add_subparsers(**kwargs)
add_yaml_arg()[source]

Add the yaml file argument, this is needed for scripts that parse the model config from yaml files

convert_arg_line_to_args(arg_line)
convert_setting_to_command_line_arg(action, key, value)

Converts a config file or env var key/value to a list of commandline args to append to the commandline.

Parameters:
  • action – The action corresponding to this setting, or None if this is a config file setting that doesn’t correspond to any defined configargparse arg.
  • key – The config file key or env var name
  • value – The raw value string from the config file or env var
error(message: string)

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

exit(status=0, message=None)
format_help()
format_usage()
format_values()

Returns a string with all args and settings and where they came from (eg. commandline, config file, enviroment variable or default)

get_command_line_key_for_unknown_config_file_setting(key)

Compute a commandline arg key to be used for a config file setting that doesn’t correspond to any defined configargparse arg (and so doesn’t have a user-specified commandline arg key).

Parameters:key – The config file key that was being set.
get_default(dest)
get_items_for_config_file_output(source_to_settings, parsed_namespace)

Does the inverse of config parsing by taking parsed values and converting them back to a string representing config file contents.

Parameters:
  • source_to_settings – the dictionary created within parse_known_args()
  • parsed_namespace – namespace object created within parse_known_args()
Returns:

an OrderedDict with the items to be written to the config file

get_possible_config_keys(action)

This method decides which actions can be set in a config file and what their keys will be. It returns a list of 0 or more config keys that can be used to set the given action’s value in a config file.

original_add_argument_method(*args, **kwargs)

add_argument(dest, …, name=value, …) add_argument(option_string, option_string, …, name=value, …)

parse(args=None, namespace=None, config_file_contents=None, env_vars=environ({'http_proxy': 'http://proxy-us.intel.com:911', 'https_proxy': 'http://proxy-us.intel.com:911'}))

Supports all the same args as the ArgumentParser.parse_args(..), as well as the following additional args.

Additional Args:
args: a list of args as in argparse, or a string (eg. “-x -y bla”) config_file_contents: String. Used for testing. env_vars: Dictionary. Used for testing.
parse_args(gen_be=True)[source]

Parse the command line arguments and setup neon runtime environment accordingly

Parameters:gen_be (bool) – if False, the arg parser will not generate the backend
Returns:contains the parsed arguments as attributes
Return type:namespace
parse_known(args=None, namespace=None, config_file_contents=None, env_vars=environ({'http_proxy': 'http://proxy-us.intel.com:911', 'https_proxy': 'http://proxy-us.intel.com:911'}))

Supports all the same args as the ArgumentParser.parse_args(..), as well as the following additional args.

Additional Args:
args: a list of args as in argparse, or a string (eg. “-x -y bla”) config_file_contents: String. Used for testing. env_vars: Dictionary. Used for testing.
parse_known_args(args=None, namespace=None, config_file_contents=None, env_vars=environ({'http_proxy': 'http://proxy-us.intel.com:911', 'https_proxy': 'http://proxy-us.intel.com:911'}))

Supports all the same args as the ArgumentParser.parse_args(..), as well as the following additional args.

Additional Args:
args: a list of args as in argparse, or a string (eg. “-x -y bla”) config_file_contents: String. Used for testing. env_vars: Dictionary. Used for testing.
print_help(file=None)
print_usage(file=None)
print_values(file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='ANSI_X3.4-1968'>)

Prints the format_values() string (to sys.stdout or another file).

register(registry_name, value, object)
set_defaults(**kwargs)
setup_default_args()[source]

Setup the default arguments used by neon