Clean up backend default handling

This commit is contained in:
Oliver Schulz 2018-11-01 23:08:52 +01:00
parent ffcdf986a3
commit b9b6439f47
2 changed files with 13 additions and 12 deletions

View File

@ -136,24 +136,27 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))
# --------------------------------------------------------- # ---------------------------------------------------------
function pickDefaultBackend() _fallback_default_backend() = backend(GRBackend())
function _pick_default_backend()
env_default = get(ENV, "PLOTS_DEFAULT_BACKEND", "") env_default = get(ENV, "PLOTS_DEFAULT_BACKEND", "")
if env_default != "" if env_default != ""
sym = Symbol(lowercase(env_default)) sym = Symbol(lowercase(env_default))
if sym in _backends if sym in _backends
if sym in _initialized_backends if sym in _initialized_backends
return backend(sym) backend(sym)
else else
@warn("You have set `PLOTS_DEFAULT_BACKEND=$env_default` but `$(backend_package_name(sym))` is not loaded.") @warn("You have set `PLOTS_DEFAULT_BACKEND=$env_default` but `$(backend_package_name(sym))` is not loaded.")
_fallback_default_backend()
end end
else else
@warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not a valid backend package. Choose from:\n\t" * @warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not a valid backend package. Choose from:\n\t" *
join(sort(_backends), "\n\t")) join(sort(_backends), "\n\t"))
_fallback_default_backend()
end end
else
_fallback_default_backend()
end end
# the default if nothing else is installed
backend(:gr)
end end
@ -163,13 +166,11 @@ end
Returns the current plotting package name. Initializes package on first call. Returns the current plotting package name. Initializes package on first call.
""" """
function backend() function backend()
if CURRENT_BACKEND.sym == :none
_pick_default_backend()
end
global CURRENT_BACKEND CURRENT_BACKEND.pkg
if CURRENT_BACKEND.sym == :none
pickDefaultBackend()
end
CURRENT_BACKEND.pkg
end end
""" """

View File

@ -726,7 +726,7 @@ function with(f::Function, args...; kw...)
# save the backend # save the backend
if CURRENT_BACKEND.sym == :none if CURRENT_BACKEND.sym == :none
pickDefaultBackend() _pick_default_backend()
end end
oldbackend = CURRENT_BACKEND.sym oldbackend = CURRENT_BACKEND.sym