kludge to allow hot-plug of optional backends

This commit is contained in:
Ralph A. Smith 2018-06-17 14:36:31 -04:00
parent 4c34a1df15
commit 682fa6e9e6
9 changed files with 33 additions and 9 deletions

View File

@ -13,6 +13,26 @@ backends() = _backends
backend_name() = CURRENT_BACKEND.sym
_backend_instance(sym::Symbol) = haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported backend $sym")
# kludge while waiting for Pkg alternatives
if VERSION >= v"0.7-"
function _findmod(f::Symbol)
for (u,v) in Base.loaded_modules
(Symbol(v) == f) && return u
end
nothing
end
function topimport(modname)
@eval Base.__toplevel__ import $modname
u = _findmod(modname)
@eval $modname = Base.loaded_modules[$u]
end
else
function myimport(modname)
@eval import $modname
end
end
# end kludge
macro init_backend(s)
str = lowercase(string(s))
sym = Symbol(str)

View File

@ -67,7 +67,7 @@ end
function _initialize_backend(::GRBackend; kw...)
@eval begin
import GR
topimport(:GR)
export GR
end
end

View File

@ -142,7 +142,7 @@ end
function _initialize_backend(::HDF5Backend)
@eval begin
import HDF5
topimport(:HDF5)
export HDF5
if length(HDF5PLOT_MAP_TELEM2STR) < 1
#Possible element types of high-level data types:

View File

@ -162,7 +162,7 @@ end
function _initialize_backend(::InspectDRBackend; kw...)
@eval begin
import InspectDR
topimport(:InspectDR)
export InspectDR
#Glyph used when plotting "Shape"s:

View File

@ -58,7 +58,7 @@ end
function _initialize_backend(::PGFPlotsBackend; kw...)
@eval begin
import PGFPlots
topimport(:PGFPlots)
export PGFPlots
end
end

View File

@ -29,7 +29,7 @@ end
function _initialize_backend(::PlotlyJSBackend; kw...)
@eval begin
import PlotlyJS
topimport(:PlotlyJS)
export PlotlyJS
end

View File

@ -77,8 +77,12 @@ function _initialize_backend(::PyPlotBackend)
# problem: https://github.com/tbreloff/Plots.jl/issues/308
# solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768
otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays))
import PyPlot, PyCall
import LaTeXStrings: latexstring
topimport(:PyPlot)
topimport(:PyCall)
topimport(:LaTeXStrings)
latexstring = LaTeXStrings.latexstring
append!(Base.Multimedia.displays, otherdisplays)
export PyPlot

View File

@ -5,7 +5,7 @@
function _initialize_backend(::[PkgName]Backend; kw...)
@eval begin
import [PkgName]
topimport(:[PkgName])
export [PkgName]
# todo: other initialization that needs to be eval-ed
end

View File

@ -42,7 +42,7 @@ end
function _initialize_backend(::UnicodePlotsBackend; kw...)
@eval begin
import UnicodePlots
topimport(:UnicodePlots)
export UnicodePlots
end
end