class documentation
class CompositeConfigParser(ConfigFileParser): (source)
Constructor: CompositeConfigParser(config_parser_types)
Create a config parser composed of other config file parsers, each given as a ConfigFileParser instance or class (a class is instantiated with no args).
The composite parser will successively try to parse the file with each parser, until it succeeds, else raise exception with all encountered errors.
Usage, to read settings from either TOML or INI files:
sections = ['tool.my_super_tool', 'tool:my_super_tool', 'my_super_tool']
parser = ArgumentParser(
default_config_files=['./pyproject.toml', 'setup.cfg', 'my_super_tool.ini'],
config_file_parser_class=CompositeConfigParser([
TomlConfigParser(sections),
IniConfigParser(sections, split_ml_text_to_list=True),
]),
)
| Method | __call__ |
Undocumented |
| Method | __init__ |
Undocumented |
| Method | get |
Returns a string describing the config file syntax. |
| Method | parse |
Parses the keys and values from a config file. |
| Method | serialize |
Serialize items using the first parser in the composite. |
| Instance Variable | parsers |
Undocumented |
overrides
configargparse.ConfigFileParser.parseParses the keys and values from a config file.
NOTE: For keys that were specified to configargparse as action="store_true" or "store_false", the config file value must be one of: "yes", "no", "on", "off", "true", "false". Otherwise an error will be raised.
| Parameters | |
stream:io.IOBase | A config file input stream (such as an open file object). |
| Returns | |
OrderedDict | Items where the keys are strings and the values are either strings or lists (eg. to support config file formats like YAML which allow lists). |