Skip to content

Commit b0f322e

Browse files
committed
more robust pdf generation on windows and adding a debug feature flag
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent a732160 commit b0f322e

File tree

8 files changed

+279
-248
lines changed

8 files changed

+279
-248
lines changed

.github/workflows/ci.yml

Lines changed: 8 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,10 @@ 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.*
189+
${{ github.workspace }}/plotly/plotly_example_surface.*
187190
retention-days: 30
188191

189192
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: 21 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,35 +1066,42 @@ 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");
1078+
#[cfg(feature = "debug")]
10781079
let mut exporter = plotly_static::StaticExporterBuilder::default()
1080+
.spawn_webdriver(true)
10791081
.webdriver_port(get_unique_port())
10801082
.pdf_export_timeout(750)
10811083
.build()
10821084
.unwrap();
1085+
#[cfg(not(feature = "debug"))]
1086+
let mut exporter = plotly_static::StaticExporterBuilder::default()
1087+
.webdriver_port(get_unique_port())
1088+
.build()
1089+
.unwrap();
10831090
plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::PDF, 1024, 680, 1.0)
10841091
.unwrap();
10851092
assert!(dst.exists());
10861093
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
10871094
let file_size = metadata.len();
10881095
assert!(file_size > 0,);
1096+
#[cfg(not(feature = "debug"))]
10891097
assert!(std::fs::remove_file(&dst).is_ok());
1090-
assert!(!dst.exists());
10911098
}
10921099

10931100
#[test]
10941101
#[cfg(feature = "plotly_static")]
10951102
fn save_to_webp() {
10961103
let plot = create_test_plot();
1097-
let dst = PathBuf::from("example.webp");
1104+
let dst = PathBuf::from("plotly_example.webp");
10981105
let mut exporter = plotly_static::StaticExporterBuilder::default()
10991106
.webdriver_port(get_unique_port())
11001107
.build()
@@ -1105,8 +1112,8 @@ mod tests {
11051112
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
11061113
let file_size = metadata.len();
11071114
assert!(file_size > 0,);
1115+
#[cfg(not(feature = "debug"))]
11081116
assert!(std::fs::remove_file(&dst).is_ok());
1109-
assert!(!dst.exists());
11101117
}
11111118

11121119
#[test]
@@ -1173,7 +1180,7 @@ mod tests {
11731180
.name("Surface");
11741181

11751182
plot.add_trace(surface);
1176-
let dst = PathBuf::from("example.png");
1183+
let dst = PathBuf::from("plotly_example_surface.png");
11771184
let mut exporter = plotly_static::StaticExporterBuilder::default()
11781185
.webdriver_port(get_unique_port())
11791186
.build()
@@ -1191,7 +1198,7 @@ mod tests {
11911198
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
11921199
let file_size = metadata.len();
11931200
assert!(file_size > 0,);
1201+
#[cfg(not(feature = "debug"))]
11941202
assert!(std::fs::remove_file(&dst).is_ok());
1195-
assert!(!dst.exists());
11961203
}
11971204
}

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"

0 commit comments

Comments
 (0)