optify 0.1.3__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.3 → optify-0.2.0}/PKG-INFO +2 -2
  2. {optify-0.1.3 → optify-0.2.0}/README.md +1 -1
  3. {optify-0.1.3 → optify-0.2.0}/pyproject.toml +2 -2
  4. {optify-0.1.3 → optify-0.2.0}/python/optify/Cargo.lock +167 -4
  5. {optify-0.1.3 → optify-0.2.0}/python/optify/Cargo.toml +2 -2
  6. {optify-0.1.3 → optify-0.2.0}/python/optify/README.md +1 -1
  7. {optify-0.1.3 → optify-0.2.0}/python/optify/src/lib.rs +23 -4
  8. optify-0.2.0/python/optify/tests/test_provider.py +34 -0
  9. {optify-0.1.3 → optify-0.2.0}/rust/optify/Cargo.toml +4 -1
  10. {optify-0.1.3 → optify-0.2.0}/rust/optify/README.md +10 -1
  11. {optify-0.1.3 → optify-0.2.0}/rust/optify/benches/loading_benchmark.rs +1 -0
  12. optify-0.1.3/rust/optify/src/builder.rs → optify-0.2.0/rust/optify/src/builder/builder_impl.rs +54 -49
  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.3/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.3/python/optify/tests/test_provider.py +0 -19
  21. {optify-0.1.3 → optify-0.2.0}/python/optify/.gitignore +0 -0
  22. {optify-0.1.3 → optify-0.2.0}/python/optify/LICENSE.txt +0 -0
  23. {optify-0.1.3 → optify-0.2.0}/python/optify/tests/test_optify.py +0 -0
  24. {optify-0.1.3 → optify-0.2.0}/rust/optify/src/lib.rs +0 -0
  25. {optify-0.1.3 → optify-0.2.0}/rust/optify/src/schema/feature.rs +0 -0
  26. {optify-0.1.3 → optify-0.2.0}/rust/optify/src/schema/metadata.rs +0 -0
  27. {optify-0.1.3 → 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.3
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.3"
29
+ version = "0.2.0"
30
30
 
31
31
  [tool.poetry]
32
32
  name = "optify"
33
- version = "0.1.3"
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"
@@ -205,6 +211,36 @@ version = "1.0.1"
205
211
  source = "registry+https://github.com/rust-lang/crates.io-index"
206
212
  checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
207
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
+
208
244
  [[package]]
209
245
  name = "generic-array"
210
246
  version = "0.14.7"
@@ -272,6 +308,26 @@ version = "2.0.5"
272
308
  source = "registry+https://github.com/rust-lang/crates.io-index"
273
309
  checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
274
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
+
275
331
  [[package]]
276
332
  name = "itoa"
277
333
  version = "1.0.14"
@@ -289,12 +345,49 @@ dependencies = [
289
345
  "serde",
290
346
  ]
291
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
+
292
368
  [[package]]
293
369
  name = "libc"
294
370
  version = "0.2.169"
295
371
  source = "registry+https://github.com/rust-lang/crates.io-index"
296
372
  checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
297
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
+
298
391
  [[package]]
299
392
  name = "memchr"
300
393
  version = "2.7.4"
@@ -310,6 +403,56 @@ dependencies = [
310
403
  "autocfg",
311
404
  ]
312
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
+
313
456
  [[package]]
314
457
  name = "once_cell"
315
458
  version = "1.20.3"
@@ -318,9 +461,11 @@ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
318
461
 
319
462
  [[package]]
320
463
  name = "optify"
321
- version = "0.6.2"
464
+ version = "0.9.0"
322
465
  dependencies = [
323
466
  "config",
467
+ "notify",
468
+ "notify-debouncer-full",
324
469
  "rayon",
325
470
  "serde",
326
471
  "serde_derive",
@@ -331,7 +476,7 @@ dependencies = [
331
476
 
332
477
  [[package]]
333
478
  name = "optify-python"
334
- version = "0.1.3"
479
+ version = "0.2.0"
335
480
  dependencies = [
336
481
  "optify",
337
482
  "pyo3",
@@ -505,6 +650,15 @@ dependencies = [
505
650
  "crossbeam-utils",
506
651
  ]
507
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
+
508
662
  [[package]]
509
663
  name = "ron"
510
664
  version = "0.8.1"
@@ -512,7 +666,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
512
666
  checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
513
667
  dependencies = [
514
668
  "base64",
515
- "bitflags",
669
+ "bitflags 2.8.0",
516
670
  "serde",
517
671
  "serde_derive",
518
672
  ]
@@ -745,7 +899,16 @@ version = "0.1.9"
745
899
  source = "registry+https://github.com/rust-lang/crates.io-index"
746
900
  checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
747
901
  dependencies = [
748
- "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",
749
912
  ]
750
913
 
751
914
  [[package]]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "optify-python"
3
- version = "0.1.3"
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.2" }
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,12 +14,30 @@ 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)
40
+ .get_options(key, &_feature_names)
22
41
  .expect("key and feature names should be valid")
23
42
  .to_string()
24
43
  }
@@ -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.2"
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,8 @@ exclude = [
18
18
 
19
19
  [dependencies]
20
20
  config = "0.15.6"
21
+ notify = "8.0.0"
22
+ notify-debouncer-full = "0.5.0"
21
23
  rayon = "1.10.0"
22
24
  serde = "1.0.217"
23
25
  serde_derive = "1.0.217"
@@ -28,6 +30,7 @@ walkdir = "2.5.0"
28
30
  [dev-dependencies]
29
31
  regex = "1.11.1"
30
32
  criterion = "0.5.1"
33
+ tempfile = "3"
31
34
 
32
35
  [[bench]]
33
36
  name = "loading_benchmark"
@@ -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
@@ -1,5 +1,6 @@
1
1
  use criterion::{black_box, criterion_group, criterion_main, Criterion};
2
2
  use optify::builder::OptionsProviderBuilder;
3
+ use optify::builder::OptionsRegistryBuilder;
3
4
  use std::fs;
4
5
  use std::io::Write;
5
6
  use std::path::Path;
@@ -3,14 +3,17 @@ use rayon::prelude::*;
3
3
  use std::collections::{HashMap, HashSet};
4
4
  use std::path::Path;
5
5
 
6
+ use crate::builder::OptionsRegistryBuilder;
6
7
  use crate::provider::{Aliases, Features, OptionsProvider, Sources};
7
8
  use crate::schema::feature::FeatureConfiguration;
8
9
  use crate::schema::metadata::OptionsMetadata;
9
10
 
10
11
  type Imports = HashMap<String, Vec<String>>;
11
12
 
13
+ /// A builder to use in production to create an `OptionsProvider`.
14
+ ///
12
15
  /// ⚠️ Development in progress ⚠️\
13
- /// Not truly considered public and mainly available to support bindings for other languages.
16
+ /// Not truly considered public yet and mainly available to support bindings for other languages.
14
17
  #[derive(Clone)]
15
18
  pub struct OptionsProviderBuilder {
16
19
  aliases: Aliases,
@@ -159,54 +162,6 @@ impl OptionsProviderBuilder {
159
162
  }
160
163
  }
161
164
 
162
- pub fn add_directory(&mut self, directory: &Path) -> Result<&Self, String> {
163
- let loading_results: Vec<Result<LoadingResult, String>> = walkdir::WalkDir::new(directory)
164
- .into_iter()
165
- .par_bridge()
166
- .filter_map(|entry| {
167
- Self::process_entry(
168
- entry
169
- .unwrap_or_else(|_| {
170
- panic!("Error walking directory: {}", directory.display())
171
- })
172
- .path(),
173
- directory,
174
- )
175
- })
176
- .collect();
177
- for loading_result in loading_results {
178
- self.process_loading_result(&loading_result)?;
179
- }
180
-
181
- Ok(self)
182
- }
183
-
184
- pub fn build(&mut self) -> Result<OptionsProvider, String> {
185
- let mut resolved_imports: HashSet<String> = HashSet::new();
186
- for (canonical_feature_name, imports_for_feature) in &self.imports {
187
- if resolved_imports.insert(canonical_feature_name.clone()) {
188
- // Check for infinite loops by starting a path here.
189
- let mut features_in_resolution_path: HashSet<String> =
190
- HashSet::from([canonical_feature_name.clone()]);
191
- resolve_imports(
192
- canonical_feature_name,
193
- imports_for_feature,
194
- &mut resolved_imports,
195
- &mut features_in_resolution_path,
196
- &self.aliases,
197
- &self.imports,
198
- &mut self.sources,
199
- )?;
200
- }
201
- }
202
-
203
- Ok(OptionsProvider::new(
204
- &self.aliases,
205
- &self.features,
206
- &self.sources,
207
- ))
208
- }
209
-
210
165
  fn process_entry(path: &Path, directory: &Path) -> Option<Result<LoadingResult, String>> {
211
166
  // Skip .md files because they are not handled by the `config` library and we may have README.md files in the directory.
212
167
  if !path.is_file() || path.extension().filter(|e| *e == "md").is_some() {
@@ -304,3 +259,53 @@ impl OptionsProviderBuilder {
304
259
  Ok(())
305
260
  }
306
261
  }
262
+
263
+ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
264
+ fn add_directory(&mut self, directory: &Path) -> Result<&Self, String> {
265
+ let loading_results: Vec<Result<LoadingResult, String>> = walkdir::WalkDir::new(directory)
266
+ .into_iter()
267
+ .par_bridge()
268
+ .filter_map(|entry| {
269
+ Self::process_entry(
270
+ entry
271
+ .unwrap_or_else(|_| {
272
+ panic!("Error walking directory: {}", directory.display())
273
+ })
274
+ .path(),
275
+ directory,
276
+ )
277
+ })
278
+ .collect();
279
+ for loading_result in loading_results {
280
+ self.process_loading_result(&loading_result)?;
281
+ }
282
+
283
+ Ok(self)
284
+ }
285
+
286
+ fn build(&mut self) -> Result<OptionsProvider, String> {
287
+ let mut resolved_imports: HashSet<String> = HashSet::new();
288
+ for (canonical_feature_name, imports_for_feature) in &self.imports {
289
+ if resolved_imports.insert(canonical_feature_name.clone()) {
290
+ // Check for infinite loops by starting a path here.
291
+ let mut features_in_resolution_path: HashSet<String> =
292
+ HashSet::from([canonical_feature_name.clone()]);
293
+ resolve_imports(
294
+ canonical_feature_name,
295
+ imports_for_feature,
296
+ &mut resolved_imports,
297
+ &mut features_in_resolution_path,
298
+ &self.aliases,
299
+ &self.imports,
300
+ &mut self.sources,
301
+ )?;
302
+ }
303
+ }
304
+
305
+ Ok(OptionsProvider::new(
306
+ &self.aliases,
307
+ &self.features,
308
+ &self.sources,
309
+ ))
310
+ }
311
+ }
@@ -0,0 +1,15 @@
1
+ use std::path::Path;
2
+
3
+ use crate::provider::OptionsRegistry;
4
+
5
+ /// Trait defining the core functionality for building an options provider.
6
+ ///
7
+ /// ⚠️ Development in progress ⚠️\
8
+ /// Not truly considered public yet and mainly available to support bindings for other languages.
9
+ pub trait OptionsRegistryBuilder<T: OptionsRegistry> {
10
+ /// Adds a directory containing feature configurations.
11
+ fn add_directory(&mut self, directory: &Path) -> Result<&Self, String>;
12
+
13
+ /// Builds the options provider.
14
+ fn build(&mut self) -> Result<T, String>;
15
+ }
@@ -0,0 +1,7 @@
1
+ pub(crate) mod builder_impl;
2
+ pub(crate) mod builder_trait;
3
+ pub(crate) mod watcher_builder;
4
+
5
+ pub use builder_impl::*;
6
+ pub use builder_trait::*;
7
+ pub use watcher_builder::*;
@@ -0,0 +1,42 @@
1
+ use std::path::{Path, PathBuf};
2
+
3
+ use crate::provider::OptionsWatcher;
4
+
5
+ use super::OptionsRegistryBuilder;
6
+
7
+ /// A builder to use for local development to create an `OptionsWatcher` which changes the underlying `OptionsProvider` when files are changed.
8
+ ///
9
+ /// This builder is kept separate from the `OptionsProviderBuilder` in order to keep `OptionsProviderBuilder` and `OptionsProvider` as simple and efficient as possible for production use.
10
+ ///
11
+ /// ⚠️ Development in progress ⚠️\
12
+ /// Not truly considered public yet and mainly available to support bindings for other languages.
13
+ #[derive(Clone)]
14
+ pub struct OptionsWatcherBuilder {
15
+ watched_directories: Vec<PathBuf>,
16
+ }
17
+
18
+ impl Default for OptionsWatcherBuilder {
19
+ fn default() -> Self {
20
+ Self::new()
21
+ }
22
+ }
23
+
24
+ impl OptionsWatcherBuilder {
25
+ pub fn new() -> Self {
26
+ OptionsWatcherBuilder {
27
+ watched_directories: Vec::new(),
28
+ }
29
+ }
30
+ }
31
+
32
+ impl OptionsRegistryBuilder<OptionsWatcher> for OptionsWatcherBuilder {
33
+ /// Add a directory to watch for changes.
34
+ fn add_directory(&mut self, directory: &Path) -> Result<&Self, String> {
35
+ self.watched_directories.push(directory.to_path_buf());
36
+ Ok(self)
37
+ }
38
+
39
+ fn build(&mut self) -> Result<OptionsWatcher, String> {
40
+ Ok(OptionsWatcher::new(self.watched_directories.clone()))
41
+ }
42
+ }
@@ -0,0 +1,7 @@
1
+ pub(crate) mod provider_impl;
2
+ pub(crate) mod provider_trait;
3
+ pub(crate) mod watcher;
4
+
5
+ pub use provider_impl::*;
6
+ pub use provider_trait::*;
7
+ pub use watcher::*;
@@ -1,8 +1,9 @@
1
- use config::{self};
2
1
  use std::collections::HashMap;
3
2
 
4
3
  use crate::schema::metadata::OptionsMetadata;
5
4
 
5
+ use super::OptionsRegistry;
6
+
6
7
  // Replicating https://github.com/juharris/dotnet-OptionsProvider/blob/main/src/OptionsProvider/OptionsProvider/IOptionsProvider.cs
7
8
  // and https://github.com/juharris/dotnet-OptionsProvider/blob/main/src/OptionsProvider/OptionsProvider/OptionsProviderWithDefaults.cs
8
9
 
@@ -14,11 +15,55 @@ pub(crate) type Features = HashMap<String, OptionsMetadata>;
14
15
  pub(crate) type Sources = HashMap<String, SourceValue>;
15
16
 
16
17
  pub struct GetOptionsPreferences {
18
+ /// Overrides to apply after the built configuration.
19
+ /// A string is used because it makes it easier to pass to the `config` library, but this may change in the future.
20
+ /// It also makes it simpler and maybe faster to get from other programming languages.
21
+ pub overrides_json: Option<String>,
17
22
  pub skip_feature_name_conversion: bool,
18
23
  }
19
24
 
25
+ impl Clone for GetOptionsPreferences {
26
+ fn clone(&self) -> Self {
27
+ Self {
28
+ overrides_json: self.overrides_json.clone(),
29
+ skip_feature_name_conversion: self.skip_feature_name_conversion,
30
+ }
31
+ }
32
+ }
33
+
34
+ impl Default for GetOptionsPreferences {
35
+ fn default() -> Self {
36
+ Self::new()
37
+ }
38
+ }
39
+
40
+ impl GetOptionsPreferences {
41
+ pub fn new() -> Self {
42
+ Self {
43
+ overrides_json: None,
44
+ skip_feature_name_conversion: false,
45
+ }
46
+ }
47
+
48
+ pub fn set_overrides_json(&mut self, overrides: Option<String>) {
49
+ self.overrides_json = overrides;
50
+ }
51
+
52
+ pub fn set_skip_feature_name_conversion(&mut self, skip_feature_name_conversion: bool) {
53
+ self.skip_feature_name_conversion = skip_feature_name_conversion;
54
+ }
55
+ }
56
+
20
57
  pub struct CacheOptions {}
21
58
 
59
+ #[doc(hidden)]
60
+ #[macro_export]
61
+ macro_rules! convert_to_str_slice {
62
+ ($vec:expr) => {
63
+ $vec.iter().map(|s| s.as_str()).collect::<Vec<&str>>()
64
+ };
65
+ }
66
+
22
67
  /// ⚠️ Development in progress ⚠️\
23
68
  /// Not truly considered public and mainly available to support bindings for other languages.
24
69
  pub struct OptionsProvider {
@@ -36,11 +81,65 @@ impl OptionsProvider {
36
81
  }
37
82
  }
38
83
 
39
- pub fn get_all_options(
84
+ fn _get_entire_config(
40
85
  &self,
41
- feature_names: &Vec<String>,
42
- cache_options: &Option<CacheOptions>,
43
- preferences: &Option<GetOptionsPreferences>,
86
+ feature_names: &[&str],
87
+ cache_options: Option<&CacheOptions>,
88
+ preferences: Option<&GetOptionsPreferences>,
89
+ ) -> Result<Result<config::Config, config::ConfigError>, String> {
90
+ if let Some(_cache_options) = cache_options {
91
+ if let Some(preferences) = preferences {
92
+ if preferences.overrides_json.is_some() {
93
+ return Err("Caching is not supported yet and caching when overrides are given will not be supported.".to_owned());
94
+ }
95
+ }
96
+ return Err("Caching is not supported yet.".to_owned());
97
+ };
98
+ let mut config_builder = config::Config::builder();
99
+ let mut skip_feature_name_conversion = false;
100
+ if let Some(_preferences) = preferences {
101
+ skip_feature_name_conversion = _preferences.skip_feature_name_conversion;
102
+ }
103
+ for feature_name in feature_names {
104
+ // Check for an alias.
105
+ // Canonical feature names are also included as keys in the aliases map.
106
+ let canonical_feature_name = if skip_feature_name_conversion {
107
+ &feature_name.to_string()
108
+ } else {
109
+ &self.get_canonical_feature_name(feature_name)?
110
+ };
111
+
112
+ let source = match self.sources.get(canonical_feature_name) {
113
+ Some(src) => src,
114
+ // Should not happen.
115
+ // All canonical feature names are included as keys in the sources map.
116
+ // It could happen in the future if we allow aliases to be added directly, but we should try to validate them when the provider is built.
117
+ None => {
118
+ return Err(format!(
119
+ "Feature name {:?} was not found.",
120
+ canonical_feature_name
121
+ ))
122
+ }
123
+ };
124
+ config_builder = config_builder.add_source(source.clone());
125
+ }
126
+ if let Some(preferences) = preferences {
127
+ if let Some(overrides) = &preferences.overrides_json {
128
+ config_builder = config_builder
129
+ .add_source(config::File::from_str(overrides, config::FileFormat::Json));
130
+ }
131
+ }
132
+
133
+ Ok(config_builder.build())
134
+ }
135
+ }
136
+
137
+ impl OptionsRegistry for OptionsProvider {
138
+ fn get_all_options(
139
+ &self,
140
+ feature_names: &[&str],
141
+ cache_options: Option<&CacheOptions>,
142
+ preferences: Option<&GetOptionsPreferences>,
44
143
  ) -> Result<serde_json::Value, String> {
45
144
  let config = self._get_entire_config(feature_names, cache_options, preferences)?;
46
145
 
@@ -58,11 +157,11 @@ impl OptionsProvider {
58
157
  //
59
158
  // @param feature_name The name of an alias or a feature.
60
159
  // @return The canonical feature name.
61
- pub fn get_canonical_feature_name(&self, feature_name: &str) -> Result<&String, String> {
160
+ fn get_canonical_feature_name(&self, feature_name: &str) -> Result<String, String> {
62
161
  // Canonical feature names are also included as keys in the aliases map.
63
162
  let feature_name = unicase::UniCase::new(feature_name.to_owned());
64
163
  match self.aliases.get(&feature_name) {
65
- Some(canonical_name) => Ok(canonical_name),
164
+ Some(canonical_name) => Ok(canonical_name.to_owned()),
66
165
  None => Err(format!(
67
166
  "The given feature {:?} was not found.",
68
167
  feature_name
@@ -70,32 +169,35 @@ impl OptionsProvider {
70
169
  }
71
170
  }
72
171
 
73
- pub fn get_feature_metadata(&self, canonical_feature_name: &str) -> Option<&OptionsMetadata> {
74
- self.features.get(canonical_feature_name)
172
+ fn get_canonical_feature_names(&self, feature_names: &[&str]) -> Result<Vec<String>, String> {
173
+ feature_names
174
+ .iter()
175
+ .map(|name| self.get_canonical_feature_name(name))
176
+ .collect()
75
177
  }
76
178
 
77
- pub fn get_features(&self) -> Vec<String> {
78
- self.sources.keys().map(|s| s.to_owned()).collect()
179
+ fn get_feature_metadata(&self, canonical_feature_name: &str) -> Option<OptionsMetadata> {
180
+ self.features.get(canonical_feature_name).cloned()
79
181
  }
80
182
 
81
- pub fn get_features_with_metadata(&self) -> &Features {
82
- &self.features
183
+ fn get_features(&self) -> Vec<String> {
184
+ self.sources.keys().cloned().collect()
83
185
  }
84
186
 
85
- pub fn get_options(
86
- &self,
87
- key: &str,
88
- feature_names: &Vec<String>,
89
- ) -> Result<serde_json::Value, String> {
90
- self.get_options_with_preferences(key, feature_names, &None, &None)
187
+ fn get_features_with_metadata(&self) -> Features {
188
+ self.features.clone()
91
189
  }
92
190
 
93
- pub fn get_options_with_preferences(
191
+ fn get_options(&self, key: &str, feature_names: &[&str]) -> Result<serde_json::Value, String> {
192
+ self.get_options_with_preferences(key, feature_names, None, None)
193
+ }
194
+
195
+ fn get_options_with_preferences(
94
196
  &self,
95
197
  key: &str,
96
- feature_names: &Vec<String>,
97
- cache_options: &Option<CacheOptions>,
98
- preferences: &Option<GetOptionsPreferences>,
198
+ feature_names: &[&str],
199
+ cache_options: Option<&CacheOptions>,
200
+ preferences: Option<&GetOptionsPreferences>,
99
201
  ) -> Result<serde_json::Value, String> {
100
202
  let config = self._get_entire_config(feature_names, cache_options, preferences)?;
101
203
 
@@ -107,43 +209,4 @@ impl OptionsProvider {
107
209
  Err(e) => Err(e.to_string()),
108
210
  }
109
211
  }
110
-
111
- fn _get_entire_config(
112
- &self,
113
- feature_names: &Vec<String>,
114
- cache_options: &Option<CacheOptions>,
115
- preferences: &Option<GetOptionsPreferences>,
116
- ) -> Result<Result<config::Config, config::ConfigError>, String> {
117
- if let Some(_cache_options) = cache_options {
118
- return Err("Caching is not supported yet.".to_owned());
119
- };
120
- let mut config_builder = config::Config::builder();
121
- let mut skip_feature_name_conversion = false;
122
- if let Some(_preferences) = preferences {
123
- skip_feature_name_conversion = _preferences.skip_feature_name_conversion;
124
- }
125
- for feature_name in feature_names {
126
- // Check for an alias.
127
- // Canonical feature names are also included as keys in the aliases map.
128
- let mut canonical_feature_name = feature_name;
129
- if !skip_feature_name_conversion {
130
- canonical_feature_name = self.get_canonical_feature_name(feature_name)?;
131
- }
132
-
133
- let source = match self.sources.get(canonical_feature_name) {
134
- Some(src) => src,
135
- // Should not happen.
136
- // All canonical feature names are included as keys in the sources map.
137
- // It could happen in the future if we allow aliases to be added directly, but we should try to validate them when the provider is built.
138
- None => {
139
- return Err(format!(
140
- "Feature name {:?} was not found.",
141
- canonical_feature_name
142
- ))
143
- }
144
- };
145
- config_builder = config_builder.add_source(source.clone());
146
- }
147
- Ok(config_builder.build())
148
- }
149
212
  }
@@ -0,0 +1,45 @@
1
+ use serde_json::Value;
2
+
3
+ use crate::{
4
+ provider::{CacheOptions, Features, GetOptionsPreferences},
5
+ schema::metadata::OptionsMetadata,
6
+ };
7
+
8
+ /// Trait defining the core functionality for an options provider
9
+ pub trait OptionsRegistry {
10
+ /// Gets all options for the specified feature names
11
+ fn get_all_options(
12
+ &self,
13
+ feature_names: &[&str],
14
+ cache_options: Option<&CacheOptions>,
15
+ preferences: Option<&GetOptionsPreferences>,
16
+ ) -> Result<Value, String>;
17
+
18
+ /// Gets the canonical feature name for a given feature name or alias
19
+ fn get_canonical_feature_name(&self, feature_name: &str) -> Result<String, String>;
20
+
21
+ // Map aliases or canonical feature names (perhaps derived from a file names) to the canonical feature names.
22
+ // Canonical feature names map to themselves.
23
+ //
24
+ // @param feature_names The names of aliases or features.
25
+ // @return The canonical feature names.
26
+ fn get_canonical_feature_names(&self, feature_names: &[&str]) -> Result<Vec<String>, String>;
27
+
28
+ fn get_feature_metadata(&self, canonical_feature_name: &str) -> Option<OptionsMetadata>;
29
+
30
+ fn get_features(&self) -> Vec<String>;
31
+
32
+ fn get_features_with_metadata(&self) -> Features;
33
+
34
+ /// Gets options for a specific key and feature names
35
+ fn get_options(&self, key: &str, feature_names: &[&str]) -> Result<Value, String>;
36
+
37
+ /// Gets options with preferences for a specific key and feature names
38
+ fn get_options_with_preferences(
39
+ &self,
40
+ key: &str,
41
+ feature_names: &[&str],
42
+ cache_options: Option<&CacheOptions>,
43
+ preferences: Option<&GetOptionsPreferences>,
44
+ ) -> Result<Value, String>;
45
+ }
@@ -0,0 +1,218 @@
1
+ use notify_debouncer_full::{new_debouncer, notify::RecommendedWatcher, DebounceEventResult};
2
+ use std::collections::HashSet;
3
+ use std::path::PathBuf;
4
+ use std::sync::{mpsc::channel, Arc, Mutex, RwLock};
5
+
6
+ use crate::builder::{OptionsProviderBuilder, OptionsRegistryBuilder};
7
+ use crate::provider::{
8
+ CacheOptions, Features, GetOptionsPreferences, OptionsProvider, OptionsRegistry,
9
+ };
10
+ use crate::schema::metadata::OptionsMetadata;
11
+
12
+ /// The duration to wait before triggering a rebuild after file changes.
13
+ pub const DEFAULT_DEBOUNCE_DURATION: std::time::Duration = std::time::Duration::from_secs(1);
14
+
15
+ /// A registry which changes the underlying when files are changed.
16
+ /// This is mainly meant to use for local development.
17
+ ///
18
+ /// ⚠️ Development in progress ⚠️\
19
+ /// Not truly considered public yet and mainly available to support bindings for other languages.
20
+ pub struct OptionsWatcher {
21
+ current_provider: Arc<RwLock<OptionsProvider>>,
22
+ last_modified: Arc<Mutex<std::time::SystemTime>>,
23
+ watched_directories: Vec<PathBuf>,
24
+ // The watcher needs to be held to continue watching files for changes.
25
+ #[allow(dead_code)]
26
+ debouncer_watcher: notify_debouncer_full::Debouncer<
27
+ RecommendedWatcher,
28
+ notify_debouncer_full::RecommendedCache,
29
+ >,
30
+ }
31
+
32
+ impl OptionsWatcher {
33
+ pub(crate) fn new(watched_directories: Vec<PathBuf>) -> Self {
34
+ // Set up the watcher before building in case the files change before building.
35
+ let (tx, rx) = channel();
36
+ let mut debouncer_watcher = new_debouncer(
37
+ DEFAULT_DEBOUNCE_DURATION,
38
+ None,
39
+ move |result: DebounceEventResult| match result {
40
+ Ok(events) => {
41
+ let paths = events
42
+ .iter()
43
+ .filter(|event| !event.kind.is_access())
44
+ .filter(|event| {
45
+ // Ignore metadata changes such as the modified time.
46
+ match event.kind {
47
+ notify::EventKind::Modify(modify_kind) => {
48
+ !matches!(modify_kind, notify::event::ModifyKind::Metadata(_))
49
+ }
50
+ _ => true,
51
+ }
52
+ })
53
+ .flat_map(|event| event.paths.clone())
54
+ .collect::<HashSet<_>>();
55
+
56
+ if paths.is_empty() {
57
+ return;
58
+ }
59
+
60
+ println!(
61
+ "[optify] Rebuilding OptionsProvider because contents at these path(s) changed: {:?}",
62
+ paths
63
+ );
64
+
65
+ tx.send(()).unwrap();
66
+ }
67
+ Err(errors) => errors
68
+ .iter()
69
+ .for_each(|error| println!("\x1b[31m[optify] {error:?}\x1b[0m")),
70
+ },
71
+ )
72
+ .unwrap();
73
+ for dir in &watched_directories {
74
+ debouncer_watcher
75
+ .watch(dir, notify::RecursiveMode::Recursive)
76
+ .expect("directory to be watched");
77
+ }
78
+ let mut builder = OptionsProviderBuilder::new();
79
+ for dir in &watched_directories {
80
+ builder
81
+ .add_directory(dir)
82
+ .expect("directory and contents to be valid");
83
+ }
84
+ let provider = builder.build().expect("provider to be built");
85
+ let last_modified = Arc::new(Mutex::new(std::time::SystemTime::now()));
86
+
87
+ let self_ = Self {
88
+ current_provider: Arc::new(RwLock::new(provider)),
89
+ last_modified,
90
+ watched_directories,
91
+ debouncer_watcher,
92
+ };
93
+
94
+ let current_provider = self_.current_provider.clone();
95
+ let watched_directories = self_.watched_directories.clone();
96
+ let last_modified = self_.last_modified.clone();
97
+
98
+ std::thread::spawn(move || {
99
+ for _ in rx {
100
+ let result = std::panic::catch_unwind(|| {
101
+ let mut skip_rebuild = false;
102
+ let mut builder = OptionsProviderBuilder::new();
103
+ for dir in &watched_directories {
104
+ if dir.exists() {
105
+ if let Err(e) = builder.add_directory(dir) {
106
+ println!(
107
+ "\x1b[31m[optify] Error rebuilding provider: {}\x1b[0m",
108
+ e
109
+ );
110
+ skip_rebuild = true;
111
+ break;
112
+ }
113
+ }
114
+ }
115
+
116
+ if skip_rebuild {
117
+ // Ignore errors because the developer might still be changing the files.
118
+ // TODO If there are still errors after a few minutes, then consider panicking.
119
+ return;
120
+ }
121
+
122
+ match builder.build() {
123
+ Ok(new_provider) => match current_provider.write() {
124
+ Ok(mut provider) => {
125
+ *provider = new_provider;
126
+ *last_modified.lock().unwrap() = std::time::SystemTime::now();
127
+ println!("\x1b[32m[optify] Successfully rebuilt the OptionsProvider.\x1b[0m");
128
+ }
129
+ Err(err) => {
130
+ println!(
131
+ "\x1b[31m[optify] Error rebuilding provider: {}\nWill not change the provider until the files are fixed.\x1b[0m",
132
+ err
133
+ );
134
+ }
135
+ },
136
+ Err(err) => {
137
+ println!("\x1b[31m[optify] Error rebuilding provider: {}\x1b[0m", err);
138
+ }
139
+ }
140
+ });
141
+
142
+ if result.is_err() {
143
+ println!("\x1b[31m[optify] Error rebuilding the provider. Will not change the provider until the files are fixed.\x1b[0m");
144
+ }
145
+ }
146
+ });
147
+
148
+ self_
149
+ }
150
+
151
+ /// Returns the time when the provider was finished building.
152
+ pub fn last_modified(&self) -> std::time::SystemTime {
153
+ *self.last_modified.lock().unwrap()
154
+ }
155
+ }
156
+
157
+ impl OptionsRegistry for OptionsWatcher {
158
+ fn get_all_options(
159
+ &self,
160
+ feature_names: &[&str],
161
+ cache_options: Option<&CacheOptions>,
162
+ preferences: Option<&GetOptionsPreferences>,
163
+ ) -> std::result::Result<serde_json::Value, String> {
164
+ let provider = self.current_provider.read().unwrap();
165
+ provider.get_all_options(feature_names, cache_options, preferences)
166
+ }
167
+
168
+ fn get_canonical_feature_name(
169
+ &self,
170
+ feature_name: &str,
171
+ ) -> std::result::Result<String, String> {
172
+ let provider = self.current_provider.read().unwrap();
173
+ provider.get_canonical_feature_name(feature_name)
174
+ }
175
+
176
+ fn get_canonical_feature_names(
177
+ &self,
178
+ feature_names: &[&str],
179
+ ) -> std::result::Result<Vec<String>, String> {
180
+ let provider = self.current_provider.read().unwrap();
181
+ provider.get_canonical_feature_names(feature_names)
182
+ }
183
+
184
+ fn get_feature_metadata(&self, canonical_feature_name: &str) -> Option<OptionsMetadata> {
185
+ let provider = self.current_provider.read().unwrap();
186
+ provider.get_feature_metadata(canonical_feature_name)
187
+ }
188
+
189
+ fn get_features(&self) -> Vec<String> {
190
+ let provider = self.current_provider.read().unwrap();
191
+ provider.get_features()
192
+ }
193
+
194
+ fn get_features_with_metadata(&self) -> Features {
195
+ let provider = self.current_provider.read().unwrap();
196
+ provider.get_features_with_metadata()
197
+ }
198
+
199
+ fn get_options(
200
+ &self,
201
+ key: &str,
202
+ feature_names: &[&str],
203
+ ) -> std::result::Result<serde_json::Value, String> {
204
+ let provider = self.current_provider.read().unwrap();
205
+ provider.get_options(key, feature_names)
206
+ }
207
+
208
+ fn get_options_with_preferences(
209
+ &self,
210
+ key: &str,
211
+ feature_names: &[&str],
212
+ cache_options: Option<&CacheOptions>,
213
+ preferences: Option<&GetOptionsPreferences>,
214
+ ) -> std::result::Result<serde_json::Value, String> {
215
+ let provider = self.current_provider.read().unwrap();
216
+ provider.get_options_with_preferences(key, feature_names, cache_options, preferences)
217
+ }
218
+ }
@@ -1,19 +0,0 @@
1
- from pathlib import Path
2
-
3
- from optify import OptionsProviderBuilder
4
-
5
-
6
- def test_features():
7
- test_suites_dir = (Path(__file__) / '../../../../tests/test_suites').resolve()
8
- builder = OptionsProviderBuilder()
9
- builder.add_directory(str(test_suites_dir / 'simple/configs'))
10
- provider = builder.build()
11
- features = provider.features()
12
- features.sort()
13
- assert features == ['A_with_comments', 'feature_A', 'feature_B/initial']
14
-
15
- try:
16
- provider.get_options_json('key', ['A'])
17
- assert False, "Should have raised an error"
18
- except BaseException as e:
19
- assert str(e) == "key and feature names should be valid: \"configuration property \\\"key\\\" not found\""
File without changes
File without changes
File without changes