projectsyn / reclass-rs

Reimplementation of https://github.com/kapicorp/reclass in Rust with Python bindings through PyO3.
BSD 3-Clause "New" or "Revised" License
7 stars 0 forks source link

Add Python classmethod `Config.from_dict()` #105

Closed simu closed 6 months ago

simu commented 6 months ago

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

github-actions[bot] commented 6 months ago

Benchmark for f83da6c

Click to view benchmark | Test | Base | PR | % | |------|--------------|------------------|---| | Reclass::inventory() multi-threaded | 1635.5±60.98µs | 1652.2±147.32µs | +1.02% | | Reclass::inventory() single-threaded | 3.6±0.18ms | 3.6±0.07ms | 0.00% |
github-actions[bot] commented 6 months ago

Benchmark for 17a548c

Click to view benchmark | Test | Base | PR | % | |------|--------------|------------------|---| | Reclass::inventory() multi-threaded | 1647.5±118.52µs | 1618.4±53.04µs | -1.77% | | Reclass::inventory() single-threaded | **3.6±0.03ms** | 3.7±0.14ms | **+2.78%** |
github-actions[bot] commented 6 months ago

Benchmark for 343931a

Click to view benchmark | Test | Base | PR | % | |------|--------------|------------------|---| | Reclass::inventory() multi-threaded | 1605.5±51.52µs | 1634.7±111.92µs | +1.82% | | Reclass::inventory() single-threaded | 3.6±0.03ms | 3.6±0.04ms | 0.00% |