Skip to content

Commit

Permalink
Manually use [email protected] on windows with explicit artifact (#25)
Browse files Browse the repository at this point in the history
* ship kaleido v0.1 as own artifact on windows

* use artifact"" only on Windows

* test absence of `@warn` for start on Windows

* adapt warning on timeout

* add mention to the README
  • Loading branch information
disberd authored Jan 14, 2025
1 parent 4c8129d commit 8e77014
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
16 changes: 16 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ authors = ["Simon Christ <[email protected]>", "Spencer Lyon <spencerl
version = "2.2.5"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Kaleido_jll = "f7e6163d-2fa5-5f23-b69c-1db539e41963"

[compat]
Artifacts = "1"
JSON = "0.21"
julia = "1.6"
Kaleido_jll = "0.1, 0.2"
julia = "1.6"

[extras]
EasyConfig = "acab07b0-f158-46d4-8913-50acef6d41fe"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
PlotlyLight = "ca7969ec-10b3-423e-8d99-40f33abb42bf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[targets]
test = ["Test", "PlotlyLight", "EasyConfig", "PlotlyJS", "Pkg"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
```
49 changes: 41 additions & 8 deletions src/PlotlyKaleido.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
module PlotlyKaleido

using JSON: JSON
using Artifacts: @artifact_str
using Base64: Base64
using Kaleido_jll: Kaleido_jll

export savefig

#-----------------------------------------------------------------------------# Windows Fallback

const FALLBACK_DIR = @static if Sys.iswindows()
artifact"Kaleido_fallback"
else
""
end

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

#-----------------------------------------------------------------------------# Kaleido Process
mutable struct Pipes
stdin::Pipe
Expand Down Expand Up @@ -54,19 +68,38 @@ function readline_noblock(io; timeout = 10)
schedule(interrupter)
schedule(task)
wait(task)
kaleido_version = read(joinpath(Kaleido_jll.artifact_dir, "version"), String)
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 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 *= "
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.
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

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 = FALLBACK_DIR
Cmd(`$(joinpath(dir, "bin", "kaleido.exe"))`; dir)
else
dir = Kaleido_jll.artifact_dir
Cmd(Kaleido_jll.kaleido(); dir)
end
return cmd
end

function start(;
plotly_version = missing,
mathjax = missing,
Expand All @@ -76,7 +109,7 @@ function start(;
)
is_running() && return
# The kaleido executable must be run from the artifact directory
BIN = Cmd(Kaleido_jll.kaleido(); dir = Kaleido_jll.artifact_dir)
BIN = get_base_cmd()
# We push the mandatory plotly flag
push!(BIN.exec, "plotly")
chromium_flags = ["--disable-gpu", Sys.isapple() ? "--single-process" : "--no-sandbox"]
Expand Down
11 changes: 3 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
using Test
import Pkg
if Sys.iswindows()
# Fix kaleido tests on windows due to [email protected] hanging
Pkg.add(;name = "Kaleido_jll", version = "0.1")
end
@test_nowarn @eval using PlotlyKaleido

@testset "Start" begin
@testset "Start" begin
if Sys.iswindows()
PlotlyKaleido.start()
# 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


import PlotlyLight, EasyConfig, PlotlyJS

@testset "Saving JSON String" begin
Expand Down Expand Up @@ -62,5 +58,4 @@ end
@testset "Shutdown" begin
PlotlyKaleido.kill_kaleido()
@test !PlotlyKaleido.is_running()

end

2 comments on commit 8e77014

@BeastyBlacksmith
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Version 2.2.5 already exists

Please sign in to comment.