optify 0.12.1__tar.gz → 0.13.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {optify-0.12.1 → optify-0.13.0}/PKG-INFO +1 -1
- {optify-0.12.1 → optify-0.13.0}/pyproject.toml +2 -2
- {optify-0.12.1 → optify-0.13.0}/python/optify/Cargo.lock +2 -2
- {optify-0.12.1 → optify-0.13.0}/python/optify/Cargo.toml +2 -2
- {optify-0.12.1 → optify-0.13.0}/rust/Cargo.toml +4 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/Cargo.toml +4 -1
- {optify-0.12.1 → optify-0.13.0}/rust/optify/README.md +16 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/benches/caching_benchmark.rs +10 -10
- {optify-0.12.1 → optify-0.13.0}/rust/optify/benches/get_all_options_benchmark.rs +6 -6
- {optify-0.12.1 → optify-0.13.0}/rust/optify/benches/get_options_benchmark.rs +11 -11
- {optify-0.12.1 → optify-0.13.0}/rust/optify/benches/loading_benchmark.rs +4 -4
- {optify-0.12.1 → optify-0.13.0}/rust/optify/build.rs +10 -4
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/builder_impl.rs +43 -25
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/builder_options.rs +30 -11
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/extract_configurable_string_files_from_config.rs +2 -3
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/extract_files_from_config.rs +2 -3
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/loading_result.rs +1 -1
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/watcher_builder.rs +2 -1
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/configurable_string/configurable_string_impl.rs +29 -32
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/configurable_values/locator.rs +17 -16
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/json/merge.rs +2 -1
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/json/mod.rs +1 -0
- optify-0.13.0/rust/optify/src/json/parse_json_pointer.rs +35 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/lib.rs +3 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/policies/feature_policies.rs +2 -1
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/policies/policy_store.rs +54 -2
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/policies/requester_feature_policy.rs +1 -1
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/policies/requester_policy.rs +3 -1
- optify-0.13.0/rust/optify/src/provider/analysis/analysis_data.rs +10 -0
- optify-0.13.0/rust/optify/src/provider/analysis/analyze.rs +39 -0
- optify-0.13.0/rust/optify/src/provider/analysis/explain.rs +188 -0
- optify-0.13.0/rust/optify/src/provider/analysis/mod.rs +17 -0
- optify-0.13.0/rust/optify/src/provider/analysis/option_analysis.rs +20 -0
- optify-0.13.0/rust/optify/src/provider/analysis/option_origin.rs +17 -0
- optify-0.13.0/rust/optify/src/provider/analysis/option_source.rs +26 -0
- optify-0.13.0/rust/optify/src/provider/analysis/origin.rs +10 -0
- optify-0.13.0/rust/optify/src/provider/analysis/projection.rs +110 -0
- optify-0.13.0/rust/optify/src/provider/analysis/provenance.rs +105 -0
- optify-0.13.0/rust/optify/src/provider/analysis/replay.rs +137 -0
- optify-0.13.0/rust/optify/src/provider/analysis/tracked_merge.rs +211 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/provider/get_options_preferences.rs +3 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/provider/mod.rs +2 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/provider/provider_impl.rs +73 -62
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/provider/provider_trait.rs +27 -3
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/provider/watcher.rs +21 -2
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/provider/watcher_options.rs +3 -2
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/schema/conditions.rs +5 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/schema/metadata.rs +2 -1
- {optify-0.12.1 → optify-0.13.0}/LICENSE.txt +0 -0
- {optify-0.12.1 → optify-0.13.0}/README.md +0 -0
- {optify-0.12.1 → optify-0.13.0}/optify/__init__.py +0 -0
- {optify-0.12.1 → optify-0.13.0}/optify/optify.pyi +0 -0
- {optify-0.12.1 → optify-0.13.0}/optify/py.typed +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/.gitignore +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/.vscode/settings.json +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/LICENSE.txt +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/README.md +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/src/lib.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/src/preferences.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/src/provider.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/src/watcher.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/tests/test_builder.py +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/tests/test_dacite.py +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/tests/test_optify.py +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/tests/test_provider.py +0 -0
- {optify-0.12.1 → optify-0.13.0}/python/optify/tests/test_pydantic.py +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/builder_trait.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/get_canonical_feature_name.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/get_supported_extensions.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/builder/mod.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/configurable_string/mod.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/configurable_values/configurable_list_impl.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/configurable_values/mod.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/json/escape_json_pointer.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/json/reader.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/policies/mod.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/policies/policies_file_contents.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/policies/policy_denied_error.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/policies/validate_requester_policies.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/provider/constraints.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/schema/feature.rs +0 -0
- {optify-0.12.1 → optify-0.13.0}/rust/optify/src/schema/mod.rs +0 -0
|
@@ -26,11 +26,11 @@ build-backend = "maturin"
|
|
|
26
26
|
|
|
27
27
|
[package]
|
|
28
28
|
name = "optify"
|
|
29
|
-
version = "0.
|
|
29
|
+
version = "0.13.0"
|
|
30
30
|
|
|
31
31
|
[tool.poetry]
|
|
32
32
|
name = "optify"
|
|
33
|
-
version = "0.
|
|
33
|
+
version = "0.13.0"
|
|
34
34
|
description = "Simplifies getting the right configuration options for a process using pre-loaded configurations from files to manage options for experiments or flights."
|
|
35
35
|
authors = ["Justin D. Harris"]
|
|
36
36
|
maintainers = ["Justin D. Harris"]
|
|
@@ -954,7 +954,7 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
|
954
954
|
|
|
955
955
|
[[package]]
|
|
956
956
|
name = "optify"
|
|
957
|
-
version = "1.
|
|
957
|
+
version = "1.6.0"
|
|
958
958
|
dependencies = [
|
|
959
959
|
"config",
|
|
960
960
|
"cow-utils",
|
|
@@ -975,7 +975,7 @@ dependencies = [
|
|
|
975
975
|
|
|
976
976
|
[[package]]
|
|
977
977
|
name = "optify-python"
|
|
978
|
-
version = "0.
|
|
978
|
+
version = "0.13.0"
|
|
979
979
|
dependencies = [
|
|
980
980
|
"optify",
|
|
981
981
|
"pyo3",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "optify-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.13.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
|
|
6
6
|
description = "Simplifies getting the right configuration options for a process using pre-loaded configurations from files (JSON, YAML, etc.) to manage options for experiments or flights. This library is mainly made to support building implementations for other languages such as Node.js, Python, and Ruby. It is not meant to be consumed directly yet."
|
|
@@ -15,5 +15,5 @@ name = "optify"
|
|
|
15
15
|
crate-type = ["cdylib"]
|
|
16
16
|
|
|
17
17
|
[dependencies]
|
|
18
|
-
optify = { path = "../../rust/optify", version = "1.
|
|
18
|
+
optify = { path = "../../rust/optify", version = "1.6.0" }
|
|
19
19
|
pyo3 = "0.29.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "optify"
|
|
3
|
-
version = "1.
|
|
3
|
+
version = "1.6.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
build = "build.rs"
|
|
6
6
|
|
|
@@ -17,6 +17,9 @@ exclude = [
|
|
|
17
17
|
"tests/*",
|
|
18
18
|
]
|
|
19
19
|
|
|
20
|
+
[lints]
|
|
21
|
+
workspace = true
|
|
22
|
+
|
|
20
23
|
[dependencies]
|
|
21
24
|
config = { version = "0.15.25", features = ["preserve_order"] }
|
|
22
25
|
cow-utils = "0.1.3"
|
|
@@ -56,6 +56,22 @@ Use `get_all_options` when you want the full merged options object instead of on
|
|
|
56
56
|
let options = provider.get_all_options(&["feature_A", "feature_B/initial"], None, None)?;
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
Use `analyze` to explain which feature and chain of imports set a value.
|
|
60
|
+
Analysis must be enabled with `BuilderOptions.is_analysis_enabled` because it retains more data.
|
|
61
|
+
See [Analysis](../../docs/Analysis.md) for details.
|
|
62
|
+
|
|
63
|
+
```rust
|
|
64
|
+
use optify::builder::BuilderOptions;
|
|
65
|
+
|
|
66
|
+
let options = BuilderOptions {
|
|
67
|
+
is_analysis_enabled: true,
|
|
68
|
+
..Default::default()
|
|
69
|
+
};
|
|
70
|
+
let provider = OptionsProvider::build_with_options("path/to/configs", options)?;
|
|
71
|
+
let analysis = provider.analyze("/myConfig/myArray", &["feature_A", "feature_B/initial"], None)?;
|
|
72
|
+
println!("{:?}", analysis.origins[0].source.defining_feature());
|
|
73
|
+
```
|
|
74
|
+
|
|
59
75
|
See [tests] for examples and tests for different implementations of this format for managing options.
|
|
60
76
|
|
|
61
77
|
## How It Works
|
|
@@ -18,7 +18,7 @@ fn benchmark_cache_vs_no_cache(c: &mut Criterion) {
|
|
|
18
18
|
let _ = provider
|
|
19
19
|
.get_all_options(black_box(&features_a), None, None)
|
|
20
20
|
.unwrap();
|
|
21
|
-
})
|
|
21
|
+
});
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
// Benchmark with caching (should be faster after first call)
|
|
@@ -32,7 +32,7 @@ fn benchmark_cache_vs_no_cache(c: &mut Criterion) {
|
|
|
32
32
|
let _ = provider
|
|
33
33
|
.get_all_options(black_box(&features_a), Some(&cache_options), None)
|
|
34
34
|
.unwrap();
|
|
35
|
-
})
|
|
35
|
+
});
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// Benchmark specific config retrieval without cache
|
|
@@ -46,7 +46,7 @@ fn benchmark_cache_vs_no_cache(c: &mut Criterion) {
|
|
|
46
46
|
None,
|
|
47
47
|
)
|
|
48
48
|
.unwrap();
|
|
49
|
-
})
|
|
49
|
+
});
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
// Benchmark specific config retrieval with cache
|
|
@@ -65,7 +65,7 @@ fn benchmark_cache_vs_no_cache(c: &mut Criterion) {
|
|
|
65
65
|
None,
|
|
66
66
|
)
|
|
67
67
|
.unwrap();
|
|
68
|
-
})
|
|
68
|
+
});
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
group.finish();
|
|
@@ -87,7 +87,7 @@ fn benchmark_cache_with_preferences(c: &mut Criterion) {
|
|
|
87
87
|
let _ = provider
|
|
88
88
|
.get_all_options(black_box(&features_a), None, Some(&preferences))
|
|
89
89
|
.unwrap();
|
|
90
|
-
})
|
|
90
|
+
});
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
// Benchmark with caching and preferences (cache hit)
|
|
@@ -108,7 +108,7 @@ fn benchmark_cache_with_preferences(c: &mut Criterion) {
|
|
|
108
108
|
Some(&preferences),
|
|
109
109
|
)
|
|
110
110
|
.unwrap();
|
|
111
|
-
})
|
|
111
|
+
});
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
group.finish();
|
|
@@ -127,7 +127,7 @@ fn benchmark_cache_multiple_features(c: &mut Criterion) {
|
|
|
127
127
|
let _ = provider
|
|
128
128
|
.get_all_options(black_box(&features_a_b), None, None)
|
|
129
129
|
.unwrap();
|
|
130
|
-
})
|
|
130
|
+
});
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
// Benchmark with caching for multiple features (cache hit)
|
|
@@ -141,7 +141,7 @@ fn benchmark_cache_multiple_features(c: &mut Criterion) {
|
|
|
141
141
|
let _ = provider
|
|
142
142
|
.get_all_options(black_box(&features_a_b), Some(&cache_options), None)
|
|
143
143
|
.unwrap();
|
|
144
|
-
})
|
|
144
|
+
});
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
group.finish();
|
|
@@ -162,7 +162,7 @@ fn benchmark_cache_performance_scaling(c: &mut Criterion) {
|
|
|
162
162
|
.get_all_options(black_box(&features_a), None, None)
|
|
163
163
|
.unwrap();
|
|
164
164
|
}
|
|
165
|
-
})
|
|
165
|
+
});
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
// Benchmark repeated calls with caching (should show significant improvement)
|
|
@@ -178,7 +178,7 @@ fn benchmark_cache_performance_scaling(c: &mut Criterion) {
|
|
|
178
178
|
.get_all_options(black_box(&features_a), Some(&cache_options), None)
|
|
179
179
|
.unwrap();
|
|
180
180
|
}
|
|
181
|
-
})
|
|
181
|
+
});
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
group.finish();
|
|
@@ -45,7 +45,7 @@ fn benchmark_get_all_options_breakdown(c: &mut Criterion) {
|
|
|
45
45
|
provider
|
|
46
46
|
.get_all_options(black_box(features), None, None)
|
|
47
47
|
.unwrap()
|
|
48
|
-
})
|
|
48
|
+
});
|
|
49
49
|
},
|
|
50
50
|
);
|
|
51
51
|
}
|
|
@@ -74,7 +74,7 @@ fn benchmark_configurable_strings(c: &mut Criterion) {
|
|
|
74
74
|
provider
|
|
75
75
|
.get_all_options(black_box(&features_with_files), None, None)
|
|
76
76
|
.unwrap()
|
|
77
|
-
})
|
|
77
|
+
});
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
// With configurable strings enabled
|
|
@@ -86,7 +86,7 @@ fn benchmark_configurable_strings(c: &mut Criterion) {
|
|
|
86
86
|
provider
|
|
87
87
|
.get_all_options(black_box(&features_with_files), None, Some(&preferences))
|
|
88
88
|
.unwrap()
|
|
89
|
-
})
|
|
89
|
+
});
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
group.finish();
|
|
@@ -105,7 +105,7 @@ fn benchmark_with_overrides(c: &mut Criterion) {
|
|
|
105
105
|
provider
|
|
106
106
|
.get_all_options(black_box(&features), None, None)
|
|
107
107
|
.unwrap()
|
|
108
|
-
})
|
|
108
|
+
});
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
// With small override
|
|
@@ -117,7 +117,7 @@ fn benchmark_with_overrides(c: &mut Criterion) {
|
|
|
117
117
|
provider
|
|
118
118
|
.get_all_options(black_box(&features), None, Some(&preferences))
|
|
119
119
|
.unwrap()
|
|
120
|
-
})
|
|
120
|
+
});
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
// With larger override
|
|
@@ -139,7 +139,7 @@ fn benchmark_with_overrides(c: &mut Criterion) {
|
|
|
139
139
|
provider
|
|
140
140
|
.get_all_options(black_box(&features), None, Some(&preferences))
|
|
141
141
|
.unwrap()
|
|
142
|
-
})
|
|
142
|
+
});
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
group.finish();
|
|
@@ -50,7 +50,7 @@ fn benchmark_get_options_with_preferences_breakdown(c: &mut Criterion) {
|
|
|
50
50
|
provider
|
|
51
51
|
.get_options(black_box(*key), black_box(*features))
|
|
52
52
|
.unwrap()
|
|
53
|
-
})
|
|
53
|
+
});
|
|
54
54
|
},
|
|
55
55
|
);
|
|
56
56
|
|
|
@@ -69,7 +69,7 @@ fn benchmark_get_options_with_preferences_breakdown(c: &mut Criterion) {
|
|
|
69
69
|
Some(&preferences),
|
|
70
70
|
)
|
|
71
71
|
.unwrap()
|
|
72
|
-
})
|
|
72
|
+
});
|
|
73
73
|
},
|
|
74
74
|
);
|
|
75
75
|
|
|
@@ -93,7 +93,7 @@ fn benchmark_get_options_with_preferences_breakdown(c: &mut Criterion) {
|
|
|
93
93
|
None,
|
|
94
94
|
)
|
|
95
95
|
.unwrap()
|
|
96
|
-
})
|
|
96
|
+
});
|
|
97
97
|
},
|
|
98
98
|
);
|
|
99
99
|
|
|
@@ -106,7 +106,7 @@ fn benchmark_get_options_with_preferences_breakdown(c: &mut Criterion) {
|
|
|
106
106
|
provider
|
|
107
107
|
.get_filtered_feature_names(black_box(features), None)
|
|
108
108
|
.unwrap()
|
|
109
|
-
})
|
|
109
|
+
});
|
|
110
110
|
},
|
|
111
111
|
);
|
|
112
112
|
|
|
@@ -119,7 +119,7 @@ fn benchmark_get_options_with_preferences_breakdown(c: &mut Criterion) {
|
|
|
119
119
|
provider
|
|
120
120
|
.get_canonical_feature_names(black_box(features))
|
|
121
121
|
.unwrap()
|
|
122
|
-
})
|
|
122
|
+
});
|
|
123
123
|
},
|
|
124
124
|
);
|
|
125
125
|
}
|
|
@@ -145,7 +145,7 @@ fn benchmark_with_overrides(c: &mut Criterion) {
|
|
|
145
145
|
None,
|
|
146
146
|
)
|
|
147
147
|
.unwrap()
|
|
148
|
-
})
|
|
148
|
+
});
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
// With small override
|
|
@@ -162,7 +162,7 @@ fn benchmark_with_overrides(c: &mut Criterion) {
|
|
|
162
162
|
Some(&preferences),
|
|
163
163
|
)
|
|
164
164
|
.unwrap()
|
|
165
|
-
})
|
|
165
|
+
});
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
// With larger override
|
|
@@ -189,7 +189,7 @@ fn benchmark_with_overrides(c: &mut Criterion) {
|
|
|
189
189
|
Some(&preferences),
|
|
190
190
|
)
|
|
191
191
|
.unwrap()
|
|
192
|
-
})
|
|
192
|
+
});
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
group.finish();
|
|
@@ -214,7 +214,7 @@ fn benchmark_skip_feature_name_conversion(c: &mut Criterion) {
|
|
|
214
214
|
Some(&preferences),
|
|
215
215
|
)
|
|
216
216
|
.unwrap()
|
|
217
|
-
})
|
|
217
|
+
});
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
// Without feature name conversion
|
|
@@ -231,7 +231,7 @@ fn benchmark_skip_feature_name_conversion(c: &mut Criterion) {
|
|
|
231
231
|
Some(&preferences),
|
|
232
232
|
)
|
|
233
233
|
.unwrap()
|
|
234
|
-
})
|
|
234
|
+
});
|
|
235
235
|
});
|
|
236
236
|
|
|
237
237
|
group.finish();
|
|
@@ -277,7 +277,7 @@ fn benchmark_many_features(c: &mut Criterion) {
|
|
|
277
277
|
black_box(preferences),
|
|
278
278
|
)
|
|
279
279
|
.unwrap()
|
|
280
|
-
})
|
|
280
|
+
});
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
283
|
|
|
@@ -68,7 +68,7 @@ fn create_test_files(dir: &Path, num_files: usize) {
|
|
|
68
68
|
i - 1
|
|
69
69
|
)
|
|
70
70
|
} else {
|
|
71
|
-
|
|
71
|
+
String::new()
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
let content = format!(
|
|
@@ -99,8 +99,8 @@ options:
|
|
|
99
99
|
let mut file = fs::File::create(&file_path).unwrap();
|
|
100
100
|
|
|
101
101
|
let content = format!(
|
|
102
|
-
r
|
|
103
|
-
"
|
|
102
|
+
r"This is what goes in the file {i}
|
|
103
|
+
"
|
|
104
104
|
);
|
|
105
105
|
file.write_all(content.as_bytes()).unwrap();
|
|
106
106
|
}
|
|
@@ -134,7 +134,7 @@ fn benchmark_loading(c: &mut Criterion) {
|
|
|
134
134
|
.unwrap(),
|
|
135
135
|
);
|
|
136
136
|
builder.add_directory(black_box(test_dir)).unwrap();
|
|
137
|
-
})
|
|
137
|
+
});
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
group.finish();
|
|
@@ -35,19 +35,25 @@ fn copy_schema_file() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if let Some(path) = source_path {
|
|
38
|
-
fs::copy(path, &dest_path)
|
|
39
|
-
|
|
38
|
+
fs::copy(path, &dest_path).unwrap_or_else(|e| {
|
|
39
|
+
panic!(
|
|
40
|
+
"Failed to copy schema file from \"{}\": {e}",
|
|
41
|
+
path.display()
|
|
42
|
+
)
|
|
43
|
+
});
|
|
40
44
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
41
45
|
} else {
|
|
42
46
|
panic!(
|
|
43
|
-
"Schema file not found at any of the expected locations: {possible_paths:?}. If you are running `cargo publish`, then the schema needs to be copied from {
|
|
47
|
+
"Schema file not found at any of the expected locations: {possible_paths:?}. If you are running `cargo publish`, then the schema needs to be copied from \"{}\" to \"{}\".",
|
|
48
|
+
original_path.display(),
|
|
49
|
+
copied_path.display(),
|
|
44
50
|
);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
Ok(())
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
/// Dynamically generate the tests for each folder in tests/test_suites
|
|
56
|
+
/// Dynamically generate the tests for each folder in `tests/test_suites`.
|
|
51
57
|
fn generate_test_suites() {
|
|
52
58
|
let test_suites_path = Path::new("../../tests/test_suites");
|
|
53
59
|
if !test_suites_path.exists() {
|
|
@@ -17,14 +17,18 @@ use crate::configurable_values::locator::{find_configurable_values, Configurable
|
|
|
17
17
|
use crate::json::merge::{merge_json_with_defaults, FrozenPaths};
|
|
18
18
|
use crate::json::reader::read_json_from_file_as;
|
|
19
19
|
use crate::policies::PolicyStore;
|
|
20
|
+
use crate::provider::analysis::AnalysisData;
|
|
20
21
|
use crate::provider::{
|
|
21
|
-
Aliases, Conditions, Features, OptionsProvider, ReferencedFileToFeatureNames, Sources,
|
|
22
|
+
Aliases, Conditions, Features, Imports, OptionsProvider, ReferencedFileToFeatureNames, Sources,
|
|
22
23
|
};
|
|
23
24
|
use crate::schema::feature::FeatureConfiguration;
|
|
24
25
|
use crate::schema::metadata::OptionsMetadata;
|
|
25
26
|
|
|
26
27
|
type Dependents = HashMap<String, Vec<String>>;
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
// Load the embedded schema file (this is resolved at compile time).
|
|
30
|
+
const EMBEDDED_SCHEMA: &[u8] =
|
|
31
|
+
include_bytes!(concat!(env!("OUT_DIR"), "/schemas/feature_file.json"));
|
|
28
32
|
|
|
29
33
|
/// A builder to use in production to create an `OptionsProvider`.
|
|
30
34
|
#[derive(Clone)]
|
|
@@ -37,6 +41,8 @@ pub struct OptionsProviderBuilder {
|
|
|
37
41
|
dependents: Dependents,
|
|
38
42
|
features: Features,
|
|
39
43
|
imports: Imports,
|
|
44
|
+
/// Set when the builder options or the config for any added directory enable analysis.
|
|
45
|
+
is_analysis_enabled: bool,
|
|
40
46
|
keyed_configurable_list_pointers: HashMap<String, HashSet<String>>,
|
|
41
47
|
keyed_configurable_string_pointers: HashMap<String, HashSet<String>>,
|
|
42
48
|
loaded_files: LoadedFiles,
|
|
@@ -140,10 +146,9 @@ fn resolve_imports(
|
|
|
140
146
|
|
|
141
147
|
// Get the source so that we can build the configuration.
|
|
142
148
|
// Getting the source also ensures the import is a canonical feature name.
|
|
143
|
-
let mut source =
|
|
144
|
-
Some(s) => s,
|
|
149
|
+
let Some(mut source) = sources.get(import) else {
|
|
145
150
|
// The import is not a canonical feature name.
|
|
146
|
-
|
|
151
|
+
match aliases.get(&unicase::UniCase::new(import.clone())) {
|
|
147
152
|
Some(canonical_name_for_import) => {
|
|
148
153
|
return Err(format!(
|
|
149
154
|
"Error when resolving imports for '{canonical_feature_name}': The import '{import}' is not a canonical feature name. Use '{canonical_name_for_import}' instead of '{import}' in order to keep dependencies clear and to help with navigating through files."
|
|
@@ -154,18 +159,19 @@ fn resolve_imports(
|
|
|
154
159
|
"Error when resolving imports for '{canonical_feature_name}': The import '{import}' is not a canonical feature name and not a recognized alias. Use a canonical feature name in order to keep dependencies clear and to help with navigating through files."
|
|
155
160
|
))
|
|
156
161
|
}
|
|
157
|
-
}
|
|
162
|
+
}
|
|
158
163
|
};
|
|
159
164
|
|
|
160
165
|
if resolved_imports.insert(import.clone()) {
|
|
161
166
|
if let Some(imports_for_import) = all_imports.get(import) {
|
|
162
|
-
let mut
|
|
163
|
-
|
|
167
|
+
let mut features_in_resolution_path_for_import =
|
|
168
|
+
features_in_resolution_path.clone();
|
|
169
|
+
features_in_resolution_path_for_import.insert(import.clone());
|
|
164
170
|
resolve_imports(
|
|
165
171
|
import,
|
|
166
172
|
imports_for_import,
|
|
167
173
|
resolved_imports,
|
|
168
|
-
&mut
|
|
174
|
+
&mut features_in_resolution_path_for_import,
|
|
169
175
|
aliases,
|
|
170
176
|
all_dependents,
|
|
171
177
|
all_imports,
|
|
@@ -186,6 +192,7 @@ fn resolve_imports(
|
|
|
186
192
|
}
|
|
187
193
|
|
|
188
194
|
impl OptionsProviderBuilder {
|
|
195
|
+
#[must_use]
|
|
189
196
|
pub fn new() -> Self {
|
|
190
197
|
OptionsProviderBuilder {
|
|
191
198
|
aliases: Aliases::new(),
|
|
@@ -196,6 +203,7 @@ impl OptionsProviderBuilder {
|
|
|
196
203
|
dependents: Dependents::new(),
|
|
197
204
|
features: Features::new(),
|
|
198
205
|
imports: HashMap::new(),
|
|
206
|
+
is_analysis_enabled: false,
|
|
199
207
|
keyed_configurable_list_pointers: HashMap::new(),
|
|
200
208
|
keyed_configurable_string_pointers: HashMap::new(),
|
|
201
209
|
loaded_files: LoadedFiles::new(),
|
|
@@ -207,6 +215,7 @@ impl OptionsProviderBuilder {
|
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
pub fn build_and_clear(&mut self) -> Result<OptionsProvider, String> {
|
|
218
|
+
let analysis_data = self.create_analysis_data();
|
|
210
219
|
self.prepare_build()?;
|
|
211
220
|
|
|
212
221
|
let all_configurable_list_pointers =
|
|
@@ -236,6 +245,7 @@ impl OptionsProviderBuilder {
|
|
|
236
245
|
std::mem::take(&mut self.aliases),
|
|
237
246
|
all_configurable_list_pointers,
|
|
238
247
|
all_configurable_string_pointers,
|
|
248
|
+
analysis_data,
|
|
239
249
|
keyed_configurable_list_pointers,
|
|
240
250
|
keyed_configurable_string_pointers,
|
|
241
251
|
std::mem::take(&mut self.conditions),
|
|
@@ -247,6 +257,16 @@ impl OptionsProviderBuilder {
|
|
|
247
257
|
))
|
|
248
258
|
}
|
|
249
259
|
|
|
260
|
+
/// Captures each feature's own options and imports before imports are merged into the sources.
|
|
261
|
+
fn create_analysis_data(&self) -> Option<AnalysisData> {
|
|
262
|
+
(self.is_analysis_enabled || self.builder_options.is_analysis_enabled).then(|| {
|
|
263
|
+
AnalysisData {
|
|
264
|
+
imports: self.imports.clone(),
|
|
265
|
+
raw_sources: self.sources.clone(),
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
|
|
250
270
|
fn prepare_build(&mut self) -> Result<(), String> {
|
|
251
271
|
let mut resolved_imports: HashSet<String> = HashSet::new();
|
|
252
272
|
for (canonical_feature_name, imports_for_feature) in &self.imports {
|
|
@@ -288,7 +308,7 @@ impl OptionsProviderBuilder {
|
|
|
288
308
|
directory: &Path,
|
|
289
309
|
builder_options: &BuilderOptions,
|
|
290
310
|
supported_extensions: &HashSet<&str>,
|
|
291
|
-
feature_contents_validator:
|
|
311
|
+
feature_contents_validator: Option<&Arc<Validator>>,
|
|
292
312
|
) -> Result<LoadingResult, String> {
|
|
293
313
|
let is_config_file = match path.extension() {
|
|
294
314
|
Some(ext) => match ext.to_str() {
|
|
@@ -420,9 +440,9 @@ impl OptionsProviderBuilder {
|
|
|
420
440
|
}
|
|
421
441
|
|
|
422
442
|
fn validate_with_schema(
|
|
423
|
-
validator:
|
|
443
|
+
validator: Option<&Arc<Validator>>,
|
|
424
444
|
original_config: &serde_json::Value,
|
|
425
|
-
path: &
|
|
445
|
+
path: &str,
|
|
426
446
|
) -> Result<(), String> {
|
|
427
447
|
match validator {
|
|
428
448
|
Some(validator) => {
|
|
@@ -432,8 +452,7 @@ fn validate_with_schema(
|
|
|
432
452
|
let errors = validator.iter_errors(original_config);
|
|
433
453
|
let error_messages: Vec<String> = errors.map(|e| format!("{e}")).collect();
|
|
434
454
|
Err(format!(
|
|
435
|
-
"Schema validation failed for {
|
|
436
|
-
path,
|
|
455
|
+
"Schema validation failed for \"{path}\": {}",
|
|
437
456
|
error_messages.join(", ")
|
|
438
457
|
))
|
|
439
458
|
}
|
|
@@ -446,7 +465,7 @@ fn process_config_file_entry(
|
|
|
446
465
|
path: &Path,
|
|
447
466
|
directory: &Path,
|
|
448
467
|
builder_options: &BuilderOptions,
|
|
449
|
-
feature_contents_validator:
|
|
468
|
+
feature_contents_validator: Option<&Arc<Validator>>,
|
|
450
469
|
) -> Result<LoadingResult, String> {
|
|
451
470
|
let absolute_path = dunce::canonicalize(path)
|
|
452
471
|
.expect("path should be valid")
|
|
@@ -459,7 +478,7 @@ fn process_config_file_entry(
|
|
|
459
478
|
let file = config::File::from(path);
|
|
460
479
|
let config_for_path = match config::Config::builder().add_source(file).build() {
|
|
461
480
|
Ok(conf) => conf,
|
|
462
|
-
Err(e) => return Err(format!("Error loading file '{}': {e}"
|
|
481
|
+
Err(e) => return Err(format!("Error loading file '{absolute_path}': {e}")),
|
|
463
482
|
};
|
|
464
483
|
|
|
465
484
|
// We need the raw JSON for validation.
|
|
@@ -467,8 +486,7 @@ fn process_config_file_entry(
|
|
|
467
486
|
Ok(v) => v,
|
|
468
487
|
Err(e) => {
|
|
469
488
|
return Err(format!(
|
|
470
|
-
"Error deserializing configuration for file '{}': {e}",
|
|
471
|
-
absolute_path,
|
|
489
|
+
"Error deserializing configuration for file '{absolute_path}': {e}",
|
|
472
490
|
))
|
|
473
491
|
}
|
|
474
492
|
};
|
|
@@ -479,8 +497,7 @@ fn process_config_file_entry(
|
|
|
479
497
|
Ok(v) => v,
|
|
480
498
|
Err(e) => {
|
|
481
499
|
return Err(format!(
|
|
482
|
-
"Error deserializing configuration for file '{}': {e}",
|
|
483
|
-
absolute_path,
|
|
500
|
+
"Error deserializing configuration for file '{absolute_path}': {e}",
|
|
484
501
|
))
|
|
485
502
|
}
|
|
486
503
|
};
|
|
@@ -553,7 +570,8 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
|
|
|
553
570
|
let directory = directory.as_ref();
|
|
554
571
|
if !directory.is_dir() {
|
|
555
572
|
return Err(format!(
|
|
556
|
-
"Error adding directory: {
|
|
573
|
+
"Error adding directory: \"{}\" is not a directory",
|
|
574
|
+
directory.display()
|
|
557
575
|
));
|
|
558
576
|
}
|
|
559
577
|
|
|
@@ -572,6 +590,7 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
|
|
|
572
590
|
} else {
|
|
573
591
|
self.builder_options.clone()
|
|
574
592
|
};
|
|
593
|
+
self.is_analysis_enabled |= builder_options.is_analysis_enabled;
|
|
575
594
|
|
|
576
595
|
if let Some(policies_path) = &builder_options.policies_path {
|
|
577
596
|
self.policy_store
|
|
@@ -618,7 +637,7 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
|
|
|
618
637
|
directory,
|
|
619
638
|
&builder_options,
|
|
620
639
|
&supported_extensions,
|
|
621
|
-
|
|
640
|
+
self.schema.as_ref(),
|
|
622
641
|
)
|
|
623
642
|
})
|
|
624
643
|
.collect()
|
|
@@ -650,9 +669,6 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
|
|
|
650
669
|
)
|
|
651
670
|
})?;
|
|
652
671
|
|
|
653
|
-
// Load the embedded schema file (this is resolved at compile time).
|
|
654
|
-
const EMBEDDED_SCHEMA: &[u8] =
|
|
655
|
-
include_bytes!(concat!(env!("OUT_DIR"), "/schemas/feature_file.json"));
|
|
656
672
|
let optify_schema_json: serde_json::Value = serde_json::from_slice(EMBEDDED_SCHEMA)
|
|
657
673
|
.map_err(|e| format!("Failed to parse embedded schema: {e}"))?;
|
|
658
674
|
let registry = Registry::new()
|
|
@@ -676,6 +692,7 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
|
|
|
676
692
|
}
|
|
677
693
|
|
|
678
694
|
fn build(&mut self) -> Result<OptionsProvider, String> {
|
|
695
|
+
let analysis_data = self.create_analysis_data();
|
|
679
696
|
self.prepare_build()?;
|
|
680
697
|
|
|
681
698
|
let all_configurable_string_pointers = self
|
|
@@ -706,6 +723,7 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
|
|
|
706
723
|
self.aliases.clone(),
|
|
707
724
|
all_configurable_list_pointers,
|
|
708
725
|
all_configurable_string_pointers,
|
|
726
|
+
analysis_data,
|
|
709
727
|
keyed_configurable_list_pointers,
|
|
710
728
|
keyed_configurable_string_pointers,
|
|
711
729
|
self.conditions.clone(),
|