This PR introduces classmethod Config.from_dict(). The method takes two arguments: the path to the inventory, and a Python dict with config options. The primary usecase for this method will be the Kapitan reclass-rs integration. We need something like this, since Kapitan generates a dict of Reclass options in Python, and we don't provide a clean way to instantiate a reclass_rs.Reclass instance from such a dict without this PR.
To avoid a lot of duplication between Config.from_dict() and Config::load_from_file() we move the setting of known config options into a new private helper function Config::set_option(). Additionally, we implement TryFrom<&PyAny> for our Value type. This conversion method allows us to convert the data in the user-supplied Python dict into serde_yaml::Value types for Config::set_option().
Finally, the PR also adds two Python tests which exercise Config.from_dict().
Checklist
[x] The PR has a meaningful title. The title will be used to auto generate the changelog
[x] PR contains a single logical change (to build a better changelog).
[x] Update the documentation.
[x] Update tests.
[x] Categorize the PR by setting a good title and adding one of the labels:
bug, enhancement, documentation, change, breaking, dependency, internal
as they show up in the changelog
This PR introduces classmethod
Config.from_dict()
. The method takes two arguments: the path to the inventory, and a Python dict with config options. The primary usecase for this method will be the Kapitan reclass-rs integration. We need something like this, since Kapitan generates a dict of Reclass options in Python, and we don't provide a clean way to instantiate areclass_rs.Reclass
instance from such a dict without this PR.To avoid a lot of duplication between
Config.from_dict()
andConfig::load_from_file()
we move the setting of known config options into a new private helper functionConfig::set_option()
. Additionally, we implementTryFrom<&PyAny>
for ourValue
type. This conversion method allows us to convert the data in the user-supplied Python dict intoserde_yaml::Value
types forConfig::set_option()
.Finally, the PR also adds two Python tests which exercise
Config.from_dict()
.Checklist
bug
,enhancement
,documentation
,change
,breaking
,dependency
,internal
as they show up in the changelog