replace build.jl by Artifacts.toml (#3023)
* replace build.jl by Artifacts.toml * check ENV * fix it
This commit is contained in:
parent
b8222b46fe
commit
efb5816bc1
7
Artifacts.toml
Normal file
7
Artifacts.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[plotly]
|
||||
git-tree-sha1 = "f03dd0451a05a5fdbbcb3e548998a9d7a1ab6368"
|
||||
lazy = true
|
||||
|
||||
[[plotly.download]]
|
||||
url = "https://cdn.plot.ly/plotly-1.54.2.min.js"
|
||||
sha256 = "487f1da6b7a1f127de59af8a65bb3fe2c63d709f011afea82896bdce28ecc0f8"
|
||||
@ -16,6 +16,7 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||
Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
|
||||
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
|
||||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
|
||||
PlotThemes = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
|
||||
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
|
||||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||
|
||||
18
deps/build.jl
vendored
18
deps/build.jl
vendored
@ -1,18 +0,0 @@
|
||||
|
||||
#TODO: download https://cdn.plot.ly/plotly-1.54.2.min.js to deps/ if it doesn't exist
|
||||
file_path = ""
|
||||
if get(ENV, "PLOTS_HOST_DEPENDENCY_LOCAL", "false") == "true"
|
||||
global file_path
|
||||
local_fn = joinpath(dirname(@__FILE__), "plotly-1.54.2.min.js")
|
||||
if !isfile(local_fn)
|
||||
@info("Cannot find deps/plotly-1.54.2.min.js... downloading latest version.")
|
||||
download("https://cdn.plot.ly/plotly-1.54.2.min.js", local_fn)
|
||||
isfile(local_fn) && (file_path = local_fn)
|
||||
else
|
||||
file_path = local_fn
|
||||
end
|
||||
end
|
||||
|
||||
open("deps.jl", "w") do io
|
||||
println(io, "const plotly_local_file_path = $(repr(file_path))")
|
||||
end
|
||||
11
src/Plots.jl
11
src/Plots.jl
@ -25,17 +25,6 @@ import JSON
|
||||
|
||||
using Requires
|
||||
|
||||
if isfile(joinpath(@__DIR__, "..", "deps", "deps.jl"))
|
||||
include(joinpath(@__DIR__, "..", "deps", "deps.jl"))
|
||||
else
|
||||
# This is a bit dirty, but I don't really see why anyone should be forced
|
||||
# to build Plots, while it will just include exactly the below line
|
||||
# as long as `ENV["PLOTS_HOST_DEPENDENCY_LOCAL"] = "true"` is not set.
|
||||
# If the above env is set + `plotly_local_file_path == ""``,
|
||||
# it will warn in the __init__ function to run build
|
||||
const plotly_local_file_path = ""
|
||||
end
|
||||
|
||||
export
|
||||
grid,
|
||||
bbox,
|
||||
|
||||
@ -875,7 +875,7 @@ html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt)
|
||||
const ijulia_initialized = Ref(false)
|
||||
|
||||
function plotly_html_head(plt::Plot)
|
||||
local_file = ("file:///" * plotly_local_file_path)
|
||||
local_file = ("file:///" * plotly_local_file_path[])
|
||||
plotly =
|
||||
use_local_dependencies[] ? local_file : "https://cdn.plot.ly/plotly-1.54.2.min.js"
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ function standalone_html_window(plt::AbstractPlot)
|
||||
old = use_local_dependencies[] # save state to restore afterwards
|
||||
# if we open a browser ourself, we can host local files, so
|
||||
# when we have a local plotly downloaded this is the way to go!
|
||||
use_local_dependencies[] = isfile(plotly_local_file_path)
|
||||
use_local_dependencies[] = isfile(plotly_local_file_path[])
|
||||
filename = write_temp_html(plt)
|
||||
open_browser_window(filename)
|
||||
# restore for other backends
|
||||
|
||||
@ -4,7 +4,7 @@ const use_local_plotlyjs = Ref(false)
|
||||
|
||||
function _init_ijulia_plotting()
|
||||
# IJulia is more stable with local file
|
||||
use_local_plotlyjs[] = isfile(plotly_local_file_path)
|
||||
use_local_plotlyjs[] = isfile(plotly_local_file_path[])
|
||||
|
||||
ENV["MPLBACKEND"] = "Agg"
|
||||
end
|
||||
|
||||
22
src/init.jl
22
src/init.jl
@ -1,5 +1,7 @@
|
||||
using REPL
|
||||
using Pkg.Artifacts
|
||||
|
||||
const plotly_local_file_path = Ref("")
|
||||
|
||||
function _plots_defaults()
|
||||
if isdefined(Main, :PLOTS_DEFAULTS)
|
||||
@ -74,16 +76,22 @@ function __init__()
|
||||
end
|
||||
end
|
||||
|
||||
if haskey(ENV, "PLOTS_HOST_DEPENDENCY_LOCAL")
|
||||
use_local_plotlyjs[] = ENV["PLOTS_HOST_DEPENDENCY_LOCAL"] == "true"
|
||||
use_local_dependencies[] = isfile(plotly_local_file_path) && use_local_plotlyjs[]
|
||||
if use_local_plotlyjs[] && !isfile(plotly_local_file_path)
|
||||
@warn("PLOTS_HOST_DEPENDENCY_LOCAL is set to true, but no local plotly file found. run Pkg.build(\"Plots\") and make sure PLOTS_HOST_DEPENDENCY_LOCAL is set to true")
|
||||
if get(ENV, "PLOTS_HOST_DEPENDENCY_LOCAL", "false") == true
|
||||
artifact_toml = joinpath(@__DIR__, "Artifacts.toml")
|
||||
|
||||
plotly_sha = artifact_hash("plotly", artifact_toml)
|
||||
if plotly_sha == nothing || !artifact_exists(plotly_sha)
|
||||
plotly_sha = create_artifact() do artifact_dir
|
||||
download("https://cdn.plot.ly/plotly-1.54.2.min.js", joinpath(artifact_dir, "plotly-1.54.2.min.js"))
|
||||
end
|
||||
end
|
||||
else
|
||||
use_local_dependencies[] = use_local_plotlyjs[]
|
||||
|
||||
plotly_local_file_path[] = joinpath(artifact_path(plotly_sha), "plotly-1.54.2.min.js")
|
||||
use_local_plotlyjs[] = true
|
||||
end
|
||||
|
||||
use_local_dependencies[] = use_local_plotlyjs[]
|
||||
|
||||
|
||||
@require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" begin
|
||||
_show(io::IO, mime::MIME"image/png", plt::Plot{<:PDFBackends}) = _show_pdfbackends(io, mime, plt)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user