Skip to content

Commit 1ecb8ac

Browse files
authored
remove disable-gpu flag for all targets (#291)
- keep only the kaleido unittests added in PR #289 in favor of previous ones Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent a7ac37d commit 1ecb8ac

File tree

3 files changed

+28
-129
lines changed

3 files changed

+28
-129
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6-
## [0.13.0] - 2025-03-xx
6+
## [0.13.0] - 2025-xx-xx
77
### Changed
88
- [[#277](https://github.com/plotly/plotly.rs/pull/277)] Removed `wasm` feature flag and put evrything behind target specific dependencies. Added `.cargo/config.toml` for configuration flags needed by `getrandom` version 0.3 on `wasm` targets.
99
- [[#281]((https://github.com/plotly/plotly.rs/pull/xxx))] Update to askama 0.13.0
10+
- [[#289]](https://github.com/plotly/plotly.rs/pull/289) Fixes Kaleido static export for MacOS targets by removing `--disable-gpu` flag for MacOS
11+
- [[#290]](https://github.com/plotly/plotly.rs/pull/289) Remove `--disable-gpu` flag for Kaleido static-image generation for all targets.
1012

1113
### Fixed
1214
- [[#284](https://github.com/plotly/plotly.rs/pull/284)] Allow plotly package to be compiled for android

plotly/src/plot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ mod tests {
587587
use std::path::PathBuf;
588588

589589
use serde_json::{json, to_value};
590-
#[cfg(not(target_os = "macos"))]
590+
#[cfg(feature = "kaleido")]
591591
use {base64::engine::general_purpose, base64::Engine};
592592

593593
use super::*;

plotly_kaleido/src/lib.rs

Lines changed: 24 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,8 @@ impl Kaleido {
185185
) -> Result<String, Box<dyn std::error::Error>> {
186186
let p = self.cmd_path.to_str().unwrap();
187187

188-
#[cfg(not(target_os = "macos"))]
189-
let cmd_args = vec![
190-
"plotly",
191-
"--disable-gpu",
192-
"--allow-file-access-from-files",
193-
"--disable-breakpad",
194-
"--disable-dev-shm-usage",
195-
"--disable-software-rasterizer",
196-
"--single-process",
197-
"--no-sandbox",
198-
];
199-
200-
// Add Kaleido issue #323
201-
#[cfg(target_os = "macos")]
188+
// Removed flag 'disable-gpu' as it causes issues on MacOS and other platforms
189+
// see Kaleido issue #323
202190
let cmd_args = vec![
203191
"plotly",
204192
"--allow-file-access-from-files",
@@ -272,36 +260,6 @@ mod tests {
272260
use super::*;
273261

274262
fn create_test_plot() -> Value {
275-
to_value(json!({
276-
"data": [
277-
{
278-
"type": "scatter",
279-
"x": [1, 2, 3, 4],
280-
"y": [10, 15, 13, 17],
281-
"name": "trace1",
282-
"mode": "markers"
283-
},
284-
{
285-
"type": "scatter",
286-
"x": [2, 3, 4, 5],
287-
"y": [16, 5, 11, 9],
288-
"name": "trace2",
289-
"mode": "lines"
290-
},
291-
{
292-
"type": "scatter",
293-
"x": [1, 2, 3, 4],
294-
"y": [12, 9, 15, 12],
295-
"name": "trace3",
296-
}
297-
],
298-
"layout": {}
299-
}))
300-
.unwrap()
301-
}
302-
303-
#[cfg(target_os = "macos")]
304-
fn create_test_surface() -> Value {
305263
to_value(json!({
306264
"data": [
307265
{
@@ -361,67 +319,78 @@ mod tests {
361319
assert_eq!(to_value(kaleido_data).unwrap(), expected);
362320
}
363321

364-
// This seems to fail unpredictably on MacOs.
365-
#[cfg(not(target_os = "macos"))]
322+
// For MacOS failures, see issue #241 and upstream https://github.com/plotly/Kaleido/issues/323 is resolved
366323
#[test]
367324
fn save_png() {
368325
let test_plot = create_test_plot();
369326
let k = Kaleido::new();
370327
let dst = PathBuf::from("example.png");
371328
let r = k.save(dst.as_path(), &test_plot, "png", 1200, 900, 4.5);
372329
assert!(r.is_ok());
330+
assert!(dst.exists());
331+
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
332+
let file_size = metadata.len();
333+
assert!(file_size > 0,);
373334
assert!(std::fs::remove_file(dst.as_path()).is_ok());
374335
}
375336

376-
// This seems to fail unpredictably on MacOs.
377-
#[cfg(not(target_os = "macos"))]
378337
#[test]
379338
fn save_jpeg() {
380339
let test_plot = create_test_plot();
381340
let k = Kaleido::new();
382341
let dst = PathBuf::from("example.jpeg");
383342
let r = k.save(dst.as_path(), &test_plot, "jpeg", 1200, 900, 4.5);
384343
assert!(r.is_ok());
344+
assert!(dst.exists());
345+
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
346+
let file_size = metadata.len();
347+
assert!(file_size > 0,);
385348
assert!(std::fs::remove_file(dst.as_path()).is_ok());
386349
}
387350

388-
// This seems to fail unpredictably on MacOs.
389-
#[cfg(not(target_os = "macos"))]
390351
#[test]
391352
fn save_webp() {
392353
let test_plot = create_test_plot();
393354
let k = Kaleido::new();
394355
let dst = PathBuf::from("example.webp");
395356
let r = k.save(dst.as_path(), &test_plot, "webp", 1200, 900, 4.5);
396357
assert!(r.is_ok());
358+
assert!(dst.exists());
359+
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
360+
let file_size = metadata.len();
361+
assert!(file_size > 0,);
397362
assert!(std::fs::remove_file(dst.as_path()).is_ok());
398363
}
399364

400-
// This seems to fail unpredictably on MacOs.
401-
#[cfg(not(target_os = "macos"))]
402365
#[test]
403366
fn save_svg() {
404367
let test_plot = create_test_plot();
405368
let k = Kaleido::new();
406369
let dst = PathBuf::from("example.svg");
407370
let r = k.save(dst.as_path(), &test_plot, "svg", 1200, 900, 4.5);
408371
assert!(r.is_ok());
372+
assert!(dst.exists());
373+
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
374+
let file_size = metadata.len();
375+
assert!(file_size > 0,);
409376
assert!(std::fs::remove_file(dst.as_path()).is_ok());
410377
}
411378

412-
// This seems to fail unpredictably on MacOs.
413-
#[cfg(not(target_os = "macos"))]
414379
#[test]
415380
fn save_pdf() {
416381
let test_plot = create_test_plot();
417382
let k = Kaleido::new();
418383
let dst = PathBuf::from("example.pdf");
419384
let r = k.save(dst.as_path(), &test_plot, "pdf", 1200, 900, 4.5);
420385
assert!(r.is_ok());
386+
assert!(dst.exists());
387+
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
388+
let file_size = metadata.len();
389+
assert!(file_size > 0,);
421390
assert!(std::fs::remove_file(dst.as_path()).is_ok());
422391
}
423392

424-
// This generates empty eps files for some reason
393+
// Kaleido generates empty eps files
425394
#[test]
426395
#[ignore]
427396
fn save_eps() {
@@ -432,76 +401,4 @@ mod tests {
432401
assert!(r.is_ok());
433402
assert!(std::fs::remove_file(dst.as_path()).is_ok());
434403
}
435-
436-
// Issue #241 workaround until https://github.com/plotly/Kaleido/issues/323 is resolved
437-
#[cfg(target_os = "macos")]
438-
#[test]
439-
fn save_surface_png() {
440-
let test_plot = create_test_surface();
441-
let k = Kaleido::new();
442-
let dst = PathBuf::from("example.png");
443-
let r = k.save(dst.as_path(), &test_plot, "png", 1200, 900, 4.5);
444-
assert!(r.is_ok());
445-
assert!(dst.exists());
446-
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
447-
let file_size = metadata.len();
448-
assert!(file_size > 0,);
449-
assert!(std::fs::remove_file(dst.as_path()).is_ok());
450-
}
451-
#[cfg(target_os = "macos")]
452-
#[test]
453-
fn save_surface_jpeg() {
454-
let test_plot = create_test_surface();
455-
let k = Kaleido::new();
456-
let dst = PathBuf::from("example.jpeg");
457-
let r = k.save(dst.as_path(), &test_plot, "jpeg", 1200, 900, 4.5);
458-
assert!(r.is_ok());
459-
assert!(dst.exists());
460-
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
461-
let file_size = metadata.len();
462-
assert!(file_size > 0,);
463-
assert!(std::fs::remove_file(dst.as_path()).is_ok());
464-
}
465-
#[cfg(target_os = "macos")]
466-
#[test]
467-
fn save_surface_webp() {
468-
let test_plot = create_test_surface();
469-
let k = Kaleido::new();
470-
let dst = PathBuf::from("example.webp");
471-
let r = k.save(dst.as_path(), &test_plot, "webp", 1200, 900, 4.5);
472-
assert!(r.is_ok());
473-
assert!(dst.exists());
474-
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
475-
let file_size = metadata.len();
476-
assert!(file_size > 0,);
477-
assert!(std::fs::remove_file(dst.as_path()).is_ok());
478-
}
479-
#[cfg(target_os = "macos")]
480-
#[test]
481-
fn save_surface_svg() {
482-
let test_plot = create_test_surface();
483-
let k = Kaleido::new();
484-
let dst = PathBuf::from("example.svg");
485-
let r = k.save(dst.as_path(), &test_plot, "svg", 1200, 900, 4.5);
486-
assert!(r.is_ok());
487-
assert!(dst.exists());
488-
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
489-
let file_size = metadata.len();
490-
assert!(file_size > 0,);
491-
assert!(std::fs::remove_file(dst.as_path()).is_ok());
492-
}
493-
#[cfg(target_os = "macos")]
494-
#[test]
495-
fn save_surface_pdf() {
496-
let test_plot = create_test_surface();
497-
let k = Kaleido::new();
498-
let dst = PathBuf::from("example.pdf");
499-
let r = k.save(dst.as_path(), &test_plot, "pdf", 1200, 900, 4.5);
500-
assert!(r.is_ok());
501-
assert!(dst.exists());
502-
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
503-
let file_size = metadata.len();
504-
assert!(file_size > 0,);
505-
assert!(std::fs::remove_file(dst.as_path()).is_ok());
506-
}
507404
}

0 commit comments

Comments
 (0)