optify 0.2.0__tar.gz → 0.6.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.
Files changed (35) hide show
  1. {optify-0.2.0 → optify-0.6.0}/PKG-INFO +31 -3
  2. {optify-0.2.0 → optify-0.6.0}/README.md +29 -1
  3. {optify-0.2.0 → optify-0.6.0}/pyproject.toml +2 -2
  4. {optify-0.2.0 → optify-0.6.0}/python/optify/.gitignore +0 -3
  5. optify-0.6.0/python/optify/.vscode/settings.json +3 -0
  6. {optify-0.2.0 → optify-0.6.0}/python/optify/Cargo.lock +48 -2
  7. {optify-0.2.0 → optify-0.6.0}/python/optify/Cargo.toml +3 -2
  8. optify-0.6.0/python/optify/LICENSE.txt +21 -0
  9. {optify-0.2.0 → optify-0.6.0}/python/optify/README.md +29 -1
  10. optify-0.6.0/python/optify/src/lib.rs +123 -0
  11. optify-0.6.0/python/optify/tests/test_builder.py +14 -0
  12. {optify-0.2.0 → optify-0.6.0}/python/optify/tests/test_optify.py +10 -5
  13. {optify-0.2.0 → optify-0.6.0}/python/optify/tests/test_provider.py +15 -5
  14. optify-0.6.0/rust/optify/.claude/settings.json +24 -0
  15. {optify-0.2.0 → optify-0.6.0}/rust/optify/Cargo.toml +4 -1
  16. {optify-0.2.0 → optify-0.6.0}/rust/optify/benches/loading_benchmark.rs +6 -8
  17. optify-0.6.0/rust/optify/build.rs +30 -0
  18. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/builder/builder_impl.rs +78 -16
  19. optify-0.6.0/rust/optify/src/provider/constraints.rs +4 -0
  20. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/provider/mod.rs +1 -0
  21. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/provider/provider_impl.rs +103 -48
  22. optify-0.6.0/rust/optify/src/provider/provider_trait.rs +68 -0
  23. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/provider/watcher.rs +85 -39
  24. optify-0.6.0/rust/optify/src/schema/conditions.rs +170 -0
  25. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/schema/feature.rs +5 -0
  26. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/schema/metadata.rs +5 -0
  27. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/schema/mod.rs +1 -0
  28. optify-0.2.0/python/optify/src/lib.rs +0 -78
  29. optify-0.2.0/rust/optify/src/provider/provider_trait.rs +0 -45
  30. {optify-0.2.0/python/optify → optify-0.6.0}/LICENSE.txt +0 -0
  31. {optify-0.2.0 → optify-0.6.0}/rust/optify/README.md +0 -0
  32. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/builder/builder_trait.rs +0 -0
  33. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/builder/mod.rs +0 -0
  34. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/builder/watcher_builder.rs +0 -0
  35. {optify-0.2.0 → optify-0.6.0}/rust/optify/src/lib.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: optify
3
- Version: 0.2.0
3
+ Version: 0.6.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -10,7 +10,7 @@ License-File: LICENSE.txt
10
10
  Summary: Simplifies getting the right configuration options for a process using pre-loaded configurations from files to manage options for experiments or flights.
11
11
  Home-Page: https://github.com/juharris/optify/tree/main/rust/optify
12
12
  Author: Justin D. Harris
13
- License: MIT
13
+ License-Expression: MIT
14
14
  Requires-Python: >=3.8
15
15
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
16
16
  Project-URL: Homepage, https://github.com/juharris/optify
@@ -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
- See the [tests directory](./tests/) for examples.
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
- See the [tests directory](./tests/) for examples.
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.2.0"
29
+ version = "0.6.0"
30
30
 
31
31
  [tool.poetry]
32
32
  name = "optify"
33
- version = "0.2.0"
33
+ version = "0.6.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"]
@@ -65,8 +65,5 @@ docs/_build/
65
65
  # PyCharm
66
66
  .idea/
67
67
 
68
- # VSCode
69
- .vscode/
70
-
71
68
  # Pyenv
72
69
  .python-version
@@ -0,0 +1,3 @@
1
+ {
2
+ "python.terminal.activateEnvironment": true
3
+ }
@@ -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"
@@ -190,6 +199,12 @@ dependencies = [
190
199
  "const-random",
191
200
  ]
192
201
 
202
+ [[package]]
203
+ name = "dunce"
204
+ version = "1.0.5"
205
+ source = "registry+https://github.com/rust-lang/crates.io-index"
206
+ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
207
+
193
208
  [[package]]
