Skip to content

Commit a749384

Browse files
committed
introduce new debug feature flag
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent 7535aba commit a749384

File tree

8 files changed

+55
-53
lines changed

8 files changed

+55
-53
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ jobs:
7676
include:
7777
- os: ubuntu-latest
7878
browser: chrome
79-
features: plotly_ndarray,plotly_image,static_export_default,ci
79+
features: plotly_ndarray,plotly_image,static_export_default,debug
8080
- os: ubuntu-latest
8181
browser: firefox
82-
features: plotly_ndarray,plotly_image,static_export_geckodriver,static_export_wd_download,ci
82+
features: plotly_ndarray,plotly_image,static_export_geckodriver,static_export_wd_download,debug
8383
- os: windows-latest
8484
browser: chrome
85-
features: plotly_ndarray,plotly_image,static_export_chromedriver,ci
85+
features: plotly_ndarray,plotly_image,static_export_chromedriver,debug
8686
- os: macos-latest
8787
browser: chrome
88-
features: plotly_ndarray,plotly_image,static_export_default,ci
88+
features: plotly_ndarray,plotly_image,static_export_default,debug
8989
runs-on: ${{ matrix.os }}
9090
timeout-minutes: ${{ matrix.os == 'windows-latest' && 30 || 10 }}
9191
steps:
@@ -183,7 +183,9 @@ jobs:
183183
uses: actions/upload-artifact@v4
184184
with:
185185
name: example-pdf-${{ matrix.os }}-${{ matrix.browser }}
186-
path: ${{ github.workspace }}/plotly_static/example.*
186+
path: |
187+
${{ github.workspace }}/plotly_static/static_example.*
188+
${{ github.workspace }}/plotly/plotly_example.*
187189
retention-days: 30
188190

189191
code-coverage:

examples/static_export/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use plotly::{Plot, Scatter};
44

