Skip to content

Refactor Polaris config class

Hugh Brown requested to merge refactor/change-config-class into master

What's here?

This MR refactors the PolarisConfig class to prepare the way for an MR that will introduce the polaris batch command. (I will add a link to that MR when it is submitted.)

The changes are:

  • Do not use the OrderedDict class as a base for PolarisConfig; this was not as useful as I thought it would be

  • Add the mergedeep module to perform merging of config options (see below for example)

  • Add properties for various options in the PolarisConfig class

  • Add unit tests for the PolarisConfig class

  • We are no longer setting defaults for each of the root, cache, graph and log directories. Instead, only root_dir is set; the class will use a default tree under that:

{root_dir}
└── {satellite_name}
    └── cache
    └── graph
    └── log
  • Update polaris_config.json.EXAMPLE to reflect that.

What is mergedeep used for?

This is for merging nested dictionaries. As an example:

  • Assume we have a defaults dictionary for Polaris Config; its batch setting will run fetch and learn, but not vi :
{
  "satellite": {
    "batch": {
      "fetch": true,
      "learn": true,
      "viz": false
    }
  }
}
  • Assume we also have a configuration file where we wish to enable viz for the batch command, while still running fetch and learn:
{
  "satellite": {
    "name": "LightSail-2",
    "batch": {
      "viz": true
    }
  }
}

The mergedeep module will do The Right Thing™ and give you this:

{
  "satellite": {
    "name": "LightSail-2"
    "batch": {
      "fetch": true,
      "learn": true,
      "viz": true
    }
  }
}

whereas an ordinary dictionary merge (new_dict = {**a, **b}) would (depending on the order you chose for the dictionaries to merge) give you one or the other of the batch sub-dictionaries, but not both.

Merge request reports