optify 0.5.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {optify-0.5.0 → optify-0.6.0}/PKG-INFO +2 -2
- {optify-0.5.0 → optify-0.6.0}/pyproject.toml +2 -2
- {optify-0.5.0 → optify-0.6.0}/python/optify/.gitignore +0 -3
- optify-0.6.0/python/optify/.vscode/settings.json +3 -0
- {optify-0.5.0 → optify-0.6.0}/python/optify/Cargo.lock +9 -2
- {optify-0.5.0 → optify-0.6.0}/python/optify/Cargo.toml +3 -2
- optify-0.6.0/python/optify/LICENSE.txt +21 -0
- {optify-0.5.0 → optify-0.6.0}/python/optify/src/lib.rs +1 -1
- {optify-0.5.0 → optify-0.6.0}/python/optify/tests/test_provider.py +1 -1
- optify-0.6.0/rust/optify/.claude/settings.json +24 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/Cargo.toml +2 -1
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/builder/builder_impl.rs +12 -4
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/provider/provider_impl.rs +38 -31
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/provider/provider_trait.rs +11 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/provider/watcher.rs +25 -15
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/schema/metadata.rs +5 -0
- {optify-0.5.0/python/optify → optify-0.6.0}/LICENSE.txt +0 -0
- {optify-0.5.0 → optify-0.6.0}/README.md +0 -0
- {optify-0.5.0 → optify-0.6.0}/python/optify/README.md +0 -0
- {optify-0.5.0 → optify-0.6.0}/python/optify/tests/test_builder.py +0 -0
- {optify-0.5.0 → optify-0.6.0}/python/optify/tests/test_optify.py +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/README.md +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/benches/loading_benchmark.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/build.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/builder/builder_trait.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/builder/mod.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/builder/watcher_builder.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/lib.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/provider/constraints.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/provider/mod.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/schema/conditions.rs +0 -0
- {optify-0.5.0 → optify-0.6.0}/rust/optify/src/schema/feature.rs +0 -0
- {optify-0.5.0 → optify-0.6.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.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -10,7 +10,7 @@ License-File: LICENSE.txt
|
|
|
10
10
|
Summary: Simplifies getting the right configuration options for a process using pre-loaded configurations from files to manage options for experiments or flights.
|
|
11
11
|
Home-Page: https://github.com/juharris/optify/tree/main/rust/optify
|
|
12
12
|
Author: Justin D. Harris
|
|
13
|
-
License: MIT
|
|
13
|
+
License-Expression: MIT
|
|
14
14
|
Requires-Python: >=3.8
|
|
15
15
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
16
16
|
Project-URL: Homepage, https://github.com/juharris/optify
|
|
@@ -26,11 +26,11 @@ build-backend = "maturin"
|
|
|
26
26
|
|
|
27
27
|
[package]
|
|
28
28
|
name = "optify"
|
|
29
|
-
version = "0.
|
|
29
|
+
version = "0.6.0"
|
|
30
30
|
|
|
31
31
|
[tool.poetry]
|
|
32
32
|
name = "optify"
|
|
33
|
-
version = "0.
|
|
33
|
+
version = "0.6.0"
|
|
34
34
|
description = "Simplifies getting the right configuration options for a process using pre-loaded configurations from files to manage options for experiments or flights."
|
|
35
35
|
authors = ["Justin D. Harris"]
|
|
36
36
|
maintainers = ["Justin D. Harris"]
|
|
@@ -199,6 +199,12 @@ dependencies = [
|
|
|
199
199
|
"const-random",
|
|
200
200
|
]
|
|
201
201
|
|
|
202
|
+
[[package]]
|
|
203
|
+
name = "dunce"
|
|
204
|
+
version = "1.0.5"
|
|
205
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
206
|
+
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
|
|
207
|
+
|
|
202
208
|
[[package]]
|
|
203
209
|
name = "either"
|
|
204
210
|
version = "1.15.0"
|
|
@@ -470,9 +476,10 @@ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
|
|
|
470
476
|
|
|
471
477
|
[[package]]
|
|
472
478
|
name = "optify"
|
|
473
|
-
version = "0.
|
|
479
|
+
version = "0.16.0"
|
|
474
480
|
dependencies = [
|
|
475
481
|
"config",
|
|
482
|
+
"dunce",
|
|
476
483
|
"notify",
|
|
477
484
|
"notify-debouncer-full",
|
|
478
485
|
"rayon",
|
|
@@ -486,7 +493,7 @@ dependencies = [
|
|
|
486
493
|
|
|
487
494
|
[[package]]
|
|
488
495
|
name = "optify-python"
|
|
489
|
-
version = "0.
|
|
496
|
+
version = "0.6.0"
|
|
490
497
|
dependencies = [
|
|
491
498
|
"optify",
|
|
492
499
|
"pyo3",
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "optify-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
|
|
6
6
|
description = "Simplifies getting the right configuration options for a process using pre-loaded configurations from files (JSON, YAML, etc.) to manage options for experiments or flights. This library is mainly made to support building implementations for other languages such as Node.js, Python, and Ruby. It is not meant to be consumed directly yet."
|
|
7
7
|
homepage = "https://github.com/juharris/optify/tree/main/rust/optify"
|
|
8
8
|
license = "MIT"
|
|
9
9
|
repository = "https://github.com/juharris/optify/tree/main/rust/optify"
|
|
10
|
+
readme = "README.md"
|
|
10
11
|
|
|
11
12
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
12
13
|
[lib]
|
|
@@ -14,5 +15,5 @@ name = "optify"
|
|
|
14
15
|
crate-type = ["cdylib"]
|
|
15
16
|
|
|
16
17
|
[dependencies]
|
|
17
|
-
optify = { path = "../../rust/optify", version = "0.
|
|
18
|
+
optify = { path = "../../rust/optify", version = "0.16.0" }
|
|
18
19
|
pyo3 = "0.24.1"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Justin D. Harris
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -18,7 +18,7 @@ def test_features():
|
|
|
18
18
|
PROVIDER.get_options_json('key', ['A'])
|
|
19
19
|
assert False, "Should have raised an error"
|
|
20
20
|
except Exception as e:
|
|
21
|
-
assert str(e) == "configuration property \"key\" not found"
|
|
21
|
+
assert str(e) == "Error getting options with features [\"A\"]: configuration property \"key\" not found"
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
def test_canonical_feature_name():
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"PostToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "Bash|Edit|MultiEdit|Update|Write",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "cargo fmt"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"matcher": "Bash|Edit|MultiEdit|Update|Write",
|
|
15
|
+
"hooks": [
|
|
16
|
+
{
|
|
17
|
+
"type": "command",
|
|
18
|
+
"command": "cargo clippy --fix --allow-dirty --allow-staged"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "optify"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.16.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
build = "build.rs"
|
|
6
6
|
|
|
@@ -19,6 +19,7 @@ exclude = [
|
|
|
19
19
|
|
|
20
20
|
[dependencies]
|
|
21
21
|
config = "0.15.6"
|
|
22
|
+
dunce = "1.0.5"
|
|
22
23
|
notify = "8.0.0"
|
|
23
24
|
notify-debouncer-full = "0.5.0"
|
|
24
25
|
rayon = "1.10.0"
|
|
@@ -198,13 +198,14 @@ impl OptionsProviderBuilder {
|
|
|
198
198
|
// The `config` library is helpful because it handles many file types.
|
|
199
199
|
// It would also be nice to support comments in .json files, even though it is not standard.
|
|
200
200
|
// The `config` library does support .json5 which supports comments.
|
|
201
|
+
let absolute_path = dunce::canonicalize(path).expect("path should be valid");
|
|
201
202
|
let file = config::File::from(path);
|
|
202
203
|
let config_for_path = match config::Config::builder().add_source(file).build() {
|
|
203
204
|
Ok(conf) => conf,
|
|
204
205
|
Err(e) => {
|
|
205
206
|
return Some(Err(format!(
|
|
206
207
|
"Error loading file '{}': {e}",
|
|
207
|
-
|
|
208
|
+
absolute_path.to_string_lossy(),
|
|
208
209
|
)))
|
|
209
210
|
}
|
|
210
211
|
};
|
|
@@ -214,7 +215,7 @@ impl OptionsProviderBuilder {
|
|
|
214
215
|
Err(e) => {
|
|
215
216
|
return Some(Err(format!(
|
|
216
217
|
"Error deserializing configuration for file '{}': {e}",
|
|
217
|
-
|
|
218
|
+
absolute_path.to_string_lossy(),
|
|
218
219
|
)))
|
|
219
220
|
}
|
|
220
221
|
};
|
|
@@ -225,7 +226,7 @@ impl OptionsProviderBuilder {
|
|
|
225
226
|
Err(e) => {
|
|
226
227
|
return Some(Err(format!(
|
|
227
228
|
"Error deserializing options for '{}': {e}",
|
|
228
|
-
|
|
229
|
+
absolute_path.to_string_lossy(),
|
|
229
230
|
)))
|
|
230
231
|
}
|
|
231
232
|
},
|
|
@@ -238,9 +239,16 @@ impl OptionsProviderBuilder {
|
|
|
238
239
|
let metadata = match feature_config.metadata {
|
|
239
240
|
Some(mut metadata) => {
|
|
240
241
|
metadata.name = Some(canonical_feature_name.clone());
|
|
242
|
+
metadata.path = Some(absolute_path.to_string_lossy().to_string());
|
|
241
243
|
metadata
|
|
242
244
|
}
|
|
243
|
-
None => OptionsMetadata::new(
|
|
245
|
+
None => OptionsMetadata::new(
|
|
246
|
+
None,
|
|
247
|
+
None,
|
|
248
|
+
Some(canonical_feature_name.clone()),
|
|
249
|
+
None,
|
|
250
|
+
Some(absolute_path.to_string_lossy().to_string()),
|
|
251
|
+
),
|
|
244
252
|
};
|
|
245
253
|
|
|
246
254
|
Some(Ok(LoadingResult {
|
|
@@ -90,28 +90,12 @@ impl OptionsProvider {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
pub fn build(directory: impl AsRef<Path>) -> Result<OptionsProvider, String> {
|
|
94
|
-
let mut builder = OptionsProviderBuilder::new();
|
|
95
|
-
builder.add_directory(directory.as_ref())?;
|
|
96
|
-
builder.build()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
pub fn build_from_directories(
|
|
100
|
-
directories: &[impl AsRef<Path>],
|
|
101
|
-
) -> Result<OptionsProvider, String> {
|
|
102
|
-
let mut builder = OptionsProviderBuilder::new();
|
|
103
|
-
for directory in directories {
|
|
104
|
-
builder.add_directory(directory.as_ref())?;
|
|
105
|
-
}
|
|
106
|
-
builder.build()
|
|
107
|
-
}
|
|
108
|
-
|
|
109
93
|
fn get_entire_config(
|
|
110
94
|
&self,
|
|
111
95
|
feature_names: &[impl AsRef<str>],
|
|
112
96
|
cache_options: Option<&CacheOptions>,
|
|
113
97
|
preferences: Option<&GetOptionsPreferences>,
|
|
114
|
-
) -> Result<
|
|
98
|
+
) -> Result<config::Config, String> {
|
|
115
99
|
if let Some(_cache_options) = cache_options {
|
|
116
100
|
if let Some(preferences) = preferences {
|
|
117
101
|
if preferences.overrides_json.is_some() {
|
|
@@ -153,7 +137,7 @@ impl OptionsProvider {
|
|
|
153
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.
|
|
154
138
|
None => {
|
|
155
139
|
return Err(format!(
|
|
156
|
-
"Feature name {canonical_feature_name:?}
|
|
140
|
+
"Feature name {canonical_feature_name:?} is not a known feature."
|
|
157
141
|
))
|
|
158
142
|
}
|
|
159
143
|
};
|
|
@@ -166,11 +150,30 @@ impl OptionsProvider {
|
|
|
166
150
|
}
|
|
167
151
|
}
|
|
168
152
|
|
|
169
|
-
|
|
153
|
+
match config_builder.build() {
|
|
154
|
+
Ok(cfg) => Ok(cfg),
|
|
155
|
+
Err(e) => Err(format!(
|
|
156
|
+
"Error combining features to build the configuration: {e}"
|
|
157
|
+
)),
|
|
158
|
+
}
|
|
170
159
|
}
|
|
171
160
|
}
|
|
172
161
|
|
|
173
162
|
impl OptionsRegistry for OptionsProvider {
|
|
163
|
+
fn build(directory: impl AsRef<Path>) -> Result<OptionsProvider, String> {
|
|
164
|
+
let mut builder = OptionsProviderBuilder::new();
|
|
165
|
+
builder.add_directory(directory.as_ref())?;
|
|
166
|
+
builder.build()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fn build_from_directories(directories: &[impl AsRef<Path>]) -> Result<OptionsProvider, String> {
|
|
170
|
+
let mut builder = OptionsProviderBuilder::new();
|
|
171
|
+
for directory in directories {
|
|
172
|
+
builder.add_directory(directory.as_ref())?;
|
|
173
|
+
}
|
|
174
|
+
builder.build()
|
|
175
|
+
}
|
|
176
|
+
|
|
174
177
|
fn get_aliases(&self) -> Vec<String> {
|
|
175
178
|
self.features
|
|
176
179
|
.values()
|
|
@@ -192,11 +195,8 @@ impl OptionsRegistry for OptionsProvider {
|
|
|
192
195
|
) -> Result<serde_json::Value, String> {
|
|
193
196
|
let config = self.get_entire_config(feature_names, cache_options, preferences)?;
|
|
194
197
|
|
|
195
|
-
match config {
|
|
196
|
-
Ok(
|
|
197
|
-
Ok(value) => Ok(value),
|
|
198
|
-
Err(e) => Err(e.to_string()),
|
|
199
|
-
},
|
|
198
|
+
match config.try_deserialize() {
|
|
199
|
+
Ok(value) => Ok(value),
|
|
200
200
|
Err(e) => Err(e.to_string()),
|
|
201
201
|
}
|
|
202
202
|
}
|
|
@@ -206,7 +206,9 @@ impl OptionsRegistry for OptionsProvider {
|
|
|
206
206
|
let feature_name = unicase::UniCase::new(feature_name.to_owned());
|
|
207
207
|
match self.aliases.get(&feature_name) {
|
|
208
208
|
Some(canonical_name) => Ok(canonical_name.to_owned()),
|
|
209
|
-
None => Err(format!(
|
|
209
|
+
None => Err(format!(
|
|
210
|
+
"Feature name {feature_name:?} is not a known feature."
|
|
211
|
+
)),
|
|
210
212
|
}
|
|
211
213
|
}
|
|
212
214
|
|
|
@@ -249,12 +251,17 @@ impl OptionsRegistry for OptionsProvider {
|
|
|
249
251
|
) -> Result<serde_json::Value, String> {
|
|
250
252
|
let config = self.get_entire_config(feature_names, cache_options, preferences)?;
|
|
251
253
|
|
|
252
|
-
match config {
|
|
253
|
-
Ok(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
254
|
+
match config.get(key) {
|
|
255
|
+
Ok(value) => Ok(value),
|
|
256
|
+
Err(e) => {
|
|
257
|
+
let features = feature_names
|
|
258
|
+
.iter()
|
|
259
|
+
.map(|name| name.as_ref())
|
|
260
|
+
.collect::<Vec<_>>();
|
|
261
|
+
Err(format!(
|
|
262
|
+
"Error getting options with features {features:?}: {e}"
|
|
263
|
+
))
|
|
264
|
+
}
|
|
258
265
|
}
|
|
259
266
|
}
|
|
260
267
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
use std::path::Path;
|
|
2
|
+
|
|
1
3
|
use serde_json::Value;
|
|
2
4
|
|
|
3
5
|
use crate::{
|
|
@@ -7,6 +9,14 @@ use crate::{
|
|
|
7
9
|
|
|
8
10
|
/// Trait defining the core functionality for an options provider
|
|
9
11
|
pub trait OptionsRegistry {
|
|
12
|
+
fn build(directory: impl AsRef<Path>) -> Result<Self, String>
|
|
13
|
+
where
|
|
14
|
+
Self: Sized;
|
|
15
|
+
|
|
16
|
+
fn build_from_directories(directories: &[impl AsRef<Path>]) -> Result<Self, String>
|
|
17
|
+
where
|
|
18
|
+
Self: Sized;
|
|
19
|
+
|
|
10
20
|
/// Gets all alias names.
|
|
11
21
|
fn get_aliases(&self) -> Vec<String>;
|
|
12
22
|
|
|
@@ -41,6 +51,7 @@ pub trait OptionsRegistry {
|
|
|
41
51
|
/// Returns all of the canonical feature names.
|
|
42
52
|
fn get_features(&self) -> Vec<String>;
|
|
43
53
|
|
|
54
|
+
/// Returns a map of all the canonical feature names to their metadata.
|
|
44
55
|
fn get_features_with_metadata(&self) -> Features;
|
|
45
56
|
|
|
46
57
|
/// Gets options for a specific key and feature names
|
|
@@ -12,6 +12,8 @@ use crate::schema::metadata::OptionsMetadata;
|
|
|
12
12
|
/// The duration to wait before triggering a rebuild after file changes.
|
|
13
13
|
pub const DEFAULT_DEBOUNCE_DURATION: std::time::Duration = std::time::Duration::from_secs(1);
|
|
14
14
|
|
|
15
|
+
pub type OptionsWatcherListener = Arc<dyn Fn(&HashSet<PathBuf>) + Send + Sync>;
|
|
16
|
+
|
|
15
17
|
/// A registry which changes the underlying when files are changed.
|
|
16
18
|
/// This is mainly meant to use for local development.
|
|
17
19
|
///
|
|
@@ -27,6 +29,7 @@ pub struct OptionsWatcher {
|
|
|
27
29
|
RecommendedWatcher,
|
|
28
30
|
notify_debouncer_full::RecommendedCache,
|
|
29
31
|
>,
|
|
32
|
+
listeners: Arc<Mutex<Vec<OptionsWatcherListener>>>,
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
impl OptionsWatcher {
|
|
@@ -61,7 +64,7 @@ impl OptionsWatcher {
|
|
|
61
64
|
"[optify] Rebuilding OptionsProvider because contents at these path(s) changed: {paths:?}"
|
|
62
65
|
);
|
|
63
66
|
|
|
64
|
-
tx.send(
|
|
67
|
+
tx.send(paths).unwrap();
|
|
65
68
|
}
|
|
66
69
|
Err(errors) => errors
|
|
67
70
|
.iter()
|
|
@@ -88,14 +91,16 @@ impl OptionsWatcher {
|
|
|
88
91
|
last_modified,
|
|
89
92
|
watched_directories,
|
|
90
93
|
debouncer_watcher,
|
|
94
|
+
listeners: Arc::new(Mutex::new(Vec::new())),
|
|
91
95
|
};
|
|
92
96
|
|
|
93
97
|
let current_provider = self_.current_provider.clone();
|
|
94
98
|
let watched_directories = self_.watched_directories.clone();
|
|
95
99
|
let last_modified = self_.last_modified.clone();
|
|
100
|
+
let listeners = self_.listeners.clone();
|
|
96
101
|
|
|
97
102
|
std::thread::spawn(move || {
|
|
98
|
-
for
|
|
103
|
+
for paths in rx {
|
|
99
104
|
let result = std::panic::catch_unwind(|| {
|
|
100
105
|
let mut skip_rebuild = false;
|
|
101
106
|
let mut builder = OptionsProviderBuilder::new();
|
|
@@ -121,6 +126,10 @@ impl OptionsWatcher {
|
|
|
121
126
|
*provider = new_provider;
|
|
122
127
|
*last_modified.lock().unwrap() = std::time::SystemTime::now();
|
|
123
128
|
eprintln!("\x1b[32m[optify] Successfully rebuilt the OptionsProvider.\x1b[0m");
|
|
129
|
+
let listeners_guard = listeners.lock().unwrap();
|
|
130
|
+
for listener in listeners_guard.iter() {
|
|
131
|
+
listener(&paths);
|
|
132
|
+
}
|
|
124
133
|
}
|
|
125
134
|
Err(err) => {
|
|
126
135
|
eprintln!(
|
|
@@ -143,29 +152,30 @@ impl OptionsWatcher {
|
|
|
143
152
|
self_
|
|
144
153
|
}
|
|
145
154
|
|
|
146
|
-
pub fn
|
|
155
|
+
pub fn add_listener(&mut self, listener: OptionsWatcherListener) {
|
|
156
|
+
self.listeners.lock().unwrap().push(listener);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// Returns the time when the provider was finished building.
|
|
160
|
+
pub fn last_modified(&self) -> std::time::SystemTime {
|
|
161
|
+
*self.last_modified.lock().unwrap()
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
impl OptionsRegistry for OptionsWatcher {
|
|
166
|
+
fn build(directory: impl AsRef<Path>) -> Result<OptionsWatcher, String> {
|
|
147
167
|
let mut builder = OptionsWatcherBuilder::new();
|
|
148
|
-
builder.add_directory(directory)?;
|
|
168
|
+
builder.add_directory(directory.as_ref())?;
|
|
149
169
|
builder.build()
|
|
150
170
|
}
|
|
151
171
|
|
|
152
|
-
|
|
153
|
-
directories: &[impl AsRef<Path>],
|
|
154
|
-
) -> Result<OptionsWatcher, String> {
|
|
172
|
+
fn build_from_directories(directories: &[impl AsRef<Path>]) -> Result<OptionsWatcher, String> {
|
|
155
173
|
let mut builder = OptionsWatcherBuilder::new();
|
|
156
174
|
for directory in directories {
|
|
157
175
|
builder.add_directory(directory.as_ref())?;
|
|
158
176
|
}
|
|
159
177
|
builder.build()
|
|
160
178
|
}
|
|
161
|
-
|
|
162
|
-
/// Returns the time when the provider was finished building.
|
|
163
|
-
pub fn last_modified(&self) -> std::time::SystemTime {
|
|
164
|
-
*self.last_modified.lock().unwrap()
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
impl OptionsRegistry for OptionsWatcher {
|
|
169
179
|
fn get_aliases(&self) -> Vec<String> {
|
|
170
180
|
self.current_provider.read().unwrap().get_aliases()
|
|
171
181
|
}
|
|
@@ -32,6 +32,9 @@ pub struct OptionsMetadata {
|
|
|
32
32
|
///
|
|
33
33
|
/// For example, emails separated by ";".
|
|
34
34
|
pub owners: Option<String>,
|
|
35
|
+
|
|
36
|
+
/// The path to the file that contains the options.
|
|
37
|
+
pub path: Option<String>,
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
impl OptionsMetadata {
|
|
@@ -40,12 +43,14 @@ impl OptionsMetadata {
|
|
|
40
43
|
details: Option<Details>,
|
|
41
44
|
name: Option<String>,
|
|
42
45
|
owners: Option<String>,
|
|
46
|
+
path: Option<String>,
|
|
43
47
|
) -> Self {
|
|
44
48
|
Self {
|
|
45
49
|
aliases,
|
|
46
50
|
details,
|
|
47
51
|
name,
|
|
48
52
|
owners,
|
|
53
|
+
path,
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|