Skip to content

Commit 8e77014

Browse files
authored
Manually use Kaleido@v0.1 on windows with explicit artifact (#25)
* 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
1 parent 4c8129d commit 8e77014

File tree

5 files changed

+68
-18
lines changed

5 files changed

+68
-18
lines changed

Artifacts.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[[Kaleido_fallback]]
2+
arch = "i686"
3+
git-tree-sha1 = "2c005b45d9aaa0e217791b3431d9e61e18806cd1"
4+
os = "windows"
5+
6+
[[Kaleido_fallback.download]]
7+
sha256 = "4b81d3f958281f53bb2f462d2745766f615a6d094b2cc59a0b03fe38c73d1b8a"
8+
url = "https://github.com/JuliaBinaryWrappers/Kaleido_jll.jl/releases/download/Kaleido-v0.1.0+0/Kaleido.v0.1.0.i686-w64-mingw32.tar.gz"
9+
[[Kaleido_fallback]]
10+
arch = "x86_64"
11+
git-tree-sha1 = "aa3e0157eff69c2604027b85f1ff85a59bfae52f"
12+
os = "windows"
13+
14+
[[Kaleido_fallback.download]]
15+
sha256 = "52bce20e749b9955ee4dd3b22fa44dbdc9a6c4a4d447e243d8c016d4b730d496"
16+
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"

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ authors = ["Simon Christ <christ@cell.uni-hannover.de>", "Spencer Lyon <spencerl
44
version = "2.2.5"
55

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

1112
[compat]
13+
Artifacts = "1"
1214
JSON = "0.21"
13-
julia = "1.6"
1415
Kaleido_jll = "0.1, 0.2"
16+
julia = "1.6"
1517

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

2325
[targets]
2426
test = ["Test", "PlotlyLight", "EasyConfig", "PlotlyJS", "Pkg"]

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ begin
6767
import Pkg
6868
Pkg.add(; name = "Kaleido_jll", version = "0.1")
6969
end
70+
71+
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.
72+
73+
To disable this automatic fallback, you can set `PlotlyKaleido.USE_KALEIDO_FALLBACK[] = false`.
7074
```

src/PlotlyKaleido.jl

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
module PlotlyKaleido
22

33
using JSON: JSON
4+
using Artifacts: @artifact_str
45
using Base64: Base64
56
using Kaleido_jll: Kaleido_jll
67

78
export savefig
89

10+
#-----------------------------------------------------------------------------# Windows Fallback
11+
12+
const FALLBACK_DIR = @static if Sys.iswindows()
13+
artifact"Kaleido_fallback"
14+
else
15+
""
16+
end
17+
18+
get_kaleido_version() = read(joinpath(Kaleido_jll.artifact_dir, "version"), String)
19+
should_try_fallback() = Sys.iswindows() && (get_kaleido_version() !== "0.1.0")
20+
21+
const USE_KALEIDO_FALLBACK = Ref(should_try_fallback())
22+
923
#-----------------------------------------------------------------------------# Kaleido Process
1024
mutable struct Pipes
1125
stdin::Pipe
@@ -54,19 +68,38 @@ function readline_noblock(io; timeout = 10)
5468
schedule(interrupter)
5569
schedule(task)
5670
wait(task)
57-
kaleido_version = read(joinpath(Kaleido_jll.artifact_dir, "version"), String)
5871
out = take!(msg)
59-
out === "Stopped" && warn_and_kill("It looks like the Kaleido process is not responding.
60-
The unresponsive process will be killed, but this means that you will not be able to save figures using `savefig`.
72+
if out === "Stopped"
73+
warn_str = "It looks like the Kaleido process is not responding since $(timeout) seconds.
74+
The unresponsive process will be killed, but this means that you will not be able to save figures using `savefig`."
75+
76+
if should_try_fallback() && !USE_KALEIDO_FALLBACK[]
77+
warn_str *= "
6178
62-
If you are on Windows this might be caused by known problems with Kaleido v0.2 on Windows (you are using version $(kaleido_version)).
63-
You might want to try forcing a downgrade of the Kaleido_jll library to 0.1.
64-
Check the Package Readme at https://github.com/JuliaPlots/PlotlyKaleido.jl/tree/main#windows-note for more details.
79+
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.
80+
Check the Package Readme at https://github.com/JuliaPlots/PlotlyKaleido.jl/tree/main#windows-note for more details."
81+
end
6582

66-
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`")
83+
warn_str *= "
84+
85+
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`"
86+
warn_and_kill(warn_str)
87+
end
6788
return out
6889
end
6990

91+
function get_base_cmd()
92+
cmd = if should_try_fallback() && USE_KALEIDO_FALLBACK[]
93+
# 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.
94+
dir = FALLBACK_DIR
95+
Cmd(`$(joinpath(dir, "bin", "kaleido.exe"))`; dir)
96+
else
97+
dir = Kaleido_jll.artifact_dir
98+
Cmd(Kaleido_jll.kaleido(); dir)
99+
end
100+
return cmd
101+
end
102+
70103
function start(;
71104
plotly_version = missing,
72105
mathjax = missing,
@@ -76,7 +109,7 @@ function start(;
76109
)
77110
is_running() && return
78111
# The kaleido executable must be run from the artifact directory
79-
BIN = Cmd(Kaleido_jll.kaleido(); dir = Kaleido_jll.artifact_dir)
112+
BIN = get_base_cmd()
80113
# We push the mandatory plotly flag
81114
push!(BIN.exec, "plotly")
82115
chromium_flags = ["--disable-gpu", Sys.isapple() ? "--single-process" : "--no-sandbox"]

test/runtests.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
using Test
22
import Pkg
3-
if Sys.iswindows()
4-
# Fix kaleido tests on windows due to Kaleido_jll@v0.2.1 hanging
5-
Pkg.add(;name = "Kaleido_jll", version = "0.1")
6-
end
73
@test_nowarn @eval using PlotlyKaleido
84

9-
@testset "Start" begin
5+
@testset "Start" begin
106
if Sys.iswindows()
11-
PlotlyKaleido.start()
7+
# We use @test_logs without log patterns to test that no @warn is thrown, as specified in the docstring of `@test_logs`
8+
@test_logs PlotlyKaleido.start()
129
else
1310
@test_nowarn PlotlyKaleido.start()
1411
end
1512
@test PlotlyKaleido.is_running()
1613
end
1714

18-
1915
import PlotlyLight, EasyConfig, PlotlyJS
2016

2117
@testset "Saving JSON String" begin
@@ -62,5 +58,4 @@ end
6258
@testset "Shutdown" begin
6359
PlotlyKaleido.kill_kaleido()
6460
@test !PlotlyKaleido.is_running()
65-
6661
end

0 commit comments

Comments
 (0)