Skip to content

remove disable-gpu flag for all targets #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ All notable changes to this project will be documented in this file.

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).

## [0.13.0] - 2025-03-xx
## [0.13.0] - 2025-xx-xx
### Changed
- [[#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.
- [[#281]((https://github.com/plotly/plotly.rs/pull/xxx))] Update to askama 0.13.0
- [[#289]](https://github.com/plotly/plotly.rs/pull/289) Fixes Kaleido static export for MacOS targets by removing `--disable-gpu` flag for MacOS
- [[#290]](https://github.com/plotly/plotly.rs/pull/289) Remove `--disable-gpu` flag for Kaleido static-image generation for all targets.

### Fixed
- [[#284](https://github.com/plotly/plotly.rs/pull/284)] Allow plotly package to be compiled for android
Expand Down
2 changes: 1 addition & 1 deletion plotly/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ mod tests {
use std::path::PathBuf;

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

use super::*;
Expand Down
151 changes: 24 additions & 127 deletions plotly_kaleido/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,8 @@ impl Kaleido {
) -> Result<String, Box<dyn std::error::Error>> {
let p = self.cmd_path.to_str().unwrap();

#[cfg(not(target_os = "macos"))]
let cmd_args = vec![
"plotly",
"--disable-gpu",
"--allow-file-access-from-files",
"--disable-breakpad",
"--disable-dev-shm-usage",
"--disable-software-rasterizer",
"--single-process",
"--no-sandbox",
];

// Add Kaleido issue #323
#[cfg(target_os = "macos")]
// Removed flag 'disable-gpu' as it causes issues on MacOS and other platforms
// see Kaleido issue #323
let cmd_args = vec![
"plotly",
"--allow-file-access-from-files",
Expand Down Expand Up @@ -272,36 +260,6 @@ mod tests {
use super::*;

fn create_test_plot() -> Value {
to_value(json!({
"data": [
{
"type": "scatter",
"x": [1, 2, 3, 4],
"y": [10, 15, 13, 17],
"name": "trace1",
"mode": "markers"
},
{
"type": "scatter",
"x": [2, 3, 4, 5],
"y": [16, 5, 11, 9],
"name": "trace2",
"mode": "lines"
},
{
"type": "scatter",
"x": [1, 2, 3, 4],
"y": [12, 9, 15, 12],
"name": "trace3",
}
],
"layout": {}
}))
.unwrap()
}

#[cfg(target_os = "macos")]
fn create_test_surface() -> Value {
to_value(json!({
"data": [
{
Expand Down Expand Up @@ -361,67 +319,78 @@ mod tests {
assert_eq!(to_value(kaleido_data).unwrap(), expected);
}

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

// This seems to fail unpredictably on MacOs.
#[cfg(not(target_os = "macos"))]
#[test]
fn save_jpeg() {
let test_plot = create_test_plot();
let k = Kaleido::new();
let dst = PathBuf::from("example.jpeg");
let r = k.save(dst.as_path(), &test_plot, "jpeg", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}

// This seems to fail unpredictably on MacOs.
#[cfg(not(target_os = "macos"))]
#[test]
fn save_webp() {
let test_plot = create_test_plot();
let k = Kaleido::new();
let dst = PathBuf::from("example.webp");
let r = k.save(dst.as_path(), &test_plot, "webp", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}

// This seems to fail unpredictably on MacOs.
#[cfg(not(target_os = "macos"))]
#[test]
fn save_svg() {
let test_plot = create_test_plot();
let k = Kaleido::new();
let dst = PathBuf::from("example.svg");
let r = k.save(dst.as_path(), &test_plot, "svg", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}

// This seems to fail unpredictably on MacOs.
#[cfg(not(target_os = "macos"))]
#[test]
fn save_pdf() {
let test_plot = create_test_plot();
let k = Kaleido::new();
let dst = PathBuf::from("example.pdf");
let r = k.save(dst.as_path(), &test_plot, "pdf", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}

// This generates empty eps files for some reason
// Kaleido generates empty eps files
#[test]
#[ignore]
fn save_eps() {
Expand All @@ -432,76 +401,4 @@ mod tests {
assert!(r.is_ok());
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}

// Issue #241 workaround until https://github.com/plotly/Kaleido/issues/323 is resolved
#[cfg(target_os = "macos")]
#[test]
fn save_surface_png() {
let test_plot = create_test_surface();
let k = Kaleido::new();
let dst = PathBuf::from("example.png");
let r = k.save(dst.as_path(), &test_plot, "png", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}
#[cfg(target_os = "macos")]
#[test]
fn save_surface_jpeg() {
let test_plot = create_test_surface();
let k = Kaleido::new();
let dst = PathBuf::from("example.jpeg");
let r = k.save(dst.as_path(), &test_plot, "jpeg", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}
#[cfg(target_os = "macos")]
#[test]
fn save_surface_webp() {
let test_plot = create_test_surface();
let k = Kaleido::new();
let dst = PathBuf::from("example.webp");
let r = k.save(dst.as_path(), &test_plot, "webp", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}
#[cfg(target_os = "macos")]
#[test]
fn save_surface_svg() {
let test_plot = create_test_surface();
let k = Kaleido::new();
let dst = PathBuf::from("example.svg");
let r = k.save(dst.as_path(), &test_plot, "svg", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}
#[cfg(target_os = "macos")]
#[test]
fn save_surface_pdf() {
let test_plot = create_test_surface();
let k = Kaleido::new();
let dst = PathBuf::from("example.pdf");
let r = k.save(dst.as_path(), &test_plot, "pdf", 1200, 900, 4.5);
assert!(r.is_ok());
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
let file_size = metadata.len();
assert!(file_size > 0,);
assert!(std::fs::remove_file(dst.as_path()).is_ok());
}
}
Loading