ConfigReader

class negmas.helpers.ConfigReader[source]

Bases: object

Methods Summary

from_config(config[, section, ...])

Creates an object of this class given the configuration info

read_config(config[, section])

Reads the configuration from a file or a dict and prepares it for parsing

Methods Documentation

classmethod from_config(config, section=None, ignore_children=True, try_parsing_children=True, scope=None)[source]

Creates an object of this class given the configuration info

Parameters
  • config (Union[str, dict]) – Either a file name or a dictionary

  • section (Optional[str]) – A section in the file or a key in the dictionary to use for loading params

  • ignore_children (bool) – If true then children will be ignored and there will be a single return

  • try_parsing_children (bool) – If true the children will first be parsed as ConfigReader classes if they are not

  • int (simple types (e.g.) –

  • str

  • float

  • Iterable[int|str|float]

  • scope – The scope at which to evaluate any child classes. This MUST be passed as scope=globals() if you are

  • parsed. (having any children that are to be) –

Returns

An object of cls if ignore_children is True or a tuple with an object of cls and a dictionary with children that were not parsed.

Remarks:

  • This function will return an object of its class after passing the key-value pairs found in the config to the init function.

  • Requiring passing scope=globals() to this function is to get around the fact that in python eval() will be called with a globals dictionary based on the module in which the function is defined not called. This means that in general when eval() is called to create the children, it will not have access to the class definitions of these children (except if they happen to be imported in this file). To avoid this problem causing an undefined_name exception, the caller must pass her globals() as the scope.

classmethod read_config(config, section=None)[source]

Reads the configuration from a file or a dict and prepares it for parsing

Parameters
  • config (Union[str, dict]) – Either a file name or a dictionary

  • section (Optional[str]) – A section in the file or a key in the dictionary to use for loading params

Return type

dict[str, Any]

Returns

A dict ready to be parsed by from_config

Remarks: