optify 0.1.2__tar.gz → 0.2.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 (27) hide show
  1. {optify-0.1.2 → optify-0.2.0}/PKG-INFO +2 -2
  2. {optify-0.1.2 → optify-0.2.0}/README.md +1 -1
  3. {optify-0.1.2 → optify-0.2.0}/pyproject.toml +2 -2
  4. {optify-0.1.2 → optify-0.2.0}/python/optify/Cargo.lock +219 -4
  5. {optify-0.1.2 → optify-0.2.0}/python/optify/Cargo.toml +2 -2
  6. {optify-0.1.2 → optify-0.2.0}/python/optify/README.md +1 -1
  7. {optify-0.1.2 → optify-0.2.0}/python/optify/src/lib.rs +26 -7
  8. optify-0.2.0/python/optify/tests/test_provider.py +34 -0
  9. {optify-0.1.2 → optify-0.2.0}/rust/optify/Cargo.toml +10 -1
  10. {optify-0.1.2 → optify-0.2.0}/rust/optify/README.md +10 -1
  11. optify-0.2.0/rust/optify/benches/loading_benchmark.rs +106 -0
  12. optify-0.1.2/rust/optify/src/builder.rs → optify-0.2.0/rust/optify/src/builder/builder_impl.rs +121 -88
  13. optify-0.2.0/rust/optify/src/builder/builder_trait.rs +15 -0
  14. optify-0.2.0/rust/optify/src/builder/mod.rs +7 -0
  15. optify-0.2.0/rust/optify/src/builder/watcher_builder.rs +42 -0
  16. optify-0.2.0/rust/optify/src/provider/mod.rs +7 -0
  17. optify-0.1.2/rust/optify/src/provider.rs → optify-0.2.0/rust/optify/src/provider/provider_impl.rs +125 -62
  18. optify-0.2.0/rust/optify/src/provider/provider_trait.rs +45 -0
  19. optify-0.2.0/rust/optify/src/provider/watcher.rs +218 -0
  20. optify-0.1.2/python/optify/tests/test_provider.py +0 -23
  21. {optify-0.1.2 → optify-0.2.0}/python/optify/.gitignore +0 -0
  22. {optify-0.1.2 → optify-0.2.0}/python/optify/LICENSE.txt +0 -0
  23. {optify-0.1.2 → optify-0.2.0}/python/optify/tests/test_optify.py +0 -0
  24. {optify-0.1.2 → optify-0.2.0}/rust/optify/src/lib.rs +0 -0
  25. {optify-0.1.2 → optify-0.2.0}/rust/optify/src/schema/feature.rs +0 -0
  26. {optify-0.1.2 → optify-0.2.0}/rust/optify/src/schema/metadata.rs +0 -0
  27. {optify-0.1.2 → optify-0.2.0}/rust/optify/src/schema/mod.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: optify
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -22,7 +22,7 @@ Project-URL: Issues, https://github.com/juharris/optify/issues
22
22
  ](https://pypi.org/project/optify)
23
23
 
24
24
  ⚠️ Development in progress ⚠️\
25
- APIs are not final and will change, for example, interfaces with be used.
25
+ APIs are not final and may change, for example, interfaces may be used and names may change.
26
26
  This is just meant to be minimal to get started and help build a Python library.
27
27
 
28
28
  See the [homepage] for details.
@@ -4,7 +4,7 @@
4
4
  ](https://pypi.org/project/optify)
5
5
 
6
6
  ⚠️ Development in progress ⚠️\
7
- APIs are not final and will change, for example, interfaces with be used.
7
+ APIs are not final and may change, for example, interfaces may be used and names may change.
8
8
  This is just meant to be minimal to get started and help build a Python library.
9
9
 
10
10
  See the [homepage] for details.
@@ -26,11 +26,11 @@ build-backend = "maturin"
26
26
 
27
27
  [package]
28
28
  name = "optify"
29
- version = "0.1.2"
29
+ version = "0.2.0"
30
30
 
31
31
  [tool.poetry]
32
32
  name = "optify"
33
- version = "0.1.2"
33
+ version = "0.2.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"]
@@ -43,6 +43,12 @@ version = "0.21.7"
43
43
  source = "registry+https://github.com/rust-lang/crates.io-index"
44
44
  checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
45
45
 
46
+ [[package]]
47
+ name = "bitflags"
48
+ version = "1.3.2"
49
+ source = "registry+https://github.com/rust-lang/crates.io-index"
50
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
51
+
46
52
  [[package]]
47
53
  name = "bitflags"
48
54
  version = "2.8.0"
@@ -124,6 +130,31 @@ dependencies = [
124
130
  "libc",
125
131
  ]
126
132
 
133
+ [[package]]
134
+ name = "crossbeam-deque"
135
+ version = "0.8.6"
136
+ source = "registry+https://github.com/rust-lang/crates.io-index"
137
+ checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
138
+ dependencies = [
139
+ "crossbeam-epoch",
140
+ "crossbeam-utils",
141
+ ]
142
+
143
+ [[package]]
144
+ name = "crossbeam-epoch"
145
+ version = "0.9.18"
146
+ source = "registry+https://github.com/rust-lang/crates.io-index"
147
+ checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
148
+ dependencies = [
149
+ "crossbeam-utils",
150
+ ]
151
+
152
+ [[package]]
153
+ name = "crossbeam-utils"
154
+ version = "0.8.21"
155
+ source = "registry+https://github.com/rust-lang/crates.io-index"
156
+ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
157
+
127
158
  [[package]]
128
159
  name = "crunchy"
129
160
  version = "0.2.3"
@@ -159,6 +190,12 @@ dependencies = [
159
190
  "const-random",
160
191
  ]
161
192
 
193
+ [[package]]
194
+ name = "either"
195
+ version = "1.15.0"
196
+ source = "registry+https://github.com/rust-lang/crates.io-index"
197
+ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
198
+
162
199
  [[package]]
163
200
  name = "encoding_rs"
164
201
  version = "0.8.35"
@@ -174,6 +211,36 @@ version = "1.0.1"
174
211
  source = "registry+https://github.com/rust-lang/crates.io-index"
175
212
  checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
176
213
 
214
+ [[package]]
215
+ name = "file-id"
216
+ version = "0.2.2"
217
+ source = "registry+https://github.com/rust-lang/crates.io-index"
218
+ checksum = "6bc904b9bbefcadbd8e3a9fb0d464a9b979de6324c03b3c663e8994f46a5be36"
219
+ dependencies = [
220
+ "windows-sys 0.52.0",
221
+ ]
222
+
223
+ [[package]]
224
+ name = "filetime"
225
+ version = "0.2.25"
226
+ source = "registry+https://github.com/rust-lang/crates.io-index"
227
+ checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586"
228
+ dependencies = [
229
+ "cfg-if",
230
+ "libc",
231
+ "libredox",
232
+ "windows-sys 0.59.0",
233
+ ]
234
+
235
+ [[package]]
236
+ name = "fsevent-sys"
237
+ version = "4.1.0"
238
+ source = "registry+https://github.com/rust-lang/crates.io-index"
239
+ checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
240
+ dependencies = [
241
+ "libc",
242
+ ]
243
+
177
244
  [[package]]
178
245
  name = "generic-array"
179
246
  version = "0.14.7"
@@ -241,6 +308,26 @@ version = "2.0.5"
241
308
  source = "registry+https://github.com/rust-lang/crates.io-index"
242
309
  checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
243
310
 
311
+ [[package]]
312
+ name = "inotify"
313
+ version = "0.11.0"
314
+ source = "registry+https://github.com/rust-lang/crates.io-index"
315
+ checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3"
316
+ dependencies = [
317
+ "bitflags 2.8.0",
318
+ "inotify-sys",
319
+ "libc",
320
+ ]
321
+
322
+ [[package]]
323
+ name = "inotify-sys"
324
+ version = "0.1.5"
325
+ source = "registry+https://github.com/rust-lang/crates.io-index"
326
+ checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb"
327
+ dependencies = [
328
+ "libc",
329
+ ]
330
+
244
331
  [[package]]
245
332
  name = "itoa"
246
333
  version = "1.0.14"
@@ -258,12 +345,49 @@ dependencies = [
258
345
  "serde",
259
346
  ]
