optify 0.2.0__tar.gz → 0.5.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.2.0 → optify-0.5.0}/PKG-INFO +30 -2
- {optify-0.2.0 → optify-0.5.0}/README.md +29 -1
- {optify-0.2.0 → optify-0.5.0}/pyproject.toml +2 -2
- {optify-0.2.0 → optify-0.5.0}/python/optify/Cargo.lock +41 -2
- {optify-0.2.0 → optify-0.5.0}/python/optify/Cargo.toml +2 -2
- {optify-0.2.0 → optify-0.5.0}/python/optify/README.md +29 -1
- optify-0.5.0/python/optify/src/lib.rs +123 -0
- optify-0.5.0/python/optify/tests/test_builder.py +14 -0
- {optify-0.2.0 → optify-0.5.0}/python/optify/tests/test_optify.py +10 -5
- {optify-0.2.0 → optify-0.5.0}/python/optify/tests/test_provider.py +15 -5
- {optify-0.2.0 → optify-0.5.0}/rust/optify/Cargo.toml +3 -1
- {optify-0.2.0 → optify-0.5.0}/rust/optify/benches/loading_benchmark.rs +6 -8
- optify-0.5.0/rust/optify/build.rs +30 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/builder/builder_impl.rs +68 -14
- optify-0.5.0/rust/optify/src/provider/constraints.rs +4 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/provider/mod.rs +1 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/provider/provider_impl.rs +85 -37
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/provider/provider_trait.rs +22 -10
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/provider/watcher.rs +73 -37
- optify-0.5.0/rust/optify/src/schema/conditions.rs +170 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/schema/feature.rs +5 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/schema/mod.rs +1 -0
- optify-0.2.0/python/optify/src/lib.rs +0 -78
- {optify-0.2.0 → optify-0.5.0}/python/optify/.gitignore +0 -0
- {optify-0.2.0 → optify-0.5.0}/python/optify/LICENSE.txt +0 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/README.md +0 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/builder/builder_trait.rs +0 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/builder/mod.rs +0 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/builder/watcher_builder.rs +0 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/lib.rs +0 -0
- {optify-0.2.0 → optify-0.5.0}/rust/optify/src/schema/metadata.rs +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: optify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -28,7 +28,35 @@ This is just meant to be minimal to get started and help build a Python library.
|
|
|
28
28
|
See the [homepage] for details.
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
|
-
|
|
31
|
+
```Python
|
|
32
|
+
import json
|
|
33
|
+
from optify import OptionsProvider
|
|
34
|
+
|
|
35
|
+
provider = OptionsProvider.build('path/to/configs')
|
|
36
|
+
config = provider.get_options_json('key', ['feature_A', 'feature_B'])
|
|
37
|
+
print(config)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Outputs:
|
|
41
|
+
```JSON
|
|
42
|
+
{
|
|
43
|
+
"myArray": [
|
|
44
|
+
"item 1",
|
|
45
|
+
"item 2"
|
|
46
|
+
],
|
|
47
|
+
"myObject": {
|
|
48
|
+
"deeper": {
|
|
49
|
+
"new": "new value",
|
|
50
|
+
"num": 3333
|
|
51
|
+
},
|
|
52
|
+
"key": "val",
|
|
53
|
+
},
|
|
54
|
+
"rootString": "root string same"
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
See the [tests directory](./tests/) for more examples.
|
|
32
60
|
|
|
33
61
|
## Development
|
|
34
62
|
|
|
@@ -10,7 +10,35 @@ This is just meant to be minimal to get started and help build a Python library.
|
|
|
10
10
|
See the [homepage] for details.
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
|
-
|
|
13
|
+
```Python
|
|
14
|
+
import json
|
|
15
|
+
from optify import OptionsProvider
|
|
16
|
+
|
|
17
|
+
provider = OptionsProvider.build('path/to/configs')
|
|
18
|
+
config = provider.get_options_json('key', ['feature_A', 'feature_B'])
|
|
19
|
+
print(config)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Outputs:
|
|
23
|
+
```JSON
|
|
24
|
+
{
|
|
25
|
+
"myArray": [
|
|
26
|
+
"item 1",
|
|
27
|
+
"item 2"
|
|
28
|
+
],
|
|
29
|
+
"myObject": {
|
|
30
|
+
"deeper": {
|
|
31
|
+
"new": "new value",
|
|
32
|
+
"num": 3333
|
|
33
|
+
},
|
|
34
|
+
"key": "val",
|
|
35
|
+
},
|
|
36
|
+
"rootString": "root string same"
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
See the [tests directory](./tests/) for more examples.
|
|
14
42
|
|
|
15
43
|
## Development
|
|
16
44
|
|
|
@@ -26,11 +26,11 @@ build-backend = "maturin"
|
|
|
26
26
|
|
|
27
27
|
[package]
|
|
28
28
|
name = "optify"
|
|
29
|
-
version = "0.
|
|
29
|
+
version = "0.5.0"
|
|
30
30
|
|
|
31
31
|
[tool.poetry]
|
|
32
32
|
name = "optify"
|
|
33
|
-
version = "0.
|
|
33
|
+
version = "0.5.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"]
|
|
@@ -14,6 +14,15 @@ dependencies = [
|
|
|
14
14
|
"zerocopy",
|
|
15
15
|
]
|
|
16
16
|
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "aho-corasick"
|
|
19
|
+
version = "1.1.3"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
|
22
|
+
dependencies = [
|
|
23
|
+
"memchr",
|
|
24
|
+
]
|
|
25
|
+
|
|
17
26
|
[[package]]
|
|
18
27
|
name = "arraydeque"
|
|
19
28
|
version = "0.5.1"
|
|
@@ -461,12 +470,13 @@ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
|
|
|
461
470
|
|
|
462
471
|
[[package]]
|
|
463
472
|
name = "optify"
|
|
464
|
-
version = "0.
|
|
473
|
+
version = "0.14.0"
|
|
465
474
|
dependencies = [
|
|
466
475
|
"config",
|
|
467
476
|
"notify",
|
|
468
477
|
"notify-debouncer-full",
|
|
469
478
|
"rayon",
|
|
479
|
+
"regex",
|
|
470
480
|
"serde",
|
|
471
481
|
"serde_derive",
|
|
472
482
|
"serde_json",
|
|
@@ -476,7 +486,7 @@ dependencies = [
|
|
|
476
486
|
|
|
477
487
|
[[package]]
|
|
478
488
|
name = "optify-python"
|
|
479
|
-
version = "0.
|
|
489
|
+
version = "0.5.0"
|
|
480
490
|
dependencies = [
|
|
481
491
|
"optify",
|
|
482
492
|
"pyo3",
|
|
@@ -659,6 +669,35 @@ dependencies = [
|
|
|
659
669
|
"bitflags 2.8.0",
|
|
660
670
|
]
|
|
661
671
|
|
|
672
|
+
[[package]]
|
|
673
|
+
name = "regex"
|
|
674
|
+
version = "1.11.1"
|
|
675
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
676
|
+
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
|
677
|
+
dependencies = [
|
|
678
|
+
"aho-corasick",
|
|
679
|
+
"memchr",
|
|
680
|
+
"regex-automata",
|
|
681
|
+
"regex-syntax",
|
|
682
|
+
]
|
|
683
|
+
|
|
684
|
+
[[package]]
|
|
685
|
+
name = "regex-automata"
|
|
686
|
+
version = "0.4.9"
|
|
687
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
688
|
+
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
|
689
|
+
dependencies = [
|
|
690
|
+
"aho-corasick",
|
|
691
|
+
"memchr",
|
|
692
|
+
"regex-syntax",
|
|
693
|
+
]
|
|
694
|
+
|
|
695
|
+
[[package]]
|
|
696
|
+
name = "regex-syntax"
|
|
697
|
+
version = "0.8.5"
|
|
698
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
699
|
+
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
|
700
|
+
|
|
662
701
|
[[package]]
|
|
663
702
|
name = "ron"
|
|
664
703
|
version = "0.8.1"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "optify-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.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."
|
|
@@ -14,5 +14,5 @@ name = "optify"
|
|
|
14
14
|
crate-type = ["cdylib"]
|
|
15
15
|
|
|
16
16
|
[dependencies]
|
|
17
|
-
optify = { path = "../../rust/optify", version = "0.
|
|
17
|
+
optify = { path = "../../rust/optify", version = "0.14.0" }
|
|
18
18
|
pyo3 = "0.24.1"
|
|
@@ -10,7 +10,35 @@ This is just meant to be minimal to get started and help build a Python library.
|
|
|
10
10
|
See the [homepage] for details.
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
|
-
|
|
13
|
+
```Python
|
|
14
|
+
import json
|
|
15
|
+
from optify import OptionsProvider
|
|
16
|
+
|
|
17
|
+
provider = OptionsProvider.build('path/to/configs')
|
|
18
|
+
config = provider.get_options_json('key', ['feature_A', 'feature_B'])
|
|
19
|
+
print(config)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Outputs:
|
|
23
|
+
```JSON
|
|
24
|
+
{
|
|
25
|
+
"myArray": [
|
|
26
|
+
"item 1",
|
|
27
|
+
"item 2"
|
|
28
|
+
],
|
|
29
|
+
"myObject": {
|
|
30
|
+
"deeper": {
|
|
31
|
+
"new": "new value",
|
|
32
|
+
"num": 3333
|
|
33
|
+
},
|
|
34
|
+
"key": "val",
|
|
35
|
+
},
|
|
36
|
+
"rootString": "root string same"
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
See the [tests directory](./tests/) for more examples.
|
|
14
42
|
|
|
15
43
|
## Development
|
|
16
44
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
use pyo3::prelude::*;
|
|
2
|
+
use pyo3::types::PyType;
|
|
3
|
+
|
|
4
|
+
use optify::builder::{OptionsProviderBuilder, OptionsRegistryBuilder};
|
|
5
|
+
use optify::provider::{GetOptionsPreferences, OptionsProvider, OptionsRegistry};
|
|
6
|
+
|
|
7
|
+
#[pyclass(name = "GetOptionsPreferences")]
|
|
8
|
+
struct PyGetOptionsPreferences(GetOptionsPreferences);
|
|
9
|
+
|
|
10
|
+
#[pymethods]
|
|
11
|
+
impl PyGetOptionsPreferences {
|
|
12
|
+
#[new]
|
|
13
|
+
fn new() -> Self {
|
|
14
|
+
Self(GetOptionsPreferences::new())
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fn set_constraints_json(&mut self, constraints_json: Option<String>) {
|
|
18
|
+
self.0.set_constraints_json(constraints_json.as_deref());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#[pyclass(name = "OptionsProviderBuilder")]
|
|
23
|
+
// TODO Try to use inheritance, maybe?
|
|
24
|
+
struct PyOptionsProviderBuilder(OptionsProviderBuilder);
|
|
25
|
+
|
|
26
|
+
#[pyclass(name = "OptionsProvider")]
|
|
27
|
+
struct PyOptionsProvider(OptionsProvider);
|
|
28
|
+
|
|
29
|
+
#[pymethods]
|
|
30
|
+
impl PyOptionsProvider {
|
|
31
|
+
#[classmethod]
|
|
32
|
+
fn build(_cls: &Bound<'_, PyType>, directory: &str) -> PyResult<PyOptionsProvider> {
|
|
33
|
+
match OptionsProvider::build(directory) {
|
|
34
|
+
Ok(provider) => Ok(PyOptionsProvider(provider)),
|
|
35
|
+
Err(e) => Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e)),
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#[classmethod]
|
|
40
|
+
fn build_from_directories(
|
|
41
|
+
_cls: &Bound<'_, PyType>,
|
|
42
|
+
directories: Vec<String>,
|
|
43
|
+
) -> PyResult<PyOptionsProvider> {
|
|
44
|
+
match OptionsProvider::build_from_directories(&directories) {
|
|
45
|
+
Ok(provider) => Ok(PyOptionsProvider(provider)),
|
|
46
|
+
Err(e) => Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e)),
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// @return All of the canonical feature names.
|
|
51
|
+
fn features(&self) -> Vec<String> {
|
|
52
|
+
self.0
|
|
53
|
+
.get_features()
|
|
54
|
+
.into_iter()
|
|
55
|
+
.map(|s| s.to_string())
|
|
56
|
+
.collect()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fn get_canonical_feature_name(&self, feature_name: &str) -> String {
|
|
60
|
+
self.0
|
|
61
|
+
.get_canonical_feature_name(feature_name)
|
|
62
|
+
.expect("feature name should be valid")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fn get_canonical_feature_names(&self, feature_names: Vec<String>) -> Vec<String> {
|
|
66
|
+
self.0
|
|
67
|
+
.get_canonical_feature_names(&feature_names)
|
|
68
|
+
.expect("feature names should be valid")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fn get_options_json(&self, key: &str, feature_names: Vec<String>) -> PyResult<String> {
|
|
72
|
+
self.get_options_json_with_preferences(key, feature_names, None)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fn get_options_json_with_preferences(
|
|
76
|
+
&self,
|
|
77
|
+
key: &str,
|
|
78
|
+
feature_names: Vec<String>,
|
|
79
|
+
preferences: Option<&PyGetOptionsPreferences>,
|
|
80
|
+
) -> PyResult<String> {
|
|
81
|
+
let preferences = preferences.map(|p| &p.0);
|
|
82
|
+
let result = &self
|
|
83
|
+
.0
|
|
84
|
+
.get_options_with_preferences(key, &feature_names, None, preferences)
|
|
85
|
+
.map_err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>)?;
|
|
86
|
+
Ok(result.to_string())
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[pymethods]
|
|
91
|
+
impl PyOptionsProviderBuilder {
|
|
92
|
+
#[new]
|
|
93
|
+
fn new() -> Self {
|
|
94
|
+
Self(OptionsProviderBuilder::new())
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fn add_directory(&mut self, directory: &str) -> PyResult<Self> {
|
|
98
|
+
let path = std::path::Path::new(&directory);
|
|
99
|
+
match self.0.add_directory(path) {
|
|
100
|
+
Ok(_) => Ok(Self(self.0.clone())),
|
|
101
|
+
Err(e) => Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e)),
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fn build(&mut self) -> PyResult<PyOptionsProvider> {
|
|
106
|
+
match self.0.build() {
|
|
107
|
+
Ok(provider) => Ok(PyOptionsProvider(provider)),
|
|
108
|
+
Err(e) => Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e)),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#[pymodule(name = "optify")]
|
|
114
|
+
mod optify_python {
|
|
115
|
+
#[pymodule_export]
|
|
116
|
+
use super::PyGetOptionsPreferences;
|
|
117
|
+
|
|
118
|
+
#[pymodule_export]
|
|
119
|
+
use super::PyOptionsProviderBuilder;
|
|
120
|
+
|
|
121
|
+
#[pymodule_export]
|
|
122
|
+
use super::PyOptionsProvider;
|
|
123
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from optify import GetOptionsPreferences, OptionsProvider, OptionsProviderBuilder
|
|
6
|
+
|
|
7
|
+
def test_bad_directory():
|
|
8
|
+
builder = OptionsProviderBuilder()
|
|
9
|
+
directory = 'bad_directory'
|
|
10
|
+
try:
|
|
11
|
+
builder.add_directory(directory)
|
|
12
|
+
assert False, "Should have raised an error"
|
|
13
|
+
except Exception as e:
|
|
14
|
+
assert str(e) == f"Error adding directory: \"{directory}\" is not a directory"
|
|
@@ -2,7 +2,7 @@ import os
|
|
|
2
2
|
import json
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
-
from optify import OptionsProviderBuilder
|
|
5
|
+
from optify import GetOptionsPreferences, OptionsProvider, OptionsProviderBuilder
|
|
6
6
|
|
|
7
7
|
def test_empty_build():
|
|
8
8
|
builder = OptionsProviderBuilder()
|
|
@@ -10,18 +10,23 @@ def test_empty_build():
|
|
|
10
10
|
assert provider is not None
|
|
11
11
|
|
|
12
12
|
def run_suite(suite_path: str) -> None:
|
|
13
|
-
provider =
|
|
14
|
-
.add_directory(os.path.join(suite_path, 'configs')) \
|
|
15
|
-
.build()
|
|
13
|
+
provider = OptionsProvider.build(os.path.join(suite_path, 'configs'))
|
|
16
14
|
expectations_path = os.path.join(suite_path, 'expectations')
|
|
17
15
|
for test_case in os.listdir(expectations_path):
|
|
18
16
|
expectation_path = os.path.join(expectations_path, test_case)
|
|
19
17
|
with open(expectation_path, 'r') as f:
|
|
20
18
|
expected_info = json.load(f)
|
|
19
|
+
constraints = expected_info.get('constraints')
|
|
20
|
+
if constraints is not None:
|
|
21
|
+
preferences = GetOptionsPreferences()
|
|
22
|
+
preferences.set_constraints_json(json.dumps(constraints))
|
|
23
|
+
else:
|
|
24
|
+
preferences = None
|
|
21
25
|
expected_options = expected_info['options']
|
|
22
26
|
features = expected_info['features']
|
|
27
|
+
|
|
23
28
|
for key, expected_value in expected_options.items():
|
|
24
|
-
actual_json = provider.
|
|
29
|
+
actual_json = provider.get_options_json_with_preferences(key, features, preferences)
|
|
25
30
|
actual_options = json.loads(actual_json)
|
|
26
31
|
assert actual_options == expected_value, (
|
|
27
32
|
f"Options for key '{key}' with features {features} do not match "
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
|
-
from optify import OptionsProviderBuilder
|
|
3
|
+
from optify import OptionsProvider, OptionsProviderBuilder
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
test_suites_dir = (Path(__file__) / '../../../../tests/test_suites').resolve()
|
|
7
|
+
simple_configs_dir = str(test_suites_dir / 'simple/configs')
|
|
7
8
|
builder = OptionsProviderBuilder()
|
|
8
|
-
builder.add_directory(
|
|
9
|
+
builder.add_directory(simple_configs_dir)
|
|
9
10
|
PROVIDER = builder.build()
|
|
10
11
|
|
|
11
12
|
def test_features():
|
|
@@ -16,8 +17,8 @@ def test_features():
|
|
|
16
17
|
try:
|
|
17
18
|
PROVIDER.get_options_json('key', ['A'])
|
|
18
19
|
assert False, "Should have raised an error"
|
|
19
|
-
except
|
|
20
|
-
assert str(e) == "
|
|
20
|
+
except Exception as e:
|
|
21
|
+
assert str(e) == "configuration property \"key\" not found"
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
def test_canonical_feature_name():
|
|
@@ -31,4 +32,13 @@ def test_canonical_feature_names():
|
|
|
31
32
|
assert PROVIDER.get_canonical_feature_names(['feature_B/initial']) == ['feature_B/initial']
|
|
32
33
|
assert PROVIDER.get_canonical_feature_names(['A_with_COmments']) == ['A_with_comments']
|
|
33
34
|
|
|
34
|
-
assert PROVIDER.get_canonical_feature_names(['A', 'B']) == ['feature_A', 'feature_B/initial']
|
|
35
|
+
assert PROVIDER.get_canonical_feature_names(['A', 'B']) == ['feature_A', 'feature_B/initial']
|
|
36
|
+
|
|
37
|
+
def test_build_from_directories():
|
|
38
|
+
provider = OptionsProvider.build_from_directories([simple_configs_dir])
|
|
39
|
+
assert provider is not None
|
|
40
|
+
features = provider.features()
|
|
41
|
+
features.sort()
|
|
42
|
+
assert features == ['A_with_comments', 'feature_A', 'feature_B/initial']
|
|
43
|
+
|
|
44
|
+
assert provider.get_options_json('myConfig', ['feature_A', 'feature_B/initial'])
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "optify"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.14.0"
|
|
4
4
|
edition = "2021"
|
|
5
|
+
build = "build.rs"
|
|
5
6
|
|
|
6
7
|
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."
|
|
7
8
|
homepage = "https://github.com/juharris/optify/tree/main/rust/optify"
|
|
@@ -21,6 +22,7 @@ config = "0.15.6"
|
|
|
21
22
|
notify = "8.0.0"
|
|
22
23
|
notify-debouncer-full = "0.5.0"
|
|
23
24
|
rayon = "1.10.0"
|
|
25
|
+
regex = "1.11.1"
|
|
24
26
|
serde = "1.0.217"
|
|
25
27
|
serde_derive = "1.0.217"
|
|
26
28
|
serde_json = "1.0.140"
|
|
@@ -26,14 +26,14 @@ fn create_test_files(dir: &Path, num_files: usize) {
|
|
|
26
26
|
fs::create_dir_all(dir).unwrap();
|
|
27
27
|
|
|
28
28
|
for i in 0..num_files / 2 {
|
|
29
|
-
let file_path = dir.join(format!("test_{}.json"
|
|
29
|
+
let file_path = dir.join(format!("test_{i}.json"));
|
|
30
30
|
let mut file = fs::File::create(&file_path).unwrap();
|
|
31
31
|
|
|
32
32
|
// Create a test configuration file with some realistic content
|
|
33
33
|
let content = format!(
|
|
34
34
|
r#"{{
|
|
35
35
|
"metadata": {{
|
|
36
|
-
"aliases": ["alias_{}_1", "alias_{}_2"]
|
|
36
|
+
"aliases": ["alias_{i}_1", "alias_{i}_2"]
|
|
37
37
|
}},
|
|
38
38
|
"options": {{
|
|
39
39
|
"setting1": "value1",
|
|
@@ -45,21 +45,20 @@ fn create_test_files(dir: &Path, num_files: usize) {
|
|
|
45
45
|
}}
|
|
46
46
|
}}
|
|
47
47
|
}}"#,
|
|
48
|
-
i, i,
|
|
49
48
|
);
|
|
50
49
|
|
|
51
50
|
file.write_all(content.as_bytes()).unwrap();
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
for i in num_files / 2..num_files {
|
|
55
|
-
let file_path = dir.join(format!("test_{}.yaml"
|
|
54
|
+
let file_path = dir.join(format!("test_{i}.yaml"));
|
|
56
55
|
let mut file = fs::File::create(&file_path).unwrap();
|
|
57
56
|
|
|
58
57
|
let content = format!(
|
|
59
58
|
r#"metadata:
|
|
60
59
|
aliases:
|
|
61
|
-
- alias_y_{}_1
|
|
62
|
-
- alias_y_{}_2
|
|
60
|
+
- alias_y_{i}_1
|
|
61
|
+
- alias_y_{i}_2
|
|
63
62
|
options:
|
|
64
63
|
setting1: value1
|
|
65
64
|
setting2: 42
|
|
@@ -68,7 +67,6 @@ options:
|
|
|
68
67
|
field1: nested_value
|
|
69
68
|
field2: [1, 2, 3]
|
|
70
69
|
"#,
|
|
71
|
-
i, i,
|
|
72
70
|
);
|
|
73
71
|
file.write_all(content.as_bytes()).unwrap();
|
|
74
72
|
}
|
|
@@ -86,7 +84,7 @@ fn benchmark_loading(c: &mut Criterion) {
|
|
|
86
84
|
|
|
87
85
|
create_test_files(test_dir, num_files);
|
|
88
86
|
|
|
89
|
-
let mut group = c.benchmark_group(format!("file_loading-{}"
|
|
87
|
+
let mut group = c.benchmark_group(format!("file_loading-{num_files}"));
|
|
90
88
|
|
|
91
89
|
group.bench_function("parallel loading", |b| {
|
|
92
90
|
b.iter(|| {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
use std::fs;
|
|
2
|
+
use std::io::Write;
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
|
|
5
|
+
fn main() {
|
|
6
|
+
generate_test_suites();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/// Dynamically generate the tests for each folder in tests/test_suites.
|
|
10
|
+
fn generate_test_suites() {
|
|
11
|
+
let out_dir = std::env::var("OUT_DIR").unwrap();
|
|
12
|
+
let dest_path = Path::new(&out_dir).join("test_suites.rs");
|
|
13
|
+
let mut f = fs::File::create(&dest_path).unwrap();
|
|
14
|
+
|
|
15
|
+
for entry in fs::read_dir("../../tests/test_suites").unwrap().flatten() {
|
|
16
|
+
let path = entry.path();
|
|
17
|
+
if path.is_dir() && !path.starts_with(".") {
|
|
18
|
+
if let Some(file_name) = path.file_name() {
|
|
19
|
+
if let Some(suite_name) = file_name.to_str() {
|
|
20
|
+
writeln!(f,
|
|
21
|
+
"#[test]\nfn test_suite_{suite_name}() {{\n test_suite(std::path::Path::new(\"../../tests/test_suites/{suite_name}\")).unwrap();\n}}\n"
|
|
22
|
+
).unwrap();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
println!("cargo:rerun-if-changed=../../tests/test_suites");
|
|
29
|
+
println!("cargo:rerun-if-changed=build.rs");
|
|
30
|
+
}
|