From bf3933ec5140c1409a0cf5a2c37129cfd7a29f0c Mon Sep 17 00:00:00 2001 From: Alberto Mengali Date: Fri, 3 Jan 2025 13:56:01 +0100 Subject: [PATCH 1/5] ship kaleido v0.1 as own artifact on windows --- Artifacts.toml | 16 ++++++++++++++++ Project.toml | 6 ++++-- src/PlotlyKaleido.jl | 24 ++++++++++++++++++++++-- test/runtests.jl | 14 ++------------ 4 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 Artifacts.toml diff --git a/Artifacts.toml b/Artifacts.toml new file mode 100644 index 0000000..8de5937 --- /dev/null +++ b/Artifacts.toml @@ -0,0 +1,16 @@ +[[Kaleido_fallback]] +arch = "i686" +git-tree-sha1 = "2c005b45d9aaa0e217791b3431d9e61e18806cd1" +os = "windows" + + [[Kaleido_fallback.download]] + sha256 = "4b81d3f958281f53bb2f462d2745766f615a6d094b2cc59a0b03fe38c73d1b8a" + url = "https://github.com/JuliaBinaryWrappers/Kaleido_jll.jl/releases/download/Kaleido-v0.1.0+0/Kaleido.v0.1.0.i686-w64-mingw32.tar.gz" +[[Kaleido_fallback]] +arch = "x86_64" +git-tree-sha1 = "aa3e0157eff69c2604027b85f1ff85a59bfae52f" +os = "windows" + + [[Kaleido_fallback.download]] + sha256 = "52bce20e749b9955ee4dd3b22fa44dbdc9a6c4a4d447e243d8c016d4b730d496" + url = "https://github.com/JuliaBinaryWrappers/Kaleido_jll.jl/releases/download/Kaleido-v0.1.0+0/Kaleido.v0.1.0.x86_64-w64-mingw32.tar.gz" \ No newline at end of file diff --git a/Project.toml b/Project.toml index fcedd5d..9964ae9 100644 --- a/Project.toml +++ b/Project.toml @@ -4,21 +4,23 @@ authors = ["Simon Christ ", "Spencer Lyon Date: Fri, 3 Jan 2025 14:09:11 +0100 Subject: [PATCH 2/5] use artifact"" only on Windows --- src/PlotlyKaleido.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/PlotlyKaleido.jl b/src/PlotlyKaleido.jl index 513364f..1c21ec6 100644 --- a/src/PlotlyKaleido.jl +++ b/src/PlotlyKaleido.jl @@ -9,6 +9,12 @@ export savefig #-----------------------------------------------------------------------------# Windows Fallback +const FALLBACK_DIR = @static if Sys.iswindows() + artifact"Kaleido_fallback" +else + "" +end + should_try_fallback() = Sys.iswindows() && (get_kaleido_version() !== "0.1.0") get_kaleido_version() = read(joinpath(Kaleido_jll.artifact_dir, "version"), String) @@ -78,7 +84,7 @@ end function get_base_cmd() cmd = if should_try_fallback() && USE_KALEIDO_FALLBACK[] # For the fallback we don't fully reproduce the jll machinery as this is much simpler and should work fine for kaleido specifically on windows. - dir = artifact"Kaleido_fallback" + dir = FALLBACK_DIR Cmd(`$(joinpath(dir, "bin", "kaleido.exe"))`; dir) else dir = Kaleido_jll.artifact_dir From 7105df49baa7eb04a46d5518f0b615613e21c4a2 Mon Sep 17 00:00:00 2001 From: Alberto Mengali Date: Fri, 3 Jan 2025 14:20:28 +0100 Subject: [PATCH 3/5] test absence of `@warn` for start on Windows --- test/runtests.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 9e1ed9e..745da7e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,7 +3,12 @@ import Pkg @test_nowarn @eval using PlotlyKaleido @testset "Start" begin - @test_nowarn PlotlyKaleido.start() + if Sys.iswindows() + # We use @test_logs without log patterns to test that no @warn is thrown, as specified in the docstring of `@test_logs` + @test_logs PlotlyKaleido.start() + else + @test_nowarn PlotlyKaleido.start() + end @test PlotlyKaleido.is_running() end From af9946a086fa74726c09075b10185ccf49ce6b87 Mon Sep 17 00:00:00 2001 From: Alberto Mengali Date: Fri, 3 Jan 2025 15:21:31 +0100 Subject: [PATCH 4/5] adapt warning on timeout --- src/PlotlyKaleido.jl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/PlotlyKaleido.jl b/src/PlotlyKaleido.jl index 1c21ec6..2893b1f 100644 --- a/src/PlotlyKaleido.jl +++ b/src/PlotlyKaleido.jl @@ -70,14 +70,20 @@ function readline_noblock(io; timeout = 10) wait(task) kaleido_version = get_kaleido_version() out = take!(msg) - out === "Stopped" && warn_and_kill("It looks like the Kaleido process is not responding. -The unresponsive process will be killed, but this means that you will not be able to save figures using `savefig`. - -If you are on Windows this might be caused by known problems with Kaleido v0.2 on Windows (you are using version $(kaleido_version)). -You might want to try forcing a downgrade of the Kaleido_jll library to 0.1. -Check the Package Readme at https://github.com/JuliaPlots/PlotlyKaleido.jl/tree/main#windows-note for more details. + if out === "Stopped" + warn_str = "It looks like the Kaleido process is not responding since $(timeout) seconds. +The unresponsive process will be killed, but this means that you will not be able to save figures using `savefig`." + + if should_try_fallback() && !USE_KALEIDO_FALLBACK[] + warn_str *= " +You seem to be on Windows but have disabled the automatic fallback to version 0.1 of Kaleido. You may want to try enabling it by calling `PlotlyKaleido.USE_KALEIDO_FALLBACK[] = true`, as higher version of Kaleido are known to have issues on Windows. +Check the Package Readme at https://github.com/JuliaPlots/PlotlyKaleido.jl/tree/main#windows-note for more details." + end -If you think this is not your case, you might try using a longer timeout to check if the process is not responding (defaults to 10 seconds) by passing the desired value in seconds using the `timeout` kwarg when calling `PlotlyKaleido.start` or `PlotlyKaleido.restart`") + warn_str *= " +Alternatively, you might try using a longer timeout to check if the process is not responding by passing the desired value in seconds using the `timeout` kwarg when calling `PlotlyKaleido.start` or `PlotlyKaleido.restart`" + warn_and_kill(warn_str) + end return out end From 8a1cb1bb4f4fa58a35a9e55e8d15facbc2779e01 Mon Sep 17 00:00:00 2001 From: Alberto Mengali Date: Fri, 3 Jan 2025 15:28:45 +0100 Subject: [PATCH 5/5] add mention to the README --- README.md | 4 ++++ src/PlotlyKaleido.jl | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0d86fcd..0b5975a 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,8 @@ begin import Pkg Pkg.add(; name = "Kaleido_jll", version = "0.1") end + +The package will now default to using an explicitly provided version of Kaleido 0.1 on Windows systems without requiring to explicitly fix the version of `Kaleido_jll` in your project environment. + +To disable this automatic fallback, you can set `PlotlyKaleido.USE_KALEIDO_FALLBACK[] = false`. ``` diff --git a/src/PlotlyKaleido.jl b/src/PlotlyKaleido.jl index 2893b1f..5c09c4b 100644 --- a/src/PlotlyKaleido.jl +++ b/src/PlotlyKaleido.jl @@ -15,8 +15,8 @@ else "" end -should_try_fallback() = Sys.iswindows() && (get_kaleido_version() !== "0.1.0") get_kaleido_version() = read(joinpath(Kaleido_jll.artifact_dir, "version"), String) +should_try_fallback() = Sys.iswindows() && (get_kaleido_version() !== "0.1.0") const USE_KALEIDO_FALLBACK = Ref(should_try_fallback()) @@ -68,7 +68,6 @@ function readline_noblock(io; timeout = 10) schedule(interrupter) schedule(task) wait(task) - kaleido_version = get_kaleido_version() out = take!(msg) if out === "Stopped" warn_str = "It looks like the Kaleido process is not responding since $(timeout) seconds. @@ -76,11 +75,13 @@ The unresponsive process will be killed, but this means that you will not be abl if should_try_fallback() && !USE_KALEIDO_FALLBACK[] warn_str *= " + You seem to be on Windows but have disabled the automatic fallback to version 0.1 of Kaleido. You may want to try enabling it by calling `PlotlyKaleido.USE_KALEIDO_FALLBACK[] = true`, as higher version of Kaleido are known to have issues on Windows. Check the Package Readme at https://github.com/JuliaPlots/PlotlyKaleido.jl/tree/main#windows-note for more details." end warn_str *= " + Alternatively, you might try using a longer timeout to check if the process is not responding by passing the desired value in seconds using the `timeout` kwarg when calling `PlotlyKaleido.start` or `PlotlyKaleido.restart`" warn_and_kill(warn_str) end