From 5f4dfdd5d26ecd30761ba07e44c6f28ceda27abc Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Thu, 22 Sep 2016 13:47:33 -0400 Subject: [PATCH] add_backend/add_backend_string redesign --- src/backends.jl | 9 +++++++-- src/backends/glvisualize.jl | 12 +++++++----- src/backends/gr.jl | 6 ++++++ src/backends/pgfplots.jl | 6 ++++++ src/backends/plotly.jl | 4 +++- src/backends/plotlyjs.jl | 10 ++++++---- src/backends/pyplot.jl | 14 ++++++++------ src/backends/unicodeplots.jl | 7 +++++++ 8 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/backends.jl b/src/backends.jl index bc008e0f..699f1cc1 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -31,8 +31,12 @@ include("backends/web.jl") # --------------------------------------------------------- -add_backend(pkg::Symbol) = add_backend(_backend_instance(pkg)) -add_backend(b::AbstractBackend) = warn("No custom install defined for $(backend_name(b))") +function add_backend(pkg::Symbol) + info("To do a standard install of $pkg, copy and run this:\n\n") + println(add_backend_string(_backend_instance(pkg))) + println() +end +add_backend_string(b::AbstractBackend) = warn("No custom install defined for $(backend_name(b))") # don't do anything as a default _create_backend_figure(plt::Plot) = nothing @@ -147,6 +151,7 @@ function backend() _initialize_backend(inst) catch err warn("Couldn't initialize $sym. (might need to install it?)") + add_backend(sym) rethrow(err) end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index a3e6f9f6..0ca5b03e 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -75,14 +75,15 @@ function _initialize_backend(::GLVisualizeBackend; kw...) end end -function add_backend(::GLVisualizeBackend) - if !is_installed("GLVisualize") +function add_backend_string(b::GLVisualizeBackend) + """ + if !Plots.is_installed("GLVisualize") Pkg.add("GLVisualize") end - if !is_installed("Contour") + if !Plots.is_installed("Contour") Pkg.add("Contour") end - if !is_installed("GLPlot") + if !Plots.is_installed("GLPlot") Pkg.add("GLPlot") end @@ -92,11 +93,12 @@ function add_backend(::GLVisualizeBackend) "GLVisualize", "GeometryTypes", "FixedSizeArrays", "FreeType", "GLPlot" ] - warn("Running Pkg.checkout(\"$pkg\"). To revert, run Pkg.free(\"$pkg\")") + warn("Running Pkg.checkout(\"\$pkg\"). To revert, run Pkg.free(\"\$pkg\")") Pkg.checkout(pkg) end warn("Running Pkg.checkout(\"Reactive\", \"sd/betterstop\"). To revert, run Pkg.free(\"Reactive\")") Pkg.checkout("Reactive", "sd/betterstop") + """ end # --------------------------------------------------------------------------- diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9f0851eb..8c9f2d2d 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -42,6 +42,12 @@ const _gr_marker = _allMarkers const _gr_scale = [:identity, :log10] is_marker_supported(::GRBackend, shape::Shape) = true +function add_backend_string(::GRBackend) + """ + Pkg.add("GR") + Pkg.build("GR") + """ +end function _initialize_backend(::GRBackend; kw...) @eval begin diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index f5b39877..0eb97fd8 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -40,6 +40,12 @@ const _pgfplots_scale = [:identity, :ln, :log2, :log10] # -------------------------------------------------------------------------------------- +function add_backend_string(::PGFPlotsBackend) + """ + Pkg.add("PGFPlots") + Pkg.build("PGFPlots") + """ +end function _initialize_backend(::PGFPlotsBackend; kw...) @eval begin diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index e8d2bbeb..d70ee16e 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -47,8 +47,10 @@ is_subplot_supported(::PlotlyBackend) = true # -------------------------------------------------------------------------------------- -function add_backend(::PlotlyBackend) +function add_backend_string(::PlotlyBackend) + """ Pkg.build("Plots") + """ end diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index c119cc02..cebd6488 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -10,15 +10,17 @@ const _plotlyjs_scale = _plotly_scale # -------------------------------------------------------------------------------------- -function add_backend(::PlotlyJSBackend) - if !is_installed("PlotlyJS") +function add_backend_string(::PlotlyJSBackend) + """ + if !Plots.is_installed("PlotlyJS") Pkg.add("PlotlyJS") end - if !is_installed("Rsvg") + if !Plots.is_installed("Rsvg") Pkg.add("Rsvg") end - @eval import Blink + import Blink Blink.AtomShell.install() + """ end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 4f801fbb..7bdb5992 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -48,13 +48,15 @@ is_marker_supported(::PyPlotBackend, shape::Shape) = true # -------------------------------------------------------------------------------------- -function add_backend(::PyPlotBackend) - if !is_installed("PyPlot") - withenv("PYTHON" => "") do - Pkg.add("PyPlot") - Pkg.build("PyPlot") - end +function add_backend_string(::PyPlotBackend) + """ + if !Plots.is_installed("PyPlot") + Pkg.add("PyPlot") end + withenv("PYTHON" => "") do + Pkg.build("PyPlot") + end + """ end function _initialize_backend(::PyPlotBackend) diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 905a3c36..710e3a4d 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -28,6 +28,13 @@ warnOnUnsupported_args(::UnicodePlotsBackend, d::KW) = nothing # -------------------------------------------------------------------------------------- +function add_backend_string(::UnicodePlotsBackend) + """ + Pkg.add("UnicodePlots") + Pkg.build("UnicodePlots") + """ +end + function _initialize_backend(::UnicodePlotsBackend; kw...) @eval begin import UnicodePlots