Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove custom default backends #4870

Merged
merged 11 commits into from
Jan 23, 2024
6 changes: 2 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlotThemes = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down Expand Up @@ -79,7 +78,6 @@ PlotlyBase = "0.7 - 0.8"
PlotlyJS = "0.18"
PlotlyKaleido = "1"
PrecompileTools = "1"
Preferences = "1"
PyPlot = "2"
PythonPlot = "1 - 1.0.2"
RecipesBase = "1.3.1"
Expand All @@ -95,7 +93,7 @@ UnicodeFun = "0.4"
UnicodePlots = "3.4"
UnitfulLatexify = "1"
Unzip = "0.1 - 0.2"
julia = "1.6"
julia = "1.10"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Expand Down Expand Up @@ -132,4 +130,4 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"

[targets]
test = ["Aqua", "Colors", "Distributions", "FileIO", "FilePathsBase", "FreeType", "Gaston", "GeometryBasics", "Gtk", "ImageMagick", "Images", "InspectDR", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "PlotlyBase", "PyPlot", "PythonPlot", "PlotlyKaleido", "HDF5", "RDatasets", "SentinelArrays", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "Unitful", "VisualRegressionTests"]
test = ["Aqua", "Colors", "Distributions", "FileIO", "FilePathsBase", "FreeType", "Gaston", "GeometryBasics", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "PlotlyBase", "PyPlot", "PythonPlot", "PlotlyKaleido", "HDF5", "RDatasets", "SentinelArrays", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "Unitful", "VisualRegressionTests"]
2 changes: 1 addition & 1 deletion src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_m
end

using Pkg, Dates, Printf, Statistics, Base64, LinearAlgebra, SparseArrays, Random
using PrecompileTools, Preferences, Reexport, RelocatableFolders
using PrecompileTools, Reexport, RelocatableFolders
using Base.Meta
@reexport using RecipesBase
@reexport using PlotThemes
Expand Down
26 changes: 2 additions & 24 deletions src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,35 +194,13 @@ end
CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))

# ---------------------------------------------------------
# from github.com/JuliaPackaging/Preferences.jl/blob/master/README.md:
# "Preferences that are accessed during compilation are automatically marked as compile-time preferences"
# ==> this must always be done during precompilation, otherwise
# the cache will not invalidate when preferences change
const PLOTS_DEFAULT_BACKEND = lowercase(load_preference(Plots, "default_backend", "gr"))
const PLOTS_DEFAULT_BACKEND = "gr"

function load_default_backend()
# environment variable preempts the `Preferences` based mechanism
CURRENT_BACKEND.sym =
get(ENV, "PLOTS_DEFAULT_BACKEND", PLOTS_DEFAULT_BACKEND) |> lowercase |> Symbol
CURRENT_BACKEND.sym = :gr
backend(CURRENT_BACKEND.sym)
end

function set_default_backend!(
backend::Union{Nothing,AbstractString,Symbol} = nothing;
force = true,
kw...,
)
if backend === nothing
delete_preferences!(Plots, "default_backend"; force, kw...)
else
# NOTE: `_check_installed` already throws a warning
if (value = lowercase(string(backend))) |> _check_installed !== nothing
set_preferences!(Plots, "default_backend" => value; force, kw...)
end
end
nothing
end

function diagnostics(io::IO = stdout)
origin = if has_preference(Plots, "default_backend")
"`Preferences`"
Expand Down
9 changes: 2 additions & 7 deletions src/init.jl
BeastyBlacksmith marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ include(_path(backend_name()))
n = length(_examples)
imports = sizehint!(Expr[], n)
examples = sizehint!(Expr[], 10n)
scratch_dir = mktempdir()
for i in setdiff(1:n, _backend_skips[backend_name()], _animation_examples)
_examples[i].external && continue
(imp = _examples[i].imports) === nothing || push!(imports, imp)
Expand All @@ -99,15 +100,9 @@ include(_path(backend_name()))
$func() = begin # evaluate each example in a local scope
$(_examples[i].exprs)
$i == 1 || return # only for one example
fn = tempname()
fn = joinpath(scratch_dir, tempname())
pl = current()
show(devnull, pl)
# FIXME: pgfplotsx requires bug
backend_name() === :pgfplotsx && return
if backend_name() === :unicodeplots
savefig(pl, "$fn.txt")
return
end
showable(MIME"image/png"(), pl) && savefig(pl, "$fn.png")
showable(MIME"application/pdf"(), pl) && savefig(pl, "$fn.pdf")
if showable(MIME"image/svg+xml"(), pl)
Expand Down
13 changes: 1 addition & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ using VisualRegressionTests
using RecipesPipeline
using FilePathsBase
using LaTeXStrings
using Preferences
using RecipesBase
using TestImages
using Unitful
Expand All @@ -23,12 +22,9 @@ using Dates
using Test
using Gtk # see JuliaPlots/VisualRegressionTests.jl/issues/30

# get `Preferences` set backend, if any
const PREVIOUS_DEFAULT_BACKEND = load_preference(Plots, "default_backend")

# NOTE: don't use `plotly` (test hang, not surprised), test only the backends used in the docs
const TEST_BACKENDS =
:gr, :unicodeplots, :pythonplot, :pgfplotsx, :plotlyjs, :gaston, :inspectdr
:gr, :unicodeplots, :pythonplot, :pgfplotsx, :plotlyjs, :gaston
BeastyBlacksmith marked this conversation as resolved.
Show resolved Hide resolved

# initial load - required for `should_warn_on_unsupported`
unicodeplots()
Expand Down Expand Up @@ -61,7 +57,6 @@ for name in (
"plotly",
"animations",
"output",
"preferences",
"backends",
)
@testset "$name" begin
Expand All @@ -73,9 +68,3 @@ for name in (
include("test_$name.jl")
end
end

if PREVIOUS_DEFAULT_BACKEND === nothing
delete_preferences!(Plots, "default_backend") # restore the absence of a preference
else
Plots.set_default_backend!(PREVIOUS_DEFAULT_BACKEND) # reset to previous state
end
59 changes: 0 additions & 59 deletions test/test_preferences.jl

This file was deleted.

Loading