194
209
  name = "either"
195
210
  version = "1.15.0"
@@ -461,12 +476,14 @@ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
461
476
 
462
477
  [[package]]
463
478
  name = "optify"
464
- version = "0.9.0"
479
+ version = "0.16.0"
465
480
  dependencies = [
466
481
  "config",
482
+ "dunce",
467
483
  "notify",
468
484
  "notify-debouncer-full",
469
485
  "rayon",
486
+ "regex",
470
487
  "serde",
471
488
  "serde_derive",
472
489
  "serde_json",
@@ -476,7 +493,7 @@ dependencies = [
476
493
 
477
494
  [[package]]
478
495
  name = "optify-python"
479
- version = "0.2.0"
496
+ version = "0.6.0"
480
497
  dependencies = [
481
498
  "optify",
482
499
  "pyo3",
@@ -659,6 +676,35 @@ dependencies = [
659
676
  "bitflags 2.8.0",
660
677
  ]
661
678
 
679
+ [[package]]
680
+ name = "regex"
681
+ version = "1.11.1"
682
+ source = "registry+https://github.com/rust-lang/crates.io-index"
683
+ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
684
+ dependencies = [
685
+ "aho-corasick",
686
+ "memchr",
687
+ "regex-automata",
688
+ "regex-syntax",
689
+ ]
690
+
691
+ [[package]]
692
+ name = "regex-automata"
693
+ version = "0.4.9"
694
+ source = "registry+https://github.com/rust-lang/crates.io-index"
695
+ checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
696
+ dependencies = [
697
+ "aho-corasick",
698
+ "memchr",
699
+ "regex-syntax",
700
+ ]
701
+
702
+ [[package]]
703
+ name = "regex-syntax"
704
+ version = "0.8.5"
705
+ source = "registry+https://github.com/rust-lang/crates.io-index"
706
+ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
707
+
662
708
  [[package]]
663
709
  name = "ron"
664
710
  version = "0.8.1"
@@ -1,12 +1,13 @@
1
1
  [package]
2
2
  name = "optify-python"
3
- version = "0.2.0"
3
+ version = "0.6.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."
7
7
  homepage = "https://github.com/juharris/optify/tree/main/rust/optify"
8
8
  license = "MIT"
9
9
  repository = "https://github.com/juharris/optify/tree/main/rust/optify"
10
+ readme = "README.md"
10
11
 
11
12
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12
13
  [lib]
@@ -14,5 +15,5 @@ name = "optify"
14
15
  crate-type = ["cdylib"]
15
16
 
16
17
  [dependencies]
17
- optify = { path = "../../rust/optify", version = "0.9.0" }
18
+ optify = { path = "../../rust/optify", version = "0.16.0" }
18
19
  pyo3 = "0.24.1"
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Justin D. Harris
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -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
- See the [tests directory](./tests/) for examples.
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
+ /// 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 = OptionsProviderBuilder() \
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.get_options_json(key, features)
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(str(test_suites_dir / 'simple/configs'))
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 BaseException as e:
20
- assert str(e) == "key and feature names should be valid: \"configuration property \\\"key\\\" not found\""
20
+ except Exception as e:
21
+ assert str(e) == "Error getting options with features [\"A\"]: 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'])
@@ -0,0 +1,24 @@
1
+ {
2
+ "hooks": {
3
+ "PostToolUse": [
4
+ {
5
+ "matcher": "Bash|Edit|MultiEdit|Update|Write",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "cargo fmt"
10
+ }
11
+ ]
12
+ },
13
+ {
14
+ "matcher": "Bash|Edit|MultiEdit|Update|Write",
15
+ "hooks": [
16
+ {
17
+ "type": "command",
18
+ "command": "cargo clippy --fix --allow-dirty --allow-staged"
19
+ }
20
+ ]
21
+ }
22
+ ]
23
+ }
24
+ }
@@ -1,7 +1,8 @@
1
1
  [package]
2
2
  name = "optify"
3
- version = "0.9.0"
3
+ version = "0.16.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"
@@ -18,9 +19,11 @@ exclude = [
18
19
 
19
20
  [dependencies]
20
21
  config = "0.15.6"
22
+ dunce = "1.0.5"
21
23
  notify = "8.0.0"
22
24
  notify-debouncer-full = "0.5.0"
23
25
  rayon = "1.10.0"
26
+ regex = "1.11.1"
24
27
  serde = "1.0.217"
25
28
  serde_derive = "1.0.217"
26
29
  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", i));
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", i));
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-{}", num_files));
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
+ }