Skip to content

Commit 4b5ec6b

Browse files
AzrenbethAzrenbeth
Azrenbeth
authored and
Azrenbeth
committed
Add no-progress-bars feature so other packages can hide them
1 parent 3244bb9 commit 4b5ec6b

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ features = ["extension-module","abi3-py36"]
3232

3333
[features]
3434
default = ["jemalloc"]
35-
jemalloc = []
35+
jemalloc = []
36+
no-progress-bars = []

auto_compressor/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ postgres-openssl = "0.5.0"
1414
jemallocator = "0.3.2"
1515
rand = "0.8.0"
1616
serial_test = "0.5.1"
17-
synapse_compress_state = { path = "../" }
17+
synapse_compress_state = { path = "../", features = ["no-progress-bars"] }
1818
env_logger = { version = "0.9.0", git = "https://github.com/TilCreator/env_logger", branch = "fix_pipe" }
1919
log = "0.4.14"
2020
log-panics = "2.0.0"

compressor_integration_tests/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ openssl = "0.10.32"
1212
postgres = "0.19.0"
1313
postgres-openssl = "0.5.0"
1414
rand = "0.8.0"
15-
synapse_compress_state = { path = "../" }
15+
synapse_compress_state = { path = "../", features = ["no-progress-bars"] }
1616
auto_compressor = { path = "../auto_compressor/" }
1717
env_logger = "0.9.0"
1818
log = "0.4.14"

src/compressor.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ impl<'a> Compressor<'a> {
181181
panic!("Can only call `create_new_tree` once");
182182
}
183183

184-
let pb = ProgressBar::new(self.original_state_map.len() as u64);
184+
let pb: ProgressBar;
185+
if cfg!(feature = "no-progress-bars") {
186+
pb = ProgressBar::hidden();
187+
} else {
188+
pb = ProgressBar::new(self.original_state_map.len() as u64);
189+
}
185190
pb.set_style(
186191
ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"),
187192
);

src/database.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,12 @@ fn get_initial_data_from_db(
369369
// Copy the data from the database into a map
370370
let mut state_group_map: BTreeMap<i64, StateGroupEntry> = BTreeMap::new();
371371

372-
let pb = ProgressBar::new_spinner();
372+
let pb: ProgressBar;
373+
if cfg!(feature = "no-progress-bars") {
374+
pb = ProgressBar::hidden();
375+
} else {
376+
pb = ProgressBar::new_spinner();
377+
}
373378
pb.set_style(
374379
ProgressStyle::default_spinner().template("{spinner} [{elapsed}] {pos} rows retrieved"),
375380
);
@@ -529,7 +534,12 @@ pub fn send_changes_to_db(
529534
println!("Writing changes...");
530535

531536
// setup the progress bar
532-
let pb = ProgressBar::new(old_map.len() as u64);
537+
let pb: ProgressBar;
538+
if cfg!(feature = "no-progress-bars") {
539+
pb = ProgressBar::hidden();
540+
} else {
541+
pb = ProgressBar::new(old_map.len() as u64);
542+
}
533543
pb.set_style(
534544
ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"),
535545
);

src/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,12 @@ fn output_sql(
487487

488488
println!("Writing changes...");
489489

490-
let pb = ProgressBar::new(old_map.len() as u64);
490+
let pb: ProgressBar;
491+
if cfg!(feature = "no-progress-bars") {
492+
pb = ProgressBar::hidden();
493+
} else {
494+
pb = ProgressBar::new(old_map.len() as u64);
495+
}
491496
pb.set_style(
492497
ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"),
493498
);
@@ -597,7 +602,12 @@ fn check_that_maps_match(
597602
) {
598603
println!("Checking that state maps match...");
599604

600-
let pb = ProgressBar::new(old_map.len() as u64);
605+
let pb: ProgressBar;
606+
if cfg!(feature = "no-progress-bars") {
607+
pb = ProgressBar::hidden();
608+
} else {
609+
pb = ProgressBar::new(old_map.len() as u64);
610+
}
601611
pb.set_style(
602612
ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"),
603613
);

0 commit comments

Comments
 (0)