Skip to content

#241 Add macOS-specific fixes and tests for Kaleido compatibility #289

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

Conversation

joaquinbejar
Copy link
Contributor

Hi 👋,

This PR fixes #241 by omitting --disable-gpu on macOS + arm64.

spec.json:

{"format":"png","width":800,"height":600,"scale":1.0,"data":{"config":{},"data":[{"name":"Surface","type":"surface","x":[1.0,2.0,3.0],"y":[4.0,5.0,6.0],"z":[[1.0,2.0,3.0],[4.0,5.0,6.0],[7.0,8.0,9.0]]}],"layout":{}}}
cat spec.json | ./kaleido plotly \
--disable-gpu \
--allow-file-access-from-files \
--disable-breakpad \
--disable-dev-shm-usage \
--disable-software-rasterizer \
--single-process \
--no-sandbox \
> out.b64
cat out.b64
{"code": 0, "message": "Success", "result": null, "version": "0.2.1"}
{"code":525,"message":"error creating static canvas/context for image server","pdfBgColor":null,"format":"png","result":null,"width":800,"height":600,"scale":1}

so we never get any image data. The fix is still to omit --disable-gpu, but I wanted to be precise in the description.

What the patch changes

// non‑macOS keeps the original flag set
#[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",
];

// macOS (Intel **and** Apple Silicon) – drop `--disable-gpu`
#[cfg(target_os = "macos")]
let cmd_args = vec![
    "plotly",
    "--allow-file-access-from-files",
    "--disable-breakpad",
    "--disable-dev-shm-usage",
    "--disable-software-rasterizer",
    "--single-process",
    "--no-sandbox",
];
  • Only the --disable-gpu flag is removed on macOS; everything else remains untouched.
  • Tested on M1, M2 Pro and M4 Max – write_image now succeeds and the tests pass.
  • Behaviour on Linux and Windows is unchanged.

Link to upstream discussion

plotly/Kaleido#323

Let me know if you’d prefer the macOS check to be target_arch = "aarch64" only (i.e. keep the flag for Intel Macs). Happy to adjust!

— Joaquín

Introduce macOS-specific arguments for Kaleido to address issue #323. Add new tests to validate image generation (e.g., PNG, JPEG, SVG, PDF) on macOS, ensuring proper functionality. This improves cross-platform support and resolves inconsistencies in the Kaleido backend.

issue: plotly#241
Cleaned up unnecessary blank lines and adjusted minor formatting issues to improve code readability and maintain consistency. No functional changes were made.
Introduced a macOS-specific `create_test_surface` function in `plotly_kaleido` and adjusted test-related imports in `plotly`. Ensures compatibility with macOS while keeping non-macOS logic intact.
Reorganized and added conditional imports to improve clarity and maintain consistent functionality across platforms. This ensures the required dependencies are properly included, particularly handling the macOS-specific conditions.
Reorganized imports in the tests module to improve clarity and maintain consistency. Non-standard library imports are now grouped separately, following a logical and readable structure.
@andrei-ng
Copy link
Collaborator

Hi @joaquinbejar ,

Thank you for the PR! Interesting find!

Let me know if you’d prefer the macOS check to be target_arch = "aarch64" only (i.e. keep the flag for Intel Macs). Happy to adjust!

target_os = "macos" is fine for now. If there will be issues, we will change it later.

I have only one commet regarding the PR. I see that you have added new unittests. Any particular reason why you chose to do that and not reuse the existing ones? Do you mind if I merge your tests with the previous ones ( I see you have added some nice extra asserts)?

@joaquinbejar
Copy link
Contributor Author

joaquinbejar commented May 12, 2025

HI @andrei-ng

Sure, that makes sense!

I added the new tests because the failure reliably showed up with a Surface trace, while the existing tests use only Scatter. I wanted to prove the fix on the exact setup that was breaking.

Feel totally free to merge my extra assertions into the existing test file (or replace it entirely) — I just separated them to keep the repro crystal-clear. Thanks for the review!

@andrei-ng
Copy link
Collaborator

HI @andrei-ng

Sure, that makes sense!

I added the new tests because the failure reliably showed up with a Surface trace, while the existing tests use only Scatter. I wanted to prove the fix on the exact setup that was breaking.

Feel totally free to merge my extra assertions into the existing test file (or replace it entirely) — I just separated them to keep the repro crystal-clear. Thanks for the review!

OK, understood. Thank you for clarifying! I will remove the old unittests in favour of yours and merge it afterwards.

@andrei-ng andrei-ng merged commit a7ac37d into plotly:main May 12, 2025
17 of 19 checks passed
andrei-ng added a commit that referenced this pull request May 12, 2025
 - keep only the kaleido unittests added in PR #289 in favor of previous ones

Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
andrei-ng added a commit that referenced this pull request May 12, 2025
 - keep only the kaleido unittests added in PR #289 in favor of previous ones

Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
andrei-ng added a commit that referenced this pull request May 12, 2025
- keep only the kaleido unittests added in PR #289 in favor of previous ones

Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants