common.config_loader

class ConfigLoader(data_dir, conf_file_name, default_conf, command_line_conf)[source]

Bases: object

The ConfigLoader class is in charge of loading all the configuration parameters to create a config dict that can be used to set all configurable parameters of the system.

Parameters
  • data_dir (str) – the path to the data directory where the configuration file may be found.

  • default_conf (dict) –

    a dictionary populated with the default configuration params and the expected types. The format is as follows:

    {"field0": {"value": value_from_conf_file, "type": expected_type, ...}}

  • command_line_conf (dict) – a dictionary containing the command line parameters that may replace the ones in default / config file.

data_dir

The path to the data directory where the configuration file may be found.

Type

str

conf_file_path

The path to the config file (the file may not exist).

Type

str

conf_fields

A dictionary populated with the configuration params and the expected types. It follows the same format as default_conf.

Type

dict

command_line_conf

A dictionary containing the command line parameters that may replace the ones in default / config file.

Type

dict

build_config()[source]

Builds a config dictionary from command line, config file and default configuration parameters.

The priority is as follows:
  • command line

  • config file

  • defaults

Returns

A dictionary containing all the configuration parameters.

Return type

dict

create_config_dict()[source]

Checks that the configuration fields (self.conf_fields) have the right type and creates a config dict if so.

Returns

A dictionary with the same keys as the provided one, but containing only the “value” field as value if the provided conf_fields are correct.

Return type

dict

Raises

ValueError – If any of the dictionary elements does not have the expected type.

extend_paths()[source]

Extends the relative paths of the conf_fields dictionary with data_dir.

If an absolute path is given, it will remain the same.

If the config contains a BTC_NETWORK field whose value is not “mainnet”, it is also appended to the path.