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_name() = CURRENT_BACKEND.sym
_backend_instance(sym::Symbol) = haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported 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) macro init_backend(s)
str = lowercase(string(s)) str = lowercase(string(s))
sym = Symbol(str) sym = Symbol(str)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -77,8 +77,12 @@ function _initialize_backend(::PyPlotBackend)
# problem: https://github.com/tbreloff/Plots.jl/issues/308 # problem: https://github.com/tbreloff/Plots.jl/issues/308
# solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768 # solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768
otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays)) 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) append!(Base.Multimedia.displays, otherdisplays)
export PyPlot export PyPlot

View File

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

View File

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