55
fn main() -> Result<(), Box<dyn std::error::Error>> {
66
// Initialize logging for debugging and monitoring
7-
// Set RUST_LOG=debug to see detailed WebDriver operations
8-
env_logger::init();
7+
// Set log level to info by default
8+
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
99

1010
info!("Starting static export example...");
1111
info!("This example demonstrates efficient exporter reuse and multiple formats");

plotly/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ static_export_default = ["plotly_static", "plotly_static/chromedriver", "plotly_
2626

2727
# All non-conflicting features
2828
all = ["plotly_ndarray", "plotly_image", "plotly_embed_js", "static_export_default"]
29+
# This is used for enabling extra debugging messages and debugging functionality
30+
debug = ["plotly_static?/debug"]
2931

3032
plotly_ndarray = ["ndarray"]
3133
plotly_image = ["image"]

plotly/src/plot.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -997,11 +997,11 @@ mod tests {
997997
#[test]
998998
fn save_html() {
999999
let plot = create_test_plot();
1000-
let dst = PathBuf::from("example.html");
1000+
let dst = PathBuf::from("plotly_example.html");
10011001
plot.write_html(&dst);
10021002
assert!(dst.exists());
1003+
#[cfg(not(feature = "debug"))]
10031004
assert!(std::fs::remove_file(&dst).is_ok());
1004-
assert!(!dst.exists());
10051005
}
10061006

10071007
#[cfg(feature = "plotly_static")]
@@ -1017,7 +1017,7 @@ mod tests {
10171017
#[cfg(feature = "plotly_static")]
10181018
fn save_to_png() {
10191019
let plot = create_test_plot();
1020-
let dst = PathBuf::from("example.png");
1020+
let dst = PathBuf::from("plotly_example.png");
10211021
let mut exporter = plotly_static::StaticExporterBuilder::default()
10221022
.webdriver_port(get_unique_port())
10231023
.build()
@@ -1028,15 +1028,15 @@ mod tests {
10281028
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
10291029
let file_size = metadata.len();
10301030
assert!(file_size > 0,);
1031+
#[cfg(not(feature = "debug"))]
10311032
assert!(std::fs::remove_file(&dst).is_ok());
1032-
assert!(!dst.exists());
10331033
}
10341034

10351035
#[test]
10361036
#[cfg(feature = "plotly_static")]
10371037
fn save_to_jpeg() {
10381038
let plot = create_test_plot();
1039-
let dst = PathBuf::from("example.jpeg");
1039+
let dst = PathBuf::from("plotly_example.jpeg");
10401040
let mut exporter = plotly_static::StaticExporterBuilder::default()
10411041
.webdriver_port(get_unique_port())
10421042
.build()
@@ -1047,15 +1047,15 @@ mod tests {
10471047
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
10481048
let file_size = metadata.len();
10491049
assert!(file_size > 0,);
1050+
#[cfg(not(feature = "debug"))]
10501051
assert!(std::fs::remove_file(&dst).is_ok());
1051-
assert!(!dst.exists());
10521052
}
10531053

10541054
#[test]
10551055
#[cfg(feature = "plotly_static")]
10561056
fn save_to_svg() {
10571057
let plot = create_test_plot();
1058-
let dst = PathBuf::from("example.svg");
1058+
let dst = PathBuf::from("plotly_example.svg");
10591059
let mut exporter = plotly_static::StaticExporterBuilder::default()
10601060
.webdriver_port(get_unique_port())
10611061
.build()
@@ -1066,15 +1066,15 @@ mod tests {
10661066
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
10671067
let file_size = metadata.len();
10681068
assert!(file_size > 0,);
1069+
#[cfg(not(feature = "debug"))]
10691070
assert!(std::fs::remove_file(&dst).is_ok());
1070-
assert!(!dst.exists());
10711071
}
10721072

10731073
#[test]
10741074
#[cfg(feature = "plotly_static")]
10751075
fn save_to_pdf() {
10761076
let plot = create_test_plot();
1077-
let dst = PathBuf::from("example.pdf");
1077+
let dst = PathBuf::from("plotly_example.pdf");
10781078
let mut exporter = plotly_static::StaticExporterBuilder::default()
10791079
.webdriver_port(get_unique_port())
10801080
.pdf_export_timeout(750)
@@ -1086,15 +1086,15 @@ mod tests {
10861086
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
10871087
let file_size = metadata.len();
10881088
assert!(file_size > 0,);
1089+
#[cfg(not(feature = "debug"))]
10891090
assert!(std::fs::remove_file(&dst).is_ok());
1090-
assert!(!dst.exists());
10911091
}
10921092

10931093
#[test]
10941094
#[cfg(feature = "plotly_static")]
10951095
fn save_to_webp() {
10961096
let plot = create_test_plot();
1097-
let dst = PathBuf::from("example.webp");
1097+
let dst = PathBuf::from("plotly_example.webp");
10981098
let mut exporter = plotly_static::StaticExporterBuilder::default()
10991099
.webdriver_port(get_unique_port())
11001100
.build()
@@ -1105,8 +1105,8 @@ mod tests {
11051105
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
11061106
let file_size = metadata.len();
11071107
assert!(file_size > 0,);
1108+
#[cfg(not(feature = "debug"))]
11081109
assert!(std::fs::remove_file(&dst).is_ok());
1109-
assert!(!dst.exists());
11101110
}
11111111

11121112
#[test]
@@ -1173,7 +1173,7 @@ mod tests {
11731173
.name("Surface");
11741174

11751175
plot.add_trace(surface);
1176-
let dst = PathBuf::from("example.png");
1176+
let dst = PathBuf::from("plotly_example.png");
11771177
let mut exporter = plotly_static::StaticExporterBuilder::default()
11781178
.webdriver_port(get_unique_port())
11791179
.build()
@@ -1191,7 +1191,7 @@ mod tests {
11911191
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
11921192
let file_size = metadata.len();
11931193
assert!(file_size > 0,);
1194+
#[cfg(not(feature = "debug"))]
11941195
assert!(std::fs::remove_file(&dst).is_ok());
1195-
assert!(!dst.exists());
11961196
}
11971197
}

plotly_static/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ exclude = ["target/*"]
1616
webdriver_download = []
1717
geckodriver = []
1818
chromedriver = []
19-
# This is used for CI testing
20-
ci = []
19+
# This is used for enabling extra debugging messages and debugging functionality
20+
debug = []
2121

2222
[dependencies]
2323
log = "0.4"

plotly_static/src/lib.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ use std::fs::File;
263263
use std::io::prelude::*;
264264
use std::path::{Path, PathBuf};
265265
use std::vec;
266-
#[cfg(test)]
266+
#[cfg(any(test, feature = "debug"))]
267267
use std::{println as error, println as warn, println as debug};
268268

269269
use anyhow::{anyhow, Context, Result};
270270
use base64::{engine::general_purpose, Engine as _};
271271
use fantoccini::{wd::Capabilities, Client, ClientBuilder};
272-
#[cfg(not(test))]
272+
#[cfg(not(any(test, feature = "debug")))]
273273
use log::{debug, error, warn};
274274
use serde::Serialize;
275275
use serde_json::map::Map as JsonMap;
@@ -1216,15 +1216,15 @@ mod tests {
12161216
.webdriver_port(get_unique_port())
12171217
.build()
12181218
.unwrap();
1219-
let dst = PathBuf::from("example.png");
1219+
let dst = PathBuf::from("static_example.png");
12201220
export
12211221
.write_fig(dst.as_path(), &test_plot, ImageFormat::PNG, 1200, 900, 4.5)
12221222
.unwrap();
12231223
assert!(dst.exists());
12241224
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
12251225
let file_size = metadata.len();
12261226
assert!(file_size > 0,);
1227-
#[cfg(not(feature = "ci"))]
1227+
#[cfg(not(feature = "debug"))]
12281228
assert!(std::fs::remove_file(dst.as_path()).is_ok());
12291229
}
12301230

@@ -1237,15 +1237,15 @@ mod tests {
12371237
.webdriver_port(get_unique_port())
12381238
.build()
12391239
.unwrap();
1240-
let dst = PathBuf::from("example.jpeg");
1240+
let dst = PathBuf::from("static_example.jpeg");
12411241
export
12421242
.write_fig(dst.as_path(), &test_plot, ImageFormat::JPEG, 1200, 900, 4.5)
12431243
.unwrap();
12441244
assert!(dst.exists());
12451245
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
12461246
let file_size = metadata.len();
12471247
assert!(file_size > 0,);
1248-
#[cfg(not(feature = "ci"))]
1248+
#[cfg(not(feature = "debug"))]
12491249
assert!(std::fs::remove_file(dst.as_path()).is_ok());
12501250
}
12511251

@@ -1259,15 +1259,15 @@ mod tests {
12591259
.build()
12601260
.unwrap();
12611261

1262-
let dst = PathBuf::from("example.jpeg");
1262+
let dst = PathBuf::from("static_example.jpeg");
12631263
export
12641264
.write_fig(dst.as_path(), &test_plot, ImageFormat::JPEG, 1200, 900, 4.5)
12651265
.unwrap();
12661266
assert!(dst.exists());
12671267
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
12681268
let file_size = metadata.len();
12691269
assert!(file_size > 0,);
1270-
#[cfg(not(feature = "ci"))]
1270+
#[cfg(not(feature = "debug"))]
12711271
assert!(std::fs::remove_file(dst.as_path()).is_ok());
12721272

12731273
let dst = PathBuf::from("example2.jpeg");
@@ -1278,7 +1278,7 @@ mod tests {
12781278
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
12791279
let file_size = metadata.len();
12801280
assert!(file_size > 0,);
1281-
#[cfg(not(feature = "ci"))]
1281+
#[cfg(not(feature = "debug"))]
12821282
assert!(std::fs::remove_file(dst.as_path()).is_ok());
12831283
}
12841284

@@ -1291,15 +1291,15 @@ mod tests {
12911291
.webdriver_port(get_unique_port())
12921292
.build()
12931293
.unwrap();
1294-
let dst = PathBuf::from("example.svg");
1294+
let dst = PathBuf::from("static_example.svg");
12951295
export
12961296
.write_fig(dst.as_path(), &test_plot, ImageFormat::SVG, 1200, 900, 4.5)
12971297
.unwrap();
12981298
assert!(dst.exists());
12991299
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
13001300
let file_size = metadata.len();
13011301
assert!(file_size > 0,);
1302-
#[cfg(not(feature = "ci"))]
1302+
#[cfg(not(feature = "debug"))]
13031303
assert!(std::fs::remove_file(dst.as_path()).is_ok());
13041304
}
13051305

@@ -1312,46 +1312,46 @@ mod tests {
13121312
.webdriver_port(get_unique_port())
13131313
.build()
13141314
.unwrap();
1315-
let dst = PathBuf::from("example.webp");
1315+
let dst = PathBuf::from("static_example.webp");
13161316
export
13171317
.write_fig(dst.as_path(), &test_plot, ImageFormat::WEBP, 1200, 900, 4.5)
13181318
.unwrap();
13191319
assert!(dst.exists());
13201320
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
13211321
let file_size = metadata.len();
13221322
assert!(file_size > 0,);
1323-
#[cfg(not(feature = "ci"))]
1323+
#[cfg(not(feature = "debug"))]
13241324
assert!(std::fs::remove_file(dst.as_path()).is_ok());
13251325
}
13261326

13271327
#[test]
13281328
fn save_pdf() {
13291329
init();
13301330
let test_plot = create_test_plot();
1331-
#[cfg(feature = "ci")]
1331+
#[cfg(feature = "debug")]
13321332
let mut exporter = StaticExporterBuilder::default()
13331333
.spawn_webdriver(true)
13341334
.webdriver_port(get_unique_port())
13351335
.pdf_export_timeout(750)
13361336
.build()
13371337
.unwrap();
13381338

1339-
#[cfg(not(feature = "ci"))]
1339+
#[cfg(not(feature = "debug"))]
13401340
let mut exporter = StaticExporterBuilder::default()
13411341
.spawn_webdriver(true)
13421342
.webdriver_port(get_unique_port())
13431343
.build()
13441344
.unwrap();
13451345

1346-
let dst = PathBuf::from("example.pdf");
1346+
let dst = PathBuf::from("static_example.pdf");
13471347
exporter
13481348
.write_fig(dst.as_path(), &test_plot, ImageFormat::PDF, 1200, 900, 4.5)
13491349
.unwrap();
13501350
assert!(dst.exists());
13511351
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
13521352
let file_size = metadata.len();
13531353
assert!(file_size > 600000,);
1354-
#[cfg(not(feature = "ci"))]
1354+
#[cfg(not(feature = "debug"))]
13551355
assert!(std::fs::remove_file(dst.as_path()).is_ok());
13561356
}
13571357

@@ -1379,7 +1379,7 @@ mod tests {
13791379
.write_fig(dst1.as_path(), &test_plot, ImageFormat::PNG, 800, 600, 1.0)
13801380
.unwrap();
13811381
assert!(dst1.exists());
1382-
#[cfg(not(feature = "ci"))]
1382+
#[cfg(not(feature = "debug"))]
13831383
assert!(std::fs::remove_file(dst1.as_path()).is_ok());
13841384

13851385
// Create second exporter on the same port - this should connect to existing
@@ -1396,7 +1396,7 @@ mod tests {
13961396
.write_fig(dst2.as_path(), &test_plot, ImageFormat::PNG, 800, 600, 1.0)
13971397
.unwrap();
13981398
assert!(dst2.exists());
1399-
#[cfg(not(feature = "ci"))]
1399+
#[cfg(not(feature = "debug"))]
14001400
assert!(std::fs::remove_file(dst2.as_path()).is_ok());
14011401

14021402
// Create third exporter on the same port - should also connect to existing
@@ -1413,7 +1413,7 @@ mod tests {
14131413
.write_fig(dst3.as_path(), &test_plot, ImageFormat::PNG, 800, 600, 1.0)
14141414
.unwrap();
14151415
assert!(dst3.exists());
1416-
#[cfg(not(feature = "ci"))]
1416+
#[cfg(not(feature = "debug"))]
14171417
assert!(std::fs::remove_file(dst3.as_path()).is_ok());
14181418
}
14191419
}

plotly_static/src/template.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::fs::File;
22
use std::io::Write;
33
use std::path::PathBuf;
4-
#[cfg(test)]
4+
#[cfg(any(test, feature = "debug"))]
55
use std::println as debug;
66

77
use anyhow::{Context, Result};
8-
#[cfg(not(test))]
9-
use log::{debug, log_enabled, Level::Debug};
8+
#[cfg(not(any(test, feature = "debug")))]
9+
use log::debug;
1010
use rand::{
1111
distr::{Alphanumeric, SampleString},
1212
rng,
@@ -224,11 +224,9 @@ pub(crate) fn html_body(js_source: &str) -> String {
224224
</html>"#
225225
);
226226

227-
#[cfg(not(test))]
228-
if log_enabled!(Debug) {
229-
if let Err(e) = to_file(&html) {
230-
debug!("Failed to save HTML to file: {e}");
231-
}
227+
#[cfg(any(test, feature = "debug"))]
228+
if let Err(e) = to_file(&html) {
229+
debug!("Failed to save HTML to file: {e}");
232230
}
233231

234232
html

0 commit comments

Comments
 (0)