snakemake.common.argparse.ArgumentParser

class snakemake.common.argparse.ArgumentParser(*args, **kwargs)[source]
__init__(*args, **kwargs)[source]

Supports args of the argparse.ArgumentParser constructor as **kwargs, as well as the following additional args.

Parameters:
  • add_config_file_help – Whether to add a description of config file syntax to the help message.

  • add_env_var_help – Whether to add something to the help message for args that can be set through environment variables.

  • auto_env_var_prefix – If set to a string instead of None, all config- file-settable options will become also settable via environment variables whose names are this prefix followed by the config file key, all in upper case. (eg. setting this to foo_ will allow an arg like --my-arg to also be set via the FOO_MY_ARG environment variable)

  • default_config_files

    When specified, this list of config files will be parsed in order, with the values from each config file taking precedence over previous ones. This allows an application to look for config files in multiple standard locations such as the install directory, home directory, and current directory. Also, shell * syntax can be used to specify all conf files in a directory. For example:

    ["/etc/conf/app_config.ini",
    "/etc/conf/conf-enabled/*.ini",
    "~/.my_app_config.ini",
    "./app_config.txt"]
    

  • ignore_unknown_config_file_keys – If true, settings that are found in a config file but don’t correspond to any defined configargparse args will be ignored. If false, they will be processed and appended to the commandline like other args, and can be retrieved using parse_known_args() instead of parse_args()

  • config_file_open_func – function used to open a config file for reading or writing. Needs to return a file-like object.

  • config_file_parser_class – configargparse.ConfigFileParser subclass which determines the config file format. configargparse comes with DefaultConfigFileParser and YAMLConfigFileParser.

  • args_for_setting_config_path – A list of one or more command line args to be used for specifying the config file path (eg. [“-c”, “–config-file”]). Default: []

  • config_arg_is_required – When args_for_setting_config_path is set, set this to True to always require users to provide a config path.

  • config_arg_help_message – the help message to use for the args listed in args_for_setting_config_path.

  • args_for_writing_out_config_file – A list of one or more command line args to use for specifying a config file output path. If provided, these args cause configargparse to write out a config file with settings based on the other provided commandline args, environment variants and defaults, and then to exit. (eg. [“-w”, “–write-out-config-file”]). Default: []

  • write_out_config_file_arg_help_message – The help message to use for the args in args_for_writing_out_config_file.

Methods

__init__(*args, **kwargs)

Supports args of the argparse.ArgumentParser constructor as **kwargs, as well as the following additional args.

add(*args, **kwargs)

This method supports the same args as ArgumentParser.add_argument(..) as well as the additional args below.

add_arg(*args, **kwargs)

This method supports the same args as ArgumentParser.add_argument(..) as well as the additional args below.

add_argument(*args[, parse_func])

This method supports the same args as ArgumentParser.add_argument(..) as well as the additional args below.

add_argument_group(*args, **kwargs)

add_mutually_exclusive_group(**kwargs)

add_subparsers(**kwargs)

convert_arg_line_to_args(arg_line)

convert_item_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)

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(...)

Converts the given settings back to a dictionary that can be passed to ConfigFormatParser.serialize(..).

get_possible_config_keys(action)

This method decides which actions can be set in a config file and what their keys will be.

get_source_to_settings_dict()

If called after parse_args() or parse_known_args(), returns a dict that contains up to 4 keys corresponding to where a given option's value is coming from: - "command_line" - "environment_variables" - "config_file" - "defaults" Each such key, will be mapped to another dictionary containing the options set via that method.

original_add_argument_method(*args, **kwargs)

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

parse([args, namespace, ...])

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

parse_args([args, namespace, ...])

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

parse_intermixed_args([args, namespace])

parse_known([args, namespace, ...])

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

parse_known_args([args, namespace, ...])

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

parse_known_intermixed_args([args, namespace])

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)

write_config_file(parsed_namespace, ...[, ...])

Write the given settings to output files.