260
347
 
348
+ [[package]]
349
+ name = "kqueue"
350
+ version = "1.0.8"
351
+ source = "registry+https://github.com/rust-lang/crates.io-index"
352
+ checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c"
353
+ dependencies = [
354
+ "kqueue-sys",
355
+ "libc",
356
+ ]
357
+
358
+ [[package]]
359
+ name = "kqueue-sys"
360
+ version = "1.0.4"
361
+ source = "registry+https://github.com/rust-lang/crates.io-index"
362
+ checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b"
363
+ dependencies = [
364
+ "bitflags 1.3.2",
365
+ "libc",
366
+ ]
367
+
261
368
  [[package]]
262
369
  name = "libc"
263
370
  version = "0.2.169"
264
371
  source = "registry+https://github.com/rust-lang/crates.io-index"
265
372
  checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
266
373
 
374
+ [[package]]
375
+ name = "libredox"
376
+ version = "0.1.3"
377
+ source = "registry+https://github.com/rust-lang/crates.io-index"
378
+ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
379
+ dependencies = [
380
+ "bitflags 2.8.0",
381
+ "libc",
382
+ "redox_syscall",
383
+ ]
384
+
385
+ [[package]]
386
+ name = "log"
387
+ version = "0.4.27"
388
+ source = "registry+https://github.com/rust-lang/crates.io-index"
389
+ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
390
+
267
391
  [[package]]
268
392
  name = "memchr"
269
393
  version = "2.7.4"
@@ -279,6 +403,56 @@ dependencies = [
279
403
  "autocfg",
280
404
  ]
281
405
 
406
+ [[package]]
407
+ name = "mio"
408
+ version = "1.0.3"
409
+ source = "registry+https://github.com/rust-lang/crates.io-index"
410
+ checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
411
+ dependencies = [
412
+ "libc",
413
+ "log",
414
+ "wasi",
415
+ "windows-sys 0.52.0",
416
+ ]
417
+
418
+ [[package]]
419
+ name = "notify"
420
+ version = "8.0.0"
421
+ source = "registry+https://github.com/rust-lang/crates.io-index"
422
+ checksum = "2fee8403b3d66ac7b26aee6e40a897d85dc5ce26f44da36b8b73e987cc52e943"
423
+ dependencies = [
424
+ "bitflags 2.8.0",
425
+ "filetime",
426
+ "fsevent-sys",
427
+ "inotify",
428
+ "kqueue",
429
+ "libc",
430
+ "log",
431
+ "mio",
432
+ "notify-types",
433
+ "walkdir",
434
+ "windows-sys 0.59.0",
435
+ ]
436
+
437
+ [[package]]
438
+ name = "notify-debouncer-full"
439
+ version = "0.5.0"
440
+ source = "registry+https://github.com/rust-lang/crates.io-index"
441
+ checksum = "d2d88b1a7538054351c8258338df7c931a590513fb3745e8c15eb9ff4199b8d1"
442
+ dependencies = [
443
+ "file-id",
444
+ "log",
445
+ "notify",
446
+ "notify-types",
447
+ "walkdir",
448
+ ]
449
+
450
+ [[package]]
451
+ name = "notify-types"
452
+ version = "2.0.0"
453
+ source = "registry+https://github.com/rust-lang/crates.io-index"
454
+ checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d"
455
+
282
456
  [[package]]
283
457
  name = "once_cell"
284
458
  version = "1.20.3"
@@ -287,9 +461,12 @@ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
287
461
 
288
462
  [[package]]
289
463
  name = "optify"
290
- version = "0.6.1"
464
+ version = "0.9.0"
291
465
  dependencies = [
292
466
  "config",
467
+ "notify",
468
+ "notify-debouncer-full",
469
+ "rayon",
293
470
  "serde",
294
471
  "serde_derive",
295
472
  "serde_json",
@@ -299,7 +476,7 @@ dependencies = [
299
476
 
300
477
  [[package]]
301
478
  name = "optify-python"
302
- version = "0.1.2"
479
+ version = "0.2.0"
303
480
  dependencies = [
304
481
  "optify",
305
482
  "pyo3",
@@ -453,6 +630,35 @@ dependencies = [
453
630
  "proc-macro2",
454
631
  ]
455
632
 
633
+ [[package]]
634
+ name = "rayon"
635
+ version = "1.10.0"
636
+ source = "registry+https://github.com/rust-lang/crates.io-index"
637
+ checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
638
+ dependencies = [
639
+ "either",
640
+ "rayon-core",
641
+ ]
642
+
643
+ [[package]]
644
+ name = "rayon-core"
645
+ version = "1.12.1"
646
+ source = "registry+https://github.com/rust-lang/crates.io-index"
647
+ checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
648
+ dependencies = [
649
+ "crossbeam-deque",
650
+ "crossbeam-utils",
651
+ ]
652
+
653
+ [[package]]
654
+ name = "redox_syscall"
655
+ version = "0.5.11"
656
+ source = "registry+https://github.com/rust-lang/crates.io-index"
657
+ checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3"
658
+ dependencies = [
659
+ "bitflags 2.8.0",
660
+ ]
661
+
456
662
  [[package]]
457
663
  name = "ron"
458
664
  version = "0.8.1"
@@ -460,7 +666,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
460
666
  checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
461
667
  dependencies = [
462
668
  "base64",
463
- "bitflags",
669
+ "bitflags 2.8.0",
464
670
  "serde",
465
671
  "serde_derive",
466
672
  ]
@@ -693,7 +899,16 @@ version = "0.1.9"
693
899
  source = "registry+https://github.com/rust-lang/crates.io-index"
694
900
  checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
695
901
  dependencies = [
696
- "windows-sys",
902
+ "windows-sys 0.59.0",
903
+ ]
904
+
905
+ [[package]]
906
+ name = "windows-sys"
907
+ version = "0.52.0"
908
+ source = "registry+https://github.com/rust-lang/crates.io-index"
909
+ checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
910
+ dependencies = [
911
+ "windows-targets",
697
912
  ]
698
913
 
699
914
  [[package]]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "optify-python"
3
- version = "0.1.2"
3
+ version = "0.2.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.6.1" }
17
+ optify = { path = "../../rust/optify", version = "0.9.0" }
18
18
  pyo3 = "0.24.1"
@@ -4,7 +4,7 @@
4
4
  ](https://pypi.org/project/optify)
5
5
 
6
6
  ⚠️ Development in progress ⚠️\
7
- APIs are not final and will change, for example, interfaces with be used.
7
+ APIs are not final and may change, for example, interfaces may be used and names may change.
8
8
  This is just meant to be minimal to get started and help build a Python library.
9
9
 
10
10
  See the [homepage] for details.
@@ -1,7 +1,8 @@
1
1
  use pyo3::prelude::*;
2
2
 
3
- use optify::builder::OptionsProviderBuilder;
4
- use optify::provider::OptionsProvider;
3
+ use optify::builder::{OptionsProviderBuilder, OptionsRegistryBuilder};
4
+ use optify::convert_to_str_slice;
5
+ use optify::provider::{OptionsProvider, OptionsRegistry};
5
6
 
6
7
  #[pyclass(name = "OptionsProviderBuilder")]
7
8
  // TODO Try to use inheritance, maybe?
@@ -13,13 +14,31 @@ struct PyOptionsProvider(OptionsProvider);
13
14
  #[pymethods]
14
15
  impl PyOptionsProvider {
15
16
  fn features(&self) -> Vec<String> {
16
- self.0.get_features()
17
+ self.0
18
+ .get_features()
19
+ .into_iter()
20
+ .map(|s| s.to_string())
21
+ .collect()
22
+ }
23
+
24
+ fn get_canonical_feature_name(&self, feature_name: &str) -> String {
25
+ self.0
26
+ .get_canonical_feature_name(feature_name)
27
+ .expect("feature name should be valid")
28
+ }
29
+
30
+ fn get_canonical_feature_names(&self, feature_names: Vec<String>) -> Vec<String> {
31
+ let _feature_names = convert_to_str_slice!(feature_names);
32
+ self.0
33
+ .get_canonical_feature_names(&_feature_names)
34
+ .expect("feature names should be valid")
17
35
  }
18
36
 
19
37
  fn get_options_json(&self, key: &str, feature_names: Vec<String>) -> String {
38
+ let _feature_names = convert_to_str_slice!(feature_names);
20
39
  self.0
21
- .get_options(key, &feature_names)
22
- .expect("Failed to get options")
40
+ .get_options(key, &_feature_names)
41
+ .expect("key and feature names should be valid")
23
42
  .to_string()
24
43
  }
25
44
  }
@@ -35,7 +54,7 @@ impl PyOptionsProviderBuilder {
35
54
  let path = std::path::Path::new(&directory);
36
55
  self.0
37
56
  .add_directory(path)
38
- .expect("Failed to add the directory");
57
+ .expect("directory contents should be valid");
39
58
  // TODO Try to avoid cloning
40
59
  Self(self.0.clone())
41
60
  }
@@ -44,7 +63,7 @@ impl PyOptionsProviderBuilder {
44
63
  PyOptionsProvider(
45
64
  self.0
46
65
  .build()
47
- .expect("Failed to build the options provider"),
66
+ .expect("OptionsProvider should be built successfully"),
48
67
  )
49
68
  }
50
69
  }
@@ -0,0 +1,34 @@
1
+ from pathlib import Path
2
+
3
+ from optify import OptionsProviderBuilder
4
+
5
+
6
+ test_suites_dir = (Path(__file__) / '../../../../tests/test_suites').resolve()
7
+ builder = OptionsProviderBuilder()
8
+ builder.add_directory(str(test_suites_dir / 'simple/configs'))
9
+ PROVIDER = builder.build()
10
+
11
+ def test_features():
12
+ features = PROVIDER.features()
13
+ features.sort()
14
+ assert features == ['A_with_comments', 'feature_A', 'feature_B/initial']
15
+
16
+ try:
17
+ PROVIDER.get_options_json('key', ['A'])
18
+ 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\""
21
+
22
+
23
+ def test_canonical_feature_name():
24
+ assert PROVIDER.get_canonical_feature_name('feaTure_A') == 'feature_A'
25
+ assert PROVIDER.get_canonical_feature_name('feature_B/initial') == 'feature_B/initial'
26
+ assert PROVIDER.get_canonical_feature_name('A_with_comments') == 'A_with_comments'
27
+
28
+
29
+ def test_canonical_feature_names():
30
+ assert PROVIDER.get_canonical_feature_names(['feature_A']) == ['feature_A']
31
+ assert PROVIDER.get_canonical_feature_names(['feature_B/initial']) == ['feature_B/initial']
32
+ assert PROVIDER.get_canonical_feature_names(['A_with_COmments']) == ['A_with_comments']
33
+
34
+ assert PROVIDER.get_canonical_feature_names(['A', 'B']) == ['feature_A', 'feature_B/initial']
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "optify"
3
- version = "0.6.1"
3
+ version = "0.9.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."
@@ -18,6 +18,9 @@ exclude = [
18
18
 
19
19
  [dependencies]
20
20
  config = "0.15.6"
21
+ notify = "8.0.0"
22
+ notify-debouncer-full = "0.5.0"
23
+ rayon = "1.10.0"
21
24
  serde = "1.0.217"
22
25
  serde_derive = "1.0.217"
23
26
  serde_json = "1.0.140"
@@ -26,3 +29,9 @@ walkdir = "2.5.0"
26
29
 
27
30
  [dev-dependencies]
28
31
  regex = "1.11.1"
32
+ criterion = "0.5.1"
33
+ tempfile = "3"
34
+
35
+ [[bench]]
36
+ name = "loading_benchmark"
37
+ harness = false
@@ -11,9 +11,15 @@ See [tests](../../tests/) for examples and tests for different implementations o
11
11
  See the root [README.md](../../README.md) for more information and examples.
12
12
 
13
13
  ⚠️ Development in progress ⚠️\
14
- APIs are not final and will change, for example, interfaces with be used.
14
+ APIs are not final and may change, for example, names may change.
15
15
  This is just meant to be minimal to get started and help build Python and Ruby libraries.
16
16
 
17
+ ## How It Works
18
+
19
+ The [`config`][config] crate (library) is used to help combine configuration files.
20
+
21
+ Optionally, when working locally, there is support to watch for changes to the configuration files and folders using the [`notify-debouncer-full`][notify-debouncer-full] crate (library).
22
+
17
23
  ## Testing
18
24
 
19
25
  Run:
@@ -32,3 +38,6 @@ cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
32
38
  cargo login
33
39
  cargo publish
34
40
  ```
41
+
42
+ [config]: https://crates.io/crates/config
43
+ [notify-debouncer-full]: https://crates.io/crates/notify-debouncer-full
@@ -0,0 +1,106 @@
1
+ use criterion::{black_box, criterion_group, criterion_main, Criterion};
2
+ use optify::builder::OptionsProviderBuilder;
3
+ use optify::builder::OptionsRegistryBuilder;
4
+ use std::fs;
5
+ use std::io::Write;
6
+ use std::path::Path;
7
+
8
+ struct TestDirGuard {
9
+ dir: &'static Path,
10
+ }
11
+
12
+ impl TestDirGuard {
13
+ fn new(dir: &'static Path) -> Self {
14
+ Self { dir }
15
+ }
16
+ }
17
+
18
+ impl Drop for TestDirGuard {
19
+ fn drop(&mut self) {
20
+ cleanup_test_files(self.dir);
21
+ }
22
+ }
23
+
24
+ fn create_test_files(dir: &Path, num_files: usize) {
25
+ cleanup_test_files(dir);
26
+ fs::create_dir_all(dir).unwrap();
27
+
28
+ for i in 0..num_files / 2 {
29
+ let file_path = dir.join(format!("test_{}.json", i));
30
+ let mut file = fs::File::create(&file_path).unwrap();
31
+
32
+ // Create a test configuration file with some realistic content
33
+ let content = format!(
34
+ r#"{{
35
+ "metadata": {{
36
+ "aliases": ["alias_{}_1", "alias_{}_2"]
37
+ }},
38
+ "options": {{
39
+ "setting1": "value1",
40
+ "setting2": 42,
41
+ "setting3": true,
42
+ "nested": {{
43
+ "field1": "nested_value",
44
+ "field2": [1, 2, 3]
45
+ }}
46
+ }}
47
+ }}"#,
48
+ i, i,
49
+ );
50
+
51
+ file.write_all(content.as_bytes()).unwrap();
52
+ }
53
+
54
+ for i in num_files / 2..num_files {
55
+ let file_path = dir.join(format!("test_{}.yaml", i));
56
+ let mut file = fs::File::create(&file_path).unwrap();
57
+
58
+ let content = format!(
59
+ r#"metadata:
60
+ aliases:
61
+ - alias_y_{}_1
62
+ - alias_y_{}_2
63
+ options:
64
+ setting1: value1
65
+ setting2: 42
66
+ setting3: true
67
+ nested:
68
+ field1: nested_value
69
+ field2: [1, 2, 3]
70
+ "#,
71
+ i, i,
72
+ );
73
+ file.write_all(content.as_bytes()).unwrap();
74
+ }
75
+ }
76
+
77
+ fn cleanup_test_files(dir: &Path) {
78
+ fs::remove_dir_all(dir).unwrap_or_default();
79
+ }
80
+
81
+ fn benchmark_loading(c: &mut Criterion) {
82
+ let test_dir = Path::new("bench_test_files");
83
+ let num_files = 100;
84
+ let _guard = TestDirGuard::new(test_dir);
85
+ let test_build = false;
86
+
87
+ create_test_files(test_dir, num_files);
88
+
89
+ let mut group = c.benchmark_group(format!("file_loading-{}", num_files));
90
+
91
+ group.bench_function("parallel loading", |b| {
92
+ b.iter(|| {
93
+ let mut builder = OptionsProviderBuilder::new();
94
+ builder.add_directory(black_box(test_dir)).unwrap();
95
+ if test_build {
96
+ // Ensure that there are no errors in the builder.
97
+ builder.build().unwrap();
98
+ }
99
+ })
100
+ });
101
+
102
+ group.finish();
103
+ }
104
+
105
+ criterion_group!(benches, benchmark_loading);
106
+ criterion_main!(benches);