optify 0.1.3__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.1.3 → optify-0.5.0}/PKG-INFO +31 -3
- {optify-0.1.3 → optify-0.5.0}/README.md +30 -2
- {optify-0.1.3 → optify-0.5.0}/pyproject.toml +2 -2
- {optify-0.1.3 → optify-0.5.0}/python/optify/Cargo.lock +206 -4
- {optify-0.1.3 → optify-0.5.0}/python/optify/Cargo.toml +2 -2
- {optify-0.1.3 → optify-0.5.0}/python/optify/README.md +30 -2
- 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.1.3 → optify-0.5.0}/python/optify/tests/test_optify.py +10 -5
- optify-0.5.0/python/optify/tests/test_provider.py +44 -0
- {optify-0.1.3 → optify-0.5.0}/rust/optify/Cargo.toml +6 -1
- {optify-0.1.3 → optify-0.5.0}/rust/optify/README.md +10 -1
- {optify-0.1.3 → optify-0.5.0}/rust/optify/benches/loading_benchmark.rs +7 -8
- optify-0.5.0/rust/optify/build.rs +30 -0
- optify-0.1.3/rust/optify/src/builder.rs → optify-0.5.0/rust/optify/src/builder/builder_impl.rs +122 -63
- optify-0.5.0/rust/optify/src/builder/builder_trait.rs +15 -0
- optify-0.5.0/rust/optify/src/builder/mod.rs +7 -0
- optify-0.5.0/rust/optify/src/builder/watcher_builder.rs +42 -0
- optify-0.5.0/rust/optify/src/provider/constraints.rs +4 -0
- optify-0.5.0/rust/optify/src/provider/mod.rs +8 -0
- optify-0.5.0/rust/optify/src/provider/provider_impl.rs +260 -0
- optify-0.5.0/rust/optify/src/provider/provider_trait.rs +57 -0
- optify-0.5.0/rust/optify/src/provider/watcher.rs +254 -0
- optify-0.5.0/rust/optify/src/schema/conditions.rs +170 -0
- {optify-0.1.3 → optify-0.5.0}/rust/optify/src/schema/feature.rs +5 -0
- {optify-0.1.3 → optify-0.5.0}/rust/optify/src/schema/mod.rs +1 -0
- optify-0.1.3/python/optify/src/lib.rs +0 -59
- optify-0.1.3/python/optify/tests/test_provider.py +0 -19
- optify-0.1.3/rust/optify/src/provider.rs +0 -149
- {optify-0.1.3 → optify-0.5.0}/python/optify/.gitignore +0 -0
- {optify-0.1.3 → optify-0.5.0}/python/optify/LICENSE.txt +0 -0
- {optify-0.1.3 → optify-0.5.0}/rust/optify/src/lib.rs +0 -0
- {optify-0.1.3 → 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
|
|
@@ -22,13 +22,41 @@ 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
|
|
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.
|
|
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
|
|
|
@@ -4,13 +4,41 @@
|
|
|
4
4
|
](https://pypi.org/project/optify)
|
|
5
5
|
|
|
6
6
|
⚠️ Development in progress ⚠️\
|
|
7
|
-
APIs are not final and
|
|
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.
|
|
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"
|
|
@@ -43,6 +52,12 @@ version = "0.21.7"
|
|
|
43
52
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
44
53
|
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
|
45
54
|
|
|
55
|
+
[[package]]
|
|
56
|
+
name = "bitflags"
|
|
57
|
+
version = "1.3.2"
|
|
58
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
59
|
+
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|
60
|
+
|
|
46
61
|
[[package]]
|
|
47
62
|
name = "bitflags"
|
|
48
63
|
version = "2.8.0"
|
|
@@ -205,6 +220,36 @@ version = "1.0.1"
|
|
|
205
220
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
206
221
|
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
|
207
222
|
|
|
223
|
+
[[package]]
|
|
224
|
+
name = "file-id"
|
|
225
|
+
version = "0.2.2"
|
|
226
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
227
|
+
checksum = "6bc904b9bbefcadbd8e3a9fb0d464a9b979de6324c03b3c663e8994f46a5be36"
|
|
228
|
+
dependencies = [
|
|
229
|
+
"windows-sys 0.52.0",
|
|
230
|
+
]
|
|
231
|
+
|
|
232
|
+
[[package]]
|
|
233
|
+
name = "filetime"
|
|
234
|
+
version = "0.2.25"
|
|
235
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
236
|
+
checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586"
|
|
237
|
+
dependencies = [
|
|
238
|
+
"cfg-if",
|
|
239
|
+
"libc",
|
|
240
|
+
"libredox",
|
|
241
|
+
"windows-sys 0.59.0",
|
|
242
|
+
]
|
|
243
|
+
|
|
244
|
+
[[package]]
|
|
245
|
+
name = "fsevent-sys"
|
|
246
|
+
version = "4.1.0"
|
|
247
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
248
|
+
checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
|
|
249
|
+
dependencies = [
|
|
250
|
+
"libc",
|
|
251
|
+
]
|
|
252
|
+
|
|
208
253
|
[[package]]
|
|
209
254
|
name = "generic-array"
|
|
210
255
|
version = "0.14.7"
|
|
@@ -272,6 +317,26 @@ version = "2.0.5"
|
|
|
272
317
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
273
318
|
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
|
|
274
319
|
|
|
320
|
+
[[package]]
|
|
321
|
+
name = "inotify"
|
|
322
|
+
version = "0.11.0"
|
|
323
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
324
|
+
checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3"
|
|
325
|
+
dependencies = [
|
|
326
|
+
"bitflags 2.8.0",
|
|
327
|
+
"inotify-sys",
|
|
328
|
+
"libc",
|
|
329
|
+
]
|
|
330
|
+
|
|
331
|
+
[[package]]
|
|
332
|
+
name = "inotify-sys"
|
|
333
|
+
version = "0.1.5"
|
|
334
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
335
|
+
checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb"
|
|
336
|
+
dependencies = [
|
|
337
|
+
"libc",
|
|
338
|
+
]
|
|
339
|
+
|
|
275
340
|
[[package]]
|
|
276
341
|
name = "itoa"
|
|
277
342
|
version = "1.0.14"
|
|
@@ -289,12 +354,49 @@ dependencies = [
|
|
|
289
354
|
"serde",
|
|
290
355
|
]
|
|
291
356
|
|
|
357
|
+
[[package]]
|
|
358
|
+
name = "kqueue"
|
|
359
|
+
version = "1.0.8"
|
|
360
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
361
|
+
checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c"
|
|
362
|
+
dependencies = [
|
|
363
|
+
"kqueue-sys",
|
|
364
|
+
"libc",
|
|
365
|
+
]
|
|
366
|
+
|
|
367
|
+
[[package]]
|
|
368
|
+
name = "kqueue-sys"
|
|
369
|
+
version = "1.0.4"
|
|
370
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
371
|
+
checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b"
|
|
372
|
+
dependencies = [
|
|
373
|
+
"bitflags 1.3.2",
|
|
374
|
+
"libc",
|
|
375
|
+
]
|
|
376
|
+
|
|
292
377
|
[[package]]
|
|
293
378
|
name = "libc"
|
|
294
379
|
version = "0.2.169"
|
|
295
380
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
296
381
|
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
|
297
382
|
|
|
383
|
+
[[package]]
|
|
384
|
+
name = "libredox"
|
|
385
|
+
version = "0.1.3"
|
|
386
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
387
|
+
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
|
|
388
|
+
dependencies = [
|
|
389
|
+
"bitflags 2.8.0",
|
|
390
|
+
"libc",
|
|
391
|
+
"redox_syscall",
|
|
392
|
+
]
|
|
393
|
+
|
|
394
|
+
[[package]]
|
|
395
|
+
name = "log"
|
|
396
|
+
version = "0.4.27"
|
|
397
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
398
|
+
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
|
399
|
+
|
|
298
400
|
[[package]]
|
|
299
401
|
name = "memchr"
|
|
300
402
|
version = "2.7.4"
|
|
@@ -310,6 +412,56 @@ dependencies = [
|
|
|
310
412
|
"autocfg",
|
|
311
413
|
]
|
|
312
414
|
|
|
415
|
+
[[package]]
|
|
416
|
+
name = "mio"
|
|
417
|
+
version = "1.0.3"
|
|
418
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
419
|
+
checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
|
|
420
|
+
dependencies = [
|
|
421
|
+
"libc",
|
|
422
|
+
"log",
|
|
423
|
+
"wasi",
|
|
424
|
+
"windows-sys 0.52.0",
|
|
425
|
+
]
|
|
426
|
+
|
|
427
|
+
[[package]]
|
|
428
|
+
name = "notify"
|
|
429
|
+
version = "8.0.0"
|
|
430
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
431
|
+
checksum = "2fee8403b3d66ac7b26aee6e40a897d85dc5ce26f44da36b8b73e987cc52e943"
|
|
432
|
+
dependencies = [
|
|
433
|
+
"bitflags 2.8.0",
|
|
434
|
+
"filetime",
|
|
435
|
+
"fsevent-sys",
|
|
436
|
+
"inotify",
|
|
437
|
+
"kqueue",
|
|
438
|
+
"libc",
|
|
439
|
+
"log",
|
|
440
|
+
"mio",
|
|
441
|
+
"notify-types",
|
|
442
|
+
"walkdir",
|
|
443
|
+
"windows-sys 0.59.0",
|
|
444
|
+
]
|
|
445
|
+
|
|
446
|
+
[[package]]
|
|
447
|
+
name = "notify-debouncer-full"
|
|
448
|
+
version = "0.5.0"
|
|
449
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
450
|
+
checksum = "d2d88b1a7538054351c8258338df7c931a590513fb3745e8c15eb9ff4199b8d1"
|
|
451
|
+
dependencies = [
|
|
452
|
+
"file-id",
|
|
453
|
+
"log",
|
|
454
|
+
"notify",
|
|
455
|
+
"notify-types",
|
|
456
|
+
"walkdir",
|
|
457
|
+
]
|
|
458
|
+
|
|
459
|
+
[[package]]
|
|
460
|
+
name = "notify-types"
|
|
461
|
+
version = "2.0.0"
|
|
462
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
463
|
+
checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d"
|
|
464
|
+
|
|
313
465
|
[[package]]
|
|
314
466
|
name = "once_cell"
|
|
315
467
|
version = "1.20.3"
|
|
@@ -318,10 +470,13 @@ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
|
|
|
318
470
|
|
|
319
471
|
[[package]]
|
|
320
472
|
name = "optify"
|
|
321
|
-
version = "0.
|
|
473
|
+
version = "0.14.0"
|
|
322
474
|
dependencies = [
|
|
323
475
|
"config",
|
|
476
|
+
"notify",
|
|
477
|
+
"notify-debouncer-full",
|
|
324
478
|
"rayon",
|
|
479
|
+
"regex",
|
|
325
480
|
"serde",
|
|
326
481
|
"serde_derive",
|
|
327
482
|
"serde_json",
|
|
@@ -331,7 +486,7 @@ dependencies = [
|
|
|
331
486
|
|
|
332
487
|
[[package]]
|
|
333
488
|
name = "optify-python"
|
|
334
|
-
version = "0.
|
|
489
|
+
version = "0.5.0"
|
|
335
490
|
dependencies = [
|
|
336
491
|
"optify",
|
|
337
492
|
"pyo3",
|
|
@@ -505,6 +660,44 @@ dependencies = [
|
|
|
505
660
|
"crossbeam-utils",
|
|
506
661
|
]
|
|
507
662
|
|
|
663
|
+
[[package]]
|
|
664
|
+
name = "redox_syscall"
|
|
665
|
+
version = "0.5.11"
|
|
666
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
667
|
+
checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3"
|
|
668
|
+
dependencies = [
|
|
669
|
+
"bitflags 2.8.0",
|
|
670
|
+
]
|
|
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
|
+
|
|
508
701
|
[[package]]
|
|
509
702
|
name = "ron"
|
|
510
703
|
version = "0.8.1"
|
|
@@ -512,7 +705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
|
512
705
|
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
|
|
513
706
|
dependencies = [
|
|
514
707
|
"base64",
|
|
515
|
-
"bitflags",
|
|
708
|
+
"bitflags 2.8.0",
|
|
516
709
|
"serde",
|
|
517
710
|
"serde_derive",
|
|
518
711
|
]
|
|
@@ -745,7 +938,16 @@ version = "0.1.9"
|
|
|
745
938
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
746
939
|
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
|
747
940
|
dependencies = [
|
|
748
|
-
"windows-sys",
|
|
941
|
+
"windows-sys 0.59.0",
|
|
942
|
+
]
|
|
943
|
+
|
|
944
|
+
[[package]]
|
|
945
|
+
name = "windows-sys"
|
|
946
|
+
version = "0.52.0"
|
|
947
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
948
|
+
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
|
949
|
+
dependencies = [
|
|
950
|
+
"windows-targets",
|
|
749
951
|
]
|
|
750
952
|
|
|
751
953
|
[[package]]
|
|
@@ -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"
|
|
@@ -4,13 +4,41 @@
|
|
|
4
4
|
](https://pypi.org/project/optify)
|
|
5
5
|
|
|
6
6
|
⚠️ Development in progress ⚠️\
|
|
7
|
-
APIs are not final and
|
|
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.
|
|
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 "
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from optify import OptionsProvider, OptionsProviderBuilder
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
test_suites_dir = (Path(__file__) / '../../../../tests/test_suites').resolve()
|
|
7
|
+
simple_configs_dir = str(test_suites_dir / 'simple/configs')
|
|
8
|
+
builder = OptionsProviderBuilder()
|
|
9
|
+
builder.add_directory(simple_configs_dir)
|
|
10
|
+
PROVIDER = builder.build()
|
|
11
|
+
|
|
12
|
+
def test_features():
|
|
13
|
+
features = PROVIDER.features()
|
|
14
|
+
features.sort()
|
|
15
|
+
assert features == ['A_with_comments', 'feature_A', 'feature_B/initial']
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
PROVIDER.get_options_json('key', ['A'])
|
|
19
|
+
assert False, "Should have raised an error"
|
|
20
|
+
except Exception as e:
|
|
21
|
+
assert str(e) == "configuration property \"key\" not found"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_canonical_feature_name():
|
|
25
|
+
assert PROVIDER.get_canonical_feature_name('feaTure_A') == 'feature_A'
|
|
26
|
+
assert PROVIDER.get_canonical_feature_name('feature_B/initial') == 'feature_B/initial'
|
|
27
|
+
assert PROVIDER.get_canonical_feature_name('A_with_comments') == 'A_with_comments'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_canonical_feature_names():
|
|
31
|
+
assert PROVIDER.get_canonical_feature_names(['feature_A']) == ['feature_A']
|
|
32
|
+
assert PROVIDER.get_canonical_feature_names(['feature_B/initial']) == ['feature_B/initial']
|
|
33
|
+
assert PROVIDER.get_canonical_feature_names(['A_with_COmments']) == ['A_with_comments']
|
|
34
|
+
|
|
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'])
|