optify 0.1.0__tar.gz → 0.1.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: optify
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -18,10 +18,18 @@ Project-URL: Issues, https://github.com/juharris/optify/issues
18
18
 
19
19
  # Optify Rust Bindings for Python
20
20
 
21
+ [![PyPI - Version](https://img.shields.io/pypi/v/optify?color=%23006dad)
22
+ ](https://pypi.org/project/optify)
23
+
21
24
  ⚠️ Development in progress ⚠️\
22
25
  APIs are not final and will change, for example, interfaces with be used.
23
26
  This is just meant to be minimal to get started and help build a Python library.
24
27
 
28
+ See the [homepage] for details.
29
+
30
+ ## Usage
31
+ See the [tests directory](./tests/) for examples.
32
+
25
33
  ## Development
26
34
 
27
35
  ### Setup
@@ -46,6 +54,14 @@ maturin develop
46
54
  pytest
47
55
  ```
48
56
 
57
+ ### Formatting
58
+ To automatically change the Rust code, run:
59
+ ```shell
60
+ cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
61
+ ```
62
+
49
63
  # Publishing
50
64
  A GitHub Action will automatically publish new versions: https://github.com/juharris/optify/actions/workflows/python_publish.yml
51
65
 
66
+ [homepage]: https://github.com/juharris/optify
67
+
@@ -1,9 +1,17 @@
1
1
  # Optify Rust Bindings for Python
2
2
 
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/optify?color=%23006dad)
4
+ ](https://pypi.org/project/optify)
5
+
3
6
  ⚠️ Development in progress ⚠️\
4
7
  APIs are not final and will change, for example, interfaces with be used.
5
8
  This is just meant to be minimal to get started and help build a Python library.
6
9
 
10
+ See the [homepage] for details.
11
+
12
+ ## Usage
13
+ See the [tests directory](./tests/) for examples.
14
+
7
15
  ## Development
8
16
 
9
17
  ### Setup
@@ -28,5 +36,13 @@ maturin develop
28
36
  pytest
29
37
  ```
30
38
 
39
+ ### Formatting
40
+ To automatically change the Rust code, run:
41
+ ```shell
42
+ cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
43
+ ```
44
+
31
45
  # Publishing
32
46
  A GitHub Action will automatically publish new versions: https://github.com/juharris/optify/actions/workflows/python_publish.yml
47
+
48
+ [homepage]: https://github.com/juharris/optify
@@ -26,11 +26,11 @@ build-backend = "maturin"
26
26
 
27
27
  [package]
28
28
  name = "optify"
29
- version = "0.1.0"
29
+ version = "0.1.2"
30
30
 
31
31
  [tool.poetry]
32
32
  name = "optify"
33
- version = "0.1.0"
33
+ version = "0.1.2"
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"]
@@ -287,7 +287,7 @@ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
287
287
 
288
288
  [[package]]
289
289
  name = "optify"
290
- version = "0.4.0"
290
+ version = "0.6.1"
291
291
  dependencies = [
292
292
  "config",
293
293
  "serde",
@@ -299,7 +299,7 @@ dependencies = [
299
299
 
300
300
  [[package]]
301
301
  name = "optify-python"
302
- version = "0.1.0"
302
+ version = "0.1.2"
303
303
  dependencies = [
304
304
  "optify",
305
305
  "pyo3",
@@ -383,9 +383,9 @@ dependencies = [
383
383
 
384
384
  [[package]]
385
385
  name = "pyo3"
386
- version = "0.23.4"
386
+ version = "0.24.1"
387
387
  source = "registry+https://github.com/rust-lang/crates.io-index"
388
- checksum = "57fe09249128b3173d092de9523eaa75136bf7ba85e0d69eca241c7939c933cc"
388
+ checksum = "17da310086b068fbdcefbba30aeb3721d5bb9af8db4987d6735b2183ca567229"
389
389
  dependencies = [
390
390
  "cfg-if",
391
391
  "indoc",
@@ -401,9 +401,9 @@ dependencies = [
401
401
 
402
402
  [[package]]
403
403
  name = "pyo3-build-config"
404
- version = "0.23.4"
404
+ version = "0.24.1"
405
405
  source = "registry+https://github.com/rust-lang/crates.io-index"
406
- checksum = "1cd3927b5a78757a0d71aa9dff669f903b1eb64b54142a9bd9f757f8fde65fd7"
406
+ checksum = "e27165889bd793000a098bb966adc4300c312497ea25cf7a690a9f0ac5aa5fc1"
407
407
  dependencies = [
408
408
  "once_cell",
409
409
  "target-lexicon",
@@ -411,9 +411,9 @@ dependencies = [
411
411
 
412
412
  [[package]]
413
413
  name = "pyo3-ffi"
414
- version = "0.23.4"
414
+ version = "0.24.1"
415
415
  source = "registry+https://github.com/rust-lang/crates.io-index"
416
- checksum = "dab6bb2102bd8f991e7749f130a70d05dd557613e39ed2deeee8e9ca0c4d548d"
416
+ checksum = "05280526e1dbf6b420062f3ef228b78c0c54ba94e157f5cb724a609d0f2faabc"
417
417
  dependencies = [
418
418
  "libc",
419
419
  "pyo3-build-config",
@@ -421,9 +421,9 @@ dependencies = [
421
421
 
422
422
  [[package]]
423
423
  name = "pyo3-macros"
424
- version = "0.23.4"
424
+ version = "0.24.1"
425
425
  source = "registry+https://github.com/rust-lang/crates.io-index"
426
- checksum = "91871864b353fd5ffcb3f91f2f703a22a9797c91b9ab497b1acac7b07ae509c7"
426
+ checksum = "5c3ce5686aa4d3f63359a5100c62a127c9f15e8398e5fdeb5deef1fed5cd5f44"
427
427
  dependencies = [
428
428
  "proc-macro2",
429
429
  "pyo3-macros-backend",
@@ -433,9 +433,9 @@ dependencies = [
433
433
 
434
434
  [[package]]
435
435
  name = "pyo3-macros-backend"
436
- version = "0.23.4"
436
+ version = "0.24.1"
437
437
  source = "registry+https://github.com/rust-lang/crates.io-index"
438
- checksum = "43abc3b80bc20f3facd86cd3c60beed58c3e2aa26213f3cda368de39c60a27e4"
438
+ checksum = "f4cf6faa0cbfb0ed08e89beb8103ae9724eb4750e3a78084ba4017cbe94f3855"
439
439
  dependencies = [
440
440
  "heck",
441
441
  "proc-macro2",
@@ -513,9 +513,9 @@ dependencies = [
513
513
 
514
514
  [[package]]
515
515
  name = "serde_json"
516
- version = "1.0.138"
516
+ version = "1.0.140"
517
517
  source = "registry+https://github.com/rust-lang/crates.io-index"
518
- checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949"
518
+ checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
519
519
  dependencies = [
520
520
  "itoa",
521
521
  "memchr",
@@ -556,9 +556,9 @@ dependencies = [
556
556
 
557
557
  [[package]]
558
558
  name = "target-lexicon"
559
- version = "0.12.16"
559
+ version = "0.13.2"
560
560
  source = "registry+https://github.com/rust-lang/crates.io-index"
561
- checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
561
+ checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a"
562
562
 
563
563
  [[package]]
564
564
  name = "thiserror"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "optify-python"
3
- version = "0.1.0"
3
+ version = "0.1.2"
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.4.0" }
18
- pyo3 = "0.23.3"
17
+ optify = { path = "../../rust/optify", version = "0.6.1" }
18
+ pyo3 = "0.24.1"
@@ -1,9 +1,17 @@
1
1
  # Optify Rust Bindings for Python
2
2
 
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/optify?color=%23006dad)
4
+ ](https://pypi.org/project/optify)
5
+
3
6
  ⚠️ Development in progress ⚠️\
4
7
  APIs are not final and will change, for example, interfaces with be used.
5
8
  This is just meant to be minimal to get started and help build a Python library.
6
9
 
10
+ See the [homepage] for details.
11
+
12
+ ## Usage
13
+ See the [tests directory](./tests/) for examples.
14
+
7
15
  ## Development
8
16
 
9
17
  ### Setup
@@ -28,5 +36,13 @@ maturin develop
28
36
  pytest
29
37
  ```
30
38
 
39
+ ### Formatting
40
+ To automatically change the Rust code, run:
41
+ ```shell
42
+ cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
43
+ ```
44
+
31
45
  # Publishing
32
46
  A GitHub Action will automatically publish new versions: https://github.com/juharris/optify/actions/workflows/python_publish.yml
47
+
48
+ [homepage]: https://github.com/juharris/optify
@@ -11,14 +11,21 @@ struct PyOptionsProviderBuilder(OptionsProviderBuilder);
11
11
  struct PyOptionsProvider(OptionsProvider);
12
12
 
13
13
  #[pymethods]
14
- impl PyOptionsProvider{
14
+ impl PyOptionsProvider {
15
+ fn features(&self) -> Vec<String> {
16
+ self.0.get_features()
17
+ }
18
+
15
19
  fn get_options_json(&self, key: &str, feature_names: Vec<String>) -> String {
16
- self.0.get_options(&key, &feature_names).unwrap().to_string()
20
+ self.0
21
+ .get_options(key, &feature_names)
22
+ .expect("Failed to get options")
23
+ .to_string()
17
24
  }
18
25
  }
19
26
 
20
27
  #[pymethods]
21
- impl PyOptionsProviderBuilder{
28
+ impl PyOptionsProviderBuilder {
22
29
  #[new]
23
30
  fn new() -> Self {
24
31
  Self(OptionsProviderBuilder::new())
@@ -26,17 +33,23 @@ impl PyOptionsProviderBuilder{
26
33
 
27
34
  fn add_directory(&mut self, directory: &str) -> Self {
28
35
  let path = std::path::Path::new(&directory);
29
- self.0.add_directory(path).unwrap();
36
+ self.0
37
+ .add_directory(path)
38
+ .expect("Failed to add the directory");
30
39
  // TODO Try to avoid cloning
31
40
  Self(self.0.clone())
32
41
  }
33
42
 
34
43
  fn build(&mut self) -> PyOptionsProvider {
35
- PyOptionsProvider(self.0.build().unwrap())
44
+ PyOptionsProvider(
45
+ self.0
46
+ .build()
47
+ .expect("Failed to build the options provider"),
48
+ )
36
49
  }
37
50
  }
38
51
 
39
- #[pymodule(name="optify")]
52
+ #[pymodule(name = "optify")]
40
53
  mod optify_python {
41
54
  #[pymodule_export]
42
55
  use super::PyOptionsProviderBuilder;
@@ -0,0 +1,23 @@
1
+ import os
2
+ import json
3
+ from pathlib import Path
4
+ import sys
5
+
6
+ from optify import OptionsProviderBuilder
7
+
8
+ def test_features():
9
+ test_suites_dir = (Path(__file__) / '../../../../tests/test_suites').resolve()
10
+ builder = OptionsProviderBuilder()
11
+ builder.add_directory(str(test_suites_dir / 'simple/configs'))
12
+ provider = builder.build()
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:
21
+ # Can't get pyo3_runtime.PanicException because can't import it and catching `Exception` doesn't work either.
22
+ e = sys.exc_info()[1]
23
+ assert str(e) == "Failed to get options: \"configuration property \\\"key\\\" not found\""
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "optify"
3
- version = "0.4.0"
3
+ version = "0.6.1"
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."
@@ -20,7 +20,7 @@ exclude = [
20
20
  config = "0.15.6"
21
21
  serde = "1.0.217"
22
22
  serde_derive = "1.0.217"
23
- serde_json = "1.0.137"
23
+ serde_json = "1.0.140"
24
24
  unicase = "2.8.1"
25
25
  walkdir = "2.5.0"
26
26
 
@@ -24,8 +24,7 @@ cargo test
24
24
  ## Formatting
25
25
  To automatically change code, run:
26
26
  ```shell
27
- cargo fmt
28
- cargo clippy --fix --allow-dirty --allow-staged
27
+ cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
29
28
  ```
30
29
 
31
30
  ## Publishing
@@ -3,8 +3,9 @@ use std::collections::{HashMap, HashSet};
3
3
  use std::path::Path;
4
4
  use walkdir::WalkDir;
5
5
 
6
- use crate::provider::{Aliases, OptionsProvider, Sources};
6
+ use crate::provider::{Aliases, Features, OptionsProvider, Sources};
7
7
  use crate::schema::feature::FeatureConfiguration;
8
+ use crate::schema::metadata::OptionsMetadata;
8
9
 
9
10
  type Imports = HashMap<String, Vec<String>>;
10
11
 
@@ -13,6 +14,7 @@ type Imports = HashMap<String, Vec<String>>;
13
14
  #[derive(Clone)]
14
15
  pub struct OptionsProviderBuilder {
15
16
  aliases: Aliases,
17
+ features: Features,
16
18
  imports: Imports,
17
19
  sources: Sources,
18
20
  }
@@ -29,7 +31,7 @@ fn add_alias(
29
31
  canonical_feature_name: &String,
30
32
  ) -> Result<(), String> {
31
33
  let uni_case_alias = unicase::UniCase::new(alias.clone());
32
- if let Some(res) = aliases.insert(uni_case_alias, canonical_feature_name.clone()) {
34
+ if let Some(ref res) = aliases.insert(uni_case_alias, canonical_feature_name.clone()) {
33
35
  return Err(format!(
34
36
  "The alias '{alias}' for canonical feature name '{canonical_feature_name}' is already mapped to '{res}'."
35
37
  ));
@@ -89,7 +91,7 @@ fn resolve_imports(
89
91
  _features_in_resolution_path.insert(import.clone());
90
92
  resolve_imports(
91
93
  import,
92
- &imports_for_import.clone(),
94
+ imports_for_import,
93
95
  resolved_imports,
94
96
  &mut _features_in_resolution_path,
95
97
  aliases,
@@ -109,7 +111,7 @@ fn resolve_imports(
109
111
  let source = sources.get(canonical_feature_name).unwrap();
110
112
  config_builder = config_builder.add_source(source.clone());
111
113
 
112
- // We have the configuration, build it and store it.
114
+ // Build the configuration and store it.
113
115
  match config_builder.build() {
114
116
  Ok(new_config) => {
115
117
  // Convert to something that can be inserted as a source.
@@ -121,8 +123,9 @@ fn resolve_imports(
121
123
  ))
122
124
  }
123
125
  };
124
- let options_as_json: serde_json::Value =
125
- options_as_config_value.try_deserialize().unwrap();
126
+ let options_as_json: serde_json::Value = options_as_config_value
127
+ .try_deserialize()
128
+ .expect("Error deserializing the configuration as JSON.");
126
129
  let options_as_json_str = serde_json::to_string(&options_as_json).unwrap();
127
130
  let source = config::File::from_str(&options_as_json_str, config::FileFormat::Json);
128
131
  sources.insert(canonical_feature_name.to_owned(), source);
@@ -142,6 +145,7 @@ impl OptionsProviderBuilder {
142
145
  pub fn new() -> Self {
143
146
  OptionsProviderBuilder {
144
147
  aliases: Aliases::new(),
148
+ features: Features::new(),
145
149
  imports: HashMap::new(),
146
150
  sources: Sources::new(),
147
151
  }
@@ -221,14 +225,26 @@ impl OptionsProviderBuilder {
221
225
  &canonical_feature_name,
222
226
  )?;
223
227
 
228
+ // Handle metadata.
224
229
  // Add aliases.
225
- if let Some(metadata) = feature_config.metadata {
226
- if let Some(aliases) = metadata.aliases {
227
- for alias in aliases {
228
- add_alias(&mut self.aliases, &alias, &canonical_feature_name)?;
230
+ // Ensure name is set.
231
+ let metadata = match feature_config.metadata {
232
+ Some(mut metadata) => {
233
+ if let Some(ref aliases) = metadata.aliases {
234
+ for alias in aliases {
235
+ add_alias(&mut self.aliases, alias, &canonical_feature_name)?;
236
+ }
229
237
  }
238
+ metadata.name = Some(canonical_feature_name.clone());
239
+ metadata
230
240
  }
231
- }
241
+ None => {
242
+ OptionsMetadata::new(None, None, None, Some(canonical_feature_name.clone()))
243
+ }
244
+ };
245
+
246
+ self.features
247
+ .insert(canonical_feature_name.clone(), metadata.clone());
232
248
  }
233
249
 
234
250
  Ok(self)
@@ -253,6 +269,10 @@ impl OptionsProviderBuilder {
253
269
  }
254
270
  }
255
271
 
256
- Ok(OptionsProvider::new(&self.aliases, &self.sources))
272
+ Ok(OptionsProvider::new(
273
+ &self.aliases,
274
+ &self.features,
275
+ &self.sources,
276
+ ))
257
277
  }
258
278
  }
@@ -1,3 +1,3 @@
1
1
  pub mod builder;
2
2
  pub mod provider;
3
- pub(crate) mod schema;
3
+ pub mod schema;
@@ -1,6 +1,8 @@
1
1
  use config::{self};
2
2
  use std::collections::HashMap;
3
3
 
4
+ use crate::schema::metadata::OptionsMetadata;
5
+
4
6
  // Replicating https://github.com/juharris/dotnet-OptionsProvider/blob/main/src/OptionsProvider/OptionsProvider/IOptionsProvider.cs
5
7
  // and https://github.com/juharris/dotnet-OptionsProvider/blob/main/src/OptionsProvider/OptionsProvider/OptionsProviderWithDefaults.cs
6
8
 
@@ -8,27 +10,49 @@ use std::collections::HashMap;
8
10
  pub(crate) type SourceValue = config::File<config::FileSourceString, config::FileFormat>;
9
11
 
10
12
  pub(crate) type Aliases = HashMap<unicase::UniCase<String>, String>;
13
+ pub(crate) type Features = HashMap<String, OptionsMetadata>;
11
14
  pub(crate) type Sources = HashMap<String, SourceValue>;
12
15
 
13
16
  pub struct GetOptionsPreferences {
14
17
  pub skip_feature_name_conversion: bool,
15
18
  }
16
19
 
20
+ pub struct CacheOptions {}
21
+
17
22
  /// ⚠️ Development in progress ⚠️\
18
23
  /// Not truly considered public and mainly available to support bindings for other languages.
19
24
  pub struct OptionsProvider {
20
25
  aliases: Aliases,
26
+ features: Features,
21
27
  sources: Sources,
22
28
  }
23
29
 
24
30
  impl OptionsProvider {
25
- pub(crate) fn new(aliases: &Aliases, sources: &Sources) -> Self {
31
+ pub(crate) fn new(aliases: &Aliases, features: &Features, sources: &Sources) -> Self {
26
32
  OptionsProvider {
27
33
  aliases: aliases.clone(),
34
+ features: features.clone(),
28
35
  sources: sources.clone(),
29
36
  }
30
37
  }
31
38
 
39
+ pub fn get_all_options(
40
+ &self,
41
+ feature_names: &Vec<String>,
42
+ cache_options: &Option<CacheOptions>,
43
+ preferences: &Option<GetOptionsPreferences>,
44
+ ) -> Result<serde_json::Value, String> {
45
+ let config = self._get_entire_config(feature_names, cache_options, preferences)?;
46
+
47
+ match config {
48
+ Ok(cfg) => match cfg.try_deserialize() {
49
+ Ok(value) => Ok(value),
50
+ Err(e) => Err(e.to_string()),
51
+ },
52
+ Err(e) => Err(e.to_string()),
53
+ }
54
+ }
55
+
32
56
  // Map an alias or canonical feature name (perhaps derived from a file name) to a canonical feature name.
33
57
  // Canonical feature names map to themselves.
34
58
  //
@@ -46,23 +70,53 @@ impl OptionsProvider {
46
70
  }
47
71
  }
48
72
 
73
+ pub fn get_feature_metadata(&self, canonical_feature_name: &str) -> Option<&OptionsMetadata> {
74
+ self.features.get(canonical_feature_name)
75
+ }
76
+
77
+ pub fn get_features(&self) -> Vec<String> {
78
+ self.sources.keys().map(|s| s.to_owned()).collect()
79
+ }
80
+
81
+ pub fn get_features_with_metadata(&self) -> &Features {
82
+ &self.features
83
+ }
84
+
49
85
  pub fn get_options(
50
86
  &self,
51
87
  key: &str,
52
88
  feature_names: &Vec<String>,
53
89
  ) -> Result<serde_json::Value, String> {
54
- self.get_option_with_preferences(key, feature_names, &None)
90
+ self.get_options_with_preferences(key, feature_names, &None, &None)
55
91
  }
56
92
 
57
- // TODO Add another method with caching
58
- // with an option to disable because we will not want to use the cache when calling from other languages because they should use their own caching
59
- // in order to avoid possible overhead and conversion.
60
- pub fn get_option_with_preferences(
93
+ pub fn get_options_with_preferences(
61
94
  &self,
62
95
  key: &str,
63
96
  feature_names: &Vec<String>,
97
+ cache_options: &Option<CacheOptions>,
64
98
  preferences: &Option<GetOptionsPreferences>,
65
99
  ) -> Result<serde_json::Value, String> {
100
+ let config = self._get_entire_config(feature_names, cache_options, preferences)?;
101
+
102
+ match config {
103
+ Ok(cfg) => match cfg.get(key) {
104
+ Ok(value) => Ok(value),
105
+ Err(e) => Err(e.to_string()),
106
+ },
107
+ Err(e) => Err(e.to_string()),
108
+ }
109
+ }
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
+ };
66
120
  let mut config_builder = config::Config::builder();
67
121
  let mut skip_feature_name_conversion = false;
68
122
  if let Some(_preferences) = preferences {
@@ -90,14 +144,6 @@ impl OptionsProvider {
90
144
  };
91
145
  config_builder = config_builder.add_source(source.clone());
92
146
  }
93
- let config = config_builder.build();
94
-
95
- match config {
96
- Ok(cfg) => match cfg.get(key) {
97
- Ok(value) => Ok(value),
98
- Err(e) => Err(e.to_string()),
99
- },
100
- Err(e) => Err(e.to_string()),
101
- }
147
+ Ok(config_builder.build())
102
148
  }
103
149
  }
@@ -6,7 +6,7 @@ use super::metadata::OptionsMetadata;
6
6
 
7
7
  pub(crate) type ConfigurationOptions = config::Value;
8
8
 
9
- #[derive(Debug, Deserialize)]
9
+ #[derive(Clone, Debug, Deserialize)]
10
10
  #[allow(unused)]
11
11
  pub(crate) struct FeatureConfiguration {
12
12
  pub imports: Option<Vec<String>>,
@@ -0,0 +1,51 @@
1
+ // Similar to https://github.com/juharris/dotnet-OptionsProvider/blob/main/src/OptionsProvider/OptionsProvider/OptionsMetadata.cs
2
+
3
+ use serde::{Deserialize, Serialize};
4
+
5
+ type Details = serde_json::Value;
6
+
7
+ /// Information about a group of options.
8
+ #[derive(Clone, Debug, Deserialize, Serialize)]
9
+ #[allow(unused)]
10
+ pub struct OptionsMetadata {
11
+ // TODO Add more props.
12
+ /// Alternative names for the group of options.
13
+ ///
14
+ /// This is helpful for using custom short names for the group of options.
15
+ pub aliases: Option<Vec<String>>,
16
+
17
+ /// Other metadata that may be custom and application specific.
18
+ ///
19
+ /// This is a good place for documentation that should be available to the application.
20
+ /// Comments that are not parsed are still great to have in files, when supported,
21
+ /// but some comments are useful to have here because they can be accessed programmatically.
22
+ pub details: Option<Details>,
23
+
24
+ /// The name of the group of options.
25
+ ///
26
+ /// This may be derived from the file name including subdirectories.
27
+ /// Should never be <tt>None</tt> or an empty string.
28
+ /// When loading the options from a file, the name is automatically derived from the file name.
29
+ pub name: Option<String>,
30
+
31
+ /// The creators or maintainers of this group of options.
32
+ ///
33
+ /// For example, emails separated by ";".
34
+ pub owners: Option<String>,
35
+ }
36
+
37
+ impl OptionsMetadata {
38
+ pub fn new(
39
+ aliases: Option<Vec<String>>,
40
+ details: Option<Details>,
41
+ name: Option<String>,
42
+ owners: Option<String>,
43
+ ) -> Self {
44
+ Self {
45
+ aliases,
46
+ details,
47
+ name,
48
+ owners,
49
+ }
50
+ }
51
+ }
@@ -1,15 +0,0 @@
1
- // Similar to https://github.com/juharris/dotnet-OptionsProvider/blob/main/src/OptionsProvider/OptionsProvider/OptionsMetadata.cs
2
-
3
- use serde::Deserialize;
4
-
5
- #[derive(Clone, Debug, Deserialize)]
6
- #[allow(unused)]
7
- pub struct OptionsMetadata {
8
- // TODO Add more props.
9
- /// Alternative names for the group of options.
10
- /// This is helpful for using custom short names for the group of options.
11
- pub aliases: Option<Vec<String>>,
12
- /// The creators or maintainers of this group of options.
13
- /// For example, emails separated by ";".
14
- pub owners: Option<String>,
15
- }
File without changes
File without changes