Skip to content

Commit 9a47e4e

Browse files
committed
try macos kaleido
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent 45c1b05 commit 9a47e4e

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

examples/kaleido/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ edition = "2021"
99

1010
[dependencies]
1111
plotly = { path = "../../plotly", features = ["kaleido", "kaleido_fetch"] }
12-
# plotly = { path = "../../plotly", features = ["kaleido"] }

plotly/src/plot.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ impl PartialEq for Plot {
585585
mod tests {
586586
use std::path::PathBuf;
587587

588+
use base64::{engine::general_purpose, Engine as _};
588589
use serde_json::{json, to_value};
589590

590591
use super::*;
@@ -748,7 +749,7 @@ mod tests {
748749
assert!(!dst.exists());
749750
}
750751

751-
#[cfg(target_os = "linux")]
752+
// #[cfg(not(target_os = "macos"))]
752753
#[test]
753754
#[cfg(feature = "kaleido")]
754755
fn test_save_to_png() {
@@ -760,19 +761,21 @@ mod tests {
760761
assert!(!dst.exists());
761762
}
762763

763-
#[cfg(target_os = "linux")]
764+
// #[cfg(not(target_os = "macos"))]
764765
#[test]
765766
#[cfg(feature = "kaleido")]
766767
fn test_save_to_jpeg() {
767768
let plot = create_test_plot();
768769
let dst = PathBuf::from("example.jpeg");
769770
plot.write_image(&dst, ImageFormat::JPEG, 1024, 680, 1.0);
770-
assert!(dst.exists());
771+
let imgSize = std::fs::metadata("example.jpeg").unwrap().len();
772+
dbg!(imgSize);
773+
assert!(!dst.exists());
771774
assert!(std::fs::remove_file(&dst).is_ok());
772775
assert!(!dst.exists());
773776
}
774777

775-
#[cfg(target_os = "linux")]
778+
// #[cfg(not(target_os = "macos"))]
776779
#[test]
777780
#[cfg(feature = "kaleido")]
778781
fn test_save_to_svg() {
@@ -796,7 +799,7 @@ mod tests {
796799
assert!(!dst.exists());
797800
}
798801

799-
#[cfg(target_os = "linux")]
802+
// #[cfg(not(target_os = "macos"))]
800803
#[test]
801804
#[cfg(feature = "kaleido")]
802805
fn test_save_to_pdf() {
@@ -820,16 +823,18 @@ mod tests {
820823
assert!(!dst.exists());
821824
}
822825

823-
#[cfg(target_os = "linux")]
824826
#[test]
827+
// #[ignore] // Fails in the CI
828+
// #[cfg(not(target_os = "macos"))]
825829
#[cfg(feature = "kaleido")]
826830
fn test_image_to_base64() {
827-
use base64::engine::general_purpose;
828-
use base64::Engine;
829831
let plot = create_test_plot();
830832

831833
let image_base64 = plot.to_base64(ImageFormat::PNG, 200, 150, 1.0);
832834

835+
std::thread::sleep(std::time::Duration::from_secs(2));
836+
837+
dbg!(&image_base64);
833838
assert!(!image_base64.is_empty());
834839

835840
let result_decoded = general_purpose::STANDARD.decode(image_base64).unwrap();
@@ -850,13 +855,17 @@ mod tests {
850855
assert!(image_base64.is_empty());
851856
}
852857

853-
#[cfg(target_os = "linux")]
854858
#[test]
859+
// #[ignore] // Fails in the CI
860+
// #[cfg(not(target_os = "macos"))]
855861
#[cfg(feature = "kaleido")]
856862
fn test_image_to_svg_string() {
857863
let plot = create_test_plot();
858864
let image_svg = plot.to_svg(200, 150, 1.0);
859865

866+
std::thread::sleep(std::time::Duration::from_secs(2));
867+
dbg!(&image_svg);
868+
860869
assert!(!image_svg.is_empty());
861870

862871
let expected = "<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"150\" style=\"\" viewBox=\"0 0 200 150\"><rect x=\"0\" y=\"0\" width=\"200\" height=\"150\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-2dc70a\"><g class=\"clips\"><clipPath id=\"clip2dc70axyplot\" class=\"plotclip\"><rect width=\"40\" height=\"2\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70ax\"><rect x=\"80\" y=\"0\" width=\"40\" height=\"150\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70ay\"><rect x=\"0\" y=\"82\" width=\"200\" height=\"2\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70axy\"><rect x=\"80\" y=\"82\" width=\"40\" height=\"2\"/></clipPath></g><g class=\"gradients\"/></defs><g class=\"bglayer\"/><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(100,0)\" d=\"M0,82v2\" style=\"stroke: rgb(238, 238, 238); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(114.25,0)\" d=\"M0,82v2\" style=\"stroke: rgb(238, 238, 238); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"/></g><g class=\"zerolinelayer\"><path class=\"xzl zl crisp\" transform=\"translate(85.75,0)\" d=\"M0,82v2\" style=\"stroke: rgb(68, 68, 68); stroke-opacity: 1; stroke-width: 1px;\"/></g><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(80,82)\" clip-path=\"url('#clip2dc70axyplot')\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter trace86f735\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M5.75,1L20,0L34.25,2\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke: rgb(31, 119, 180); stroke-opacity: 1; stroke-width: 2px; opacity: 1;\"/></g><g class=\"points\"><path class=\"point\" transform=\"translate(5.75,1)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(20,0)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(34.25,2)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g><g class=\"text\"/></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(85.75,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">0</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(100,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">1</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(114.25,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">2</text></g></g><g class=\"yaxislayer-above\"><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,84)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">2</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,83.5)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">4</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,83)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">6</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,82.5)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">8</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,82)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">10</text></g></g><g class=\"overaxes-above\"/></g></g><g class=\"polarlayer\"/><g class=\"ternarylayer\"/><g class=\"geolayer\"/><g class=\"funnelarealayer\"/><g class=\"pielayer\"/><g class=\"treemaplayer\"/><g class=\"sunburstlayer\"/><g class=\"glimages\"/><defs id=\"topdefs-2dc70a\"><g class=\"clips\"/></defs><g class=\"layer-above\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"infolayer\"><g class=\"g-gtitle\"/><g class=\"g-xtitle\"/><g class=\"g-ytitle\"/></g></svg>";

plotly_kaleido/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ fn main() -> Result<()> {
141141

142142
extract_zip(&dst, &kaleido_zip_file)?;
143143
} else {
144-
println!("'download' feature disabled. Kaleido binary won't be downloaded and must be installed manually.")
144+
let msg = format!("'download' feature disabled. Please install Kaleido manually and make the environment variable 'KALEIDO_PATH' point to it.");
145+
println!("cargo::warning={msg}");
145146
}
146147
Ok(())
147148
}

plotly_kaleido/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ impl Kaleido {
197197
"--disable-dev-shm-usage",
198198
"--disable-software-rasterizer",
199199
"--single-process",
200+
"--disable-gpu",
201+
"--timeout 2000",
200202
])
201203
.stdin(Stdio::piped())
202204
.stdout(Stdio::piped())
@@ -297,7 +299,7 @@ mod tests {
297299
}
298300

299301
// This seems to fail unpredictably on MacOs.
300-
#[cfg(target_os = "linux")]
302+
#[cfg(not(target_os = "macos"))]
301303
#[test]
302304
fn test_save_png() {
303305
let test_plot = create_test_plot();
@@ -309,7 +311,7 @@ mod tests {
309311
}
310312

311313
// This seems to fail unpredictably on MacOs.
312-
#[cfg(target_os = "linux")]
314+
#[cfg(not(target_os = "macos"))]
313315
#[test]
314316
fn test_save_jpeg() {
315317
let test_plot = create_test_plot();
@@ -321,7 +323,7 @@ mod tests {
321323
}
322324

323325
// This seems to fail unpredictably on MacOs.
324-
#[cfg(target_os = "linux")]
326+
#[cfg(not(target_os = "macos"))]
325327
#[test]
326328
fn test_save_webp() {
327329
let test_plot = create_test_plot();
@@ -333,7 +335,7 @@ mod tests {
333335
}
334336

335337
// This seems to fail unpredictably on MacOs.
336-
#[cfg(target_os = "linux")]
338+
#[cfg(not(target_os = "macos"))]
337339
#[test]
338340
fn test_save_svg() {
339341
let test_plot = create_test_plot();
@@ -345,7 +347,7 @@ mod tests {
345347
}
346348

347349
// This seems to fail unpredictably on MacOs.
348-
#[cfg(target_os = "linux")]
350+
#[cfg(not(target_os = "macos"))]
349351
#[test]
350352
fn test_save_pdf() {
351353
let test_plot = create_test_plot();

0 commit comments

Comments
 (0)