Skip to content

Add custom class for handling configuration dictionaries #434

@brews

Description

@brews

Idea from Rising to have implactlab_tools.utils.files.get_allargv_config() return a specialized dictionary for run configuration data. This new feature is also an onboarding project for @brews.

The rules for these configs for the projection system are (paraphrasing):

  1. A configuration file may contain multiple levels of configuration: dictionaries within other dictionaries, and so on.

  2. Different parts of the code are passed different parts of the configuration. This has two use cases: (1) because they are meant to use a specific sub-level of the configuration (e.g., a function may just want the sub-dictionary that contains weather variable definitions), or (2) when different parts of the config. initialize different parts of the calculation, so the same function is called with different parts at different times. The config. dictionary is usually included in a function call as an optional config argument.

  3. Dictionary keys are "inherited" into all lower levels. So, when we access a sub-level of the dictionary, what we actually use as the configuration dictionary at that level contains all of the keys of that sub-level, plus any keys of the parent level(s) that were not over-written by the sub-level. The code that currently creates this combined config. is merge(parent, child) in https://bitbucket.org/ClimateImpactLab/impact-calculations/src/master/interpret/configs.py.

  4. Key access should be case-insensitive and underscore-vs.-dash insensitive. This is not fully implemented in the current system.

Specifically looking for these features in the new class:

  1. It looks just like a dict object, although I think only the getitem, setitem, and iter methods need to be defined.

  2. It will always be initialized by a dictionary.

  3. It silently implements (3) and (4) above. I suggest that (3) is implemented by defining a parent attribute for each ConfigurationDictionary, which is accessed if the key is not found in the present dictionary. This will be useful for the next item.

  4. Whenever a key is accessed, the inspect.stack() is stored, associated with that key. Only the most recent is needed.

  5. A merge method, like the one from the code above, which can be used to merge two different configurations. Probably this can be implemented using by just making them both ConfigurationDictionarys, and setting the parent attribute on one of them. Make sure that a merge does not cause all keys to be accessed in the sense used in 4.

  6. A method on the object, "assert_completelyused" would assert that every key in the config. tree has been accessed.

Also need to write documentation and tests.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions