Skip to content

Commit 2d3d8ae

Browse files
remove custom default backends (#4870)
* don't precompile custom default backend * don't load backend on precompile * remove preference setting * set julia compat to 1.10 * all of it * remove InspectDR from test environment * remove inspectdr from TEST_BACKENDS * set inspectdr compat to the future * fix nightly * also `with` * mor withs
1 parent 90be928 commit 2d3d8ae

17 files changed

+39
-139
lines changed

Project.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
2222
PlotThemes = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
2323
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
2424
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
25-
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
2625
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2726
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
2827
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -64,7 +63,7 @@ FixedPointNumbers = "0.6 - 0.8"
6463
GR = "0.69.5 - 0.73"
6564
Gaston = "1"
6665
HDF5 = "0.16"
67-
InspectDR = "0.4"
66+
InspectDR = "0.5"
6867
JLFzf = "0.1"
6968
JSON = "0.21, 1"
7069
LaTeXStrings = "1"
@@ -79,7 +78,6 @@ PlotlyBase = "0.7 - 0.8"
7978
PlotlyJS = "0.18"
8079
PlotlyKaleido = "1"
8180
PrecompileTools = "1"
82-
Preferences = "1"
8381
PyPlot = "2"
8482
PythonPlot = "1 - 1.0.2"
8583
RecipesBase = "1.3.1"
@@ -95,7 +93,7 @@ UnicodeFun = "0.4"
9593
UnicodePlots = "3.4"
9694
UnitfulLatexify = "1"
9795
Unzip = "0.1 - 0.2"
98-
julia = "1.6"
96+
julia = "1.10"
9997

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

134132
[targets]
135-
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"]
133+
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"]

src/Plots.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_m
88
end
99

1010
using Pkg, Dates, Printf, Statistics, Base64, LinearAlgebra, SparseArrays, Random
11-
using PrecompileTools, Preferences, Reexport, RelocatableFolders
11+
using PrecompileTools, Reexport, RelocatableFolders
1212
using Base.Meta
1313
@reexport using RecipesBase
1414
@reexport using PlotThemes

src/backends.jl

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -194,35 +194,13 @@ end
194194
CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))
195195

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

203199
function load_default_backend()
204-
# environment variable preempts the `Preferences` based mechanism
205-
CURRENT_BACKEND.sym =
206-
get(ENV, "PLOTS_DEFAULT_BACKEND", PLOTS_DEFAULT_BACKEND) |> lowercase |> Symbol
200+
CURRENT_BACKEND.sym = :gr
207201
backend(CURRENT_BACKEND.sym)
208202
end
209203

210-
function set_default_backend!(
211-
backend::Union{Nothing,AbstractString,Symbol} = nothing;
212-
force = true,
213-
kw...,
214-
)
215-
if backend === nothing
216-
delete_preferences!(Plots, "default_backend"; force, kw...)
217-
else
218-
# NOTE: `_check_installed` already throws a warning
219-
if (value = lowercase(string(backend))) |> _check_installed !== nothing
220-
set_preferences!(Plots, "default_backend" => value; force, kw...)
221-
end
222-
end
223-
nothing
224-
end
225-
226204
function diagnostics(io::IO = stdout)
227205
origin = if has_preference(Plots, "default_backend")
228206
"`Preferences`"

src/examples.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ const _examples = PlotExample[
937937
"3D axis flip / mirror",
938938
:(using LinearAlgebra),
939939
quote
940-
with(scalefonts = 0.5) do
940+
Plots.with(scalefonts = 0.5) do
941941
x, y = collect(-6:0.5:10), collect(-8:0.5:8)
942942

943943
args = x, y, (x, y) -> sinc(norm([x, y]) / π)
@@ -1198,7 +1198,7 @@ const _examples = PlotExample[
11981198
legs,
11991199
)
12001200
w, h = Plots._plot_defaults[:size]
1201-
with(scalefonts = 0.5, size = (2w, 2h)) do
1201+
Plots.with(scalefonts = 0.5, size = (2w, 2h)) do
12021202
plot(leg_plots()..., leg_plots(legend_column = -1)...; layout = (6, 3))
12031203
end
12041204
end,
@@ -1230,7 +1230,7 @@ const _examples = PlotExample[
12301230
legs,
12311231
)
12321232
w, h = Plots._plot_defaults[:size]
1233-
with(scalefonts = 0.5, size = (2w, 2h)) do
1233+
Plots.with(scalefonts = 0.5, size = (2w, 2h)) do
12341234
plot(leg_plots()..., leg_plots(legend_column = -1)...; layout = (6, 3))
12351235
end
12361236
end,

src/init.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ include(_path(backend_name()))
8989
n = length(_examples)
9090
imports = sizehint!(Expr[], n)
9191
examples = sizehint!(Expr[], 10n)
92+
scratch_dir = mktempdir()
9293
for i in setdiff(1:n, _backend_skips[backend_name()], _animation_examples)
9394
_examples[i].external && continue
9495
(imp = _examples[i].imports) === nothing || push!(imports, imp)
@@ -99,15 +100,9 @@ include(_path(backend_name()))
99100
$func() = begin # evaluate each example in a local scope
100101
$(_examples[i].exprs)
101102
$i == 1 || return # only for one example
102-
fn = tempname()
103+
fn = joinpath(scratch_dir, tempname())
103104
pl = current()
104105
show(devnull, pl)
105-
# FIXME: pgfplotsx requires bug
106-
backend_name() === :pgfplotsx && return
107-
if backend_name() === :unicodeplots
108-
savefig(pl, "$fn.txt")
109-
return
110-
end
111106
showable(MIME"image/png"(), pl) && savefig(pl, "$fn.png")
112107
showable(MIME"application/pdf"(), pl) && savefig(pl, "$fn.pdf")
113108
if showable(MIME"image/svg+xml"(), pl)

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ allFunctions(arg) = trueOrAllTrue(a -> isa(a, Function), arg)
634634
"""
635635
Allows temporary setting of backend and defaults for Plots. Settings apply only for the `do` block. Example:
636636
```
637-
with(:gr, size=(400,400), type=:histogram) do
637+
Plots.with(:gr, size=(400,400), type=:histogram) do
638638
plot(rand(10))
639639
plot(rand(10))
640640
end

test/runtests.jl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ using VisualRegressionTests
1313
using RecipesPipeline
1414
using FilePathsBase
1515
using LaTeXStrings
16-
using Preferences
1716
using RecipesBase
1817
using TestImages
1918
using Unitful
@@ -23,12 +22,8 @@ using Dates
2322
using Test
2423
using Gtk # see JuliaPlots/VisualRegressionTests.jl/issues/30
2524

26-
# get `Preferences` set backend, if any
27-
const PREVIOUS_DEFAULT_BACKEND = load_preference(Plots, "default_backend")
28-
2925
# NOTE: don't use `plotly` (test hang, not surprised), test only the backends used in the docs
30-
const TEST_BACKENDS =
31-
:gr, :unicodeplots, :pythonplot, :pgfplotsx, :plotlyjs, :gaston, :inspectdr
26+
const TEST_BACKENDS = :gr, :unicodeplots, :pythonplot, :pgfplotsx, :plotlyjs, :gaston
3227

3328
# initial load - required for `should_warn_on_unsupported`
3429
unicodeplots()
@@ -61,7 +56,6 @@ for name in (
6156
"plotly",
6257
"animations",
6358
"output",
64-
"preferences",
6559
"backends",
6660
)
6761
@testset "$name" begin
@@ -73,9 +67,3 @@ for name in (
7367
include("test_$name.jl")
7468
end
7569
end
76-
77-
if PREVIOUS_DEFAULT_BACKEND === nothing
78-
delete_preferences!(Plots, "default_backend") # restore the absence of a preference
79-
else
80-
Plots.set_default_backend!(PREVIOUS_DEFAULT_BACKEND) # reset to previous state
81-
end

test/test_axes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
["500.×10^{0}", "1.00×10^{3}", "1.50×10^{3}"]
2929
@test Plots.get_labels(:latex, 1:3, :identity) == ["\$1\$", "\$2\$", "\$3\$"]
3030
# GR is used during tests and it correctly overrides labelfunc(), but PGFPlotsX did not
31-
with(:pgfplotsx) do
31+
Plots.with(:pgfplotsx) do
3232
@test Plots.get_labels(:auto, 1:3, :log10) == ["10^{1}", "10^{2}", "10^{3}"]
3333
end
3434
@test Plots.get_labels(:auto, 1:3, :log10) == ["10^{1}", "10^{2}", "10^{3}"]

test/test_backends.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,25 @@ end
122122
## Uncomment the following lines to update reference images for different backends
123123
#=
124124
125-
with(:gr) do
125+
Plots.with(:gr) do
126126
image_comparison_facts(:gr, tol = PLOTS_IMG_TOL, skip = Plots._backend_skips[:gr])
127127
end
128128
129-
with(:plotlyjs) do
129+
Plots.with(:plotlyjs) do
130130
image_comparison_facts(:plotlyjs, tol = PLOTS_IMG_TOL, skip = Plots._backend_skips[:plotlyjs])
131131
end
132132
133-
with(:pyplot) do
133+
Plots.with(:pyplot) do
134134
image_comparison_facts(:pyplot, tol = PLOTS_IMG_TOL, skip = Plots._backend_skips[:pyplot])
135135
end
136136
137-
with(:pgfplotsx) do
137+
Plots.with(:pgfplotsx) do
138138
image_comparison_facts(:pgfplotsx, tol = PLOTS_IMG_TOL, skip = Plots._backend_skips[:pgfplotsx])
139139
end
140140
=#
141141

142142
@testset "UnicodePlots" begin
143-
with(:unicodeplots) do
143+
Plots.with(:unicodeplots) do
144144
@test backend() == Plots.UnicodePlotsBackend()
145145

146146
io = IOContext(IOBuffer(), :color => true)
@@ -190,7 +190,7 @@ end
190190
push!(blacklist, 50) # NOTE: remove when github.com/jheinen/GR.jl/issues/507 is resolved
191191

192192
@testset "GR - reference images" begin
193-
with(:gr) do
193+
Plots.with(:gr) do
194194
# NOTE: use `ENV["VISUAL_REGRESSION_TESTS_AUTO"] = true;` to automatically replace reference images
195195
@test backend() == Plots.GRBackend()
196196
@test backend_name() === :gr
@@ -203,7 +203,7 @@ push!(blacklist, 50) # NOTE: remove when github.com/jheinen/GR.jl/issues/507 i
203203
end
204204

205205
is_pkgeval() || @testset "PlotlyJS" begin
206-
with(:plotlyjs) do
206+
Plots.with(:plotlyjs) do
207207
@test backend() == Plots.PlotlyJSBackend()
208208
pl = plot(rand(10))
209209
@test pl isa Plot

test/test_misc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ end
2020
end
2121

2222
@testset "NoFail" begin
23-
with(:unicodeplots) do
23+
Plots.with(:unicodeplots) do
2424
@test backend() == Plots.UnicodePlotsBackend()
2525

2626
dsp = TextDisplay(IOContext(IOBuffer(), :color => true))
@@ -223,7 +223,7 @@ end
223223

224224
@testset "wrap" begin
225225
# not sure what is intended here ...
226-
wrapped = wrap([:red, :blue])
226+
wrapped = Plots.wrap([:red, :blue])
227227
@test !isempty(wrapped)
228228
@test scatter(1:2, color = wrapped) isa Plots.Plot
229229
end
@@ -241,7 +241,7 @@ end
241241
@test plot(skipmissing(1:5)) isa Plots.Plot
242242
end
243243

244-
with(:gr) do
244+
Plots.with(:gr) do
245245
@testset "text" begin
246246
io = PipeBuffer()
247247
x = y = range(-3, 3, length = 10)

test/test_output.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ macro test_save(fmt)
2929
end |> esc
3030
end
3131

32-
with(:gr) do
32+
Plots.with(:gr) do
3333
@test Plots.defaultOutputFormat(plot()) == "png"
3434
@test Plots.addExtension("foo", "bar") == "foo.bar"
3535

@@ -39,14 +39,14 @@ with(:gr) do
3939
@test_save :ps
4040
end
4141

42-
with(:unicodeplots) do
42+
Plots.with(:unicodeplots) do
4343
@test_save :txt
4444
if Plots.UnicodePlots.get_font_face() nothing
4545
@test_save :png
4646
end
4747
end
4848

49-
with(:plotlyjs) do
49+
Plots.with(:plotlyjs) do
5050
@test_save :html
5151
@test_save :json
5252
@test_save :pdf
@@ -55,21 +55,21 @@ with(:plotlyjs) do
5555
# @test_save :eps
5656
end
5757

58-
with(:plotly) do
58+
Plots.with(:plotly) do
5959
@test_save :pdf
6060
@test_save :png
6161
@test_save :svg
6262
@test_save :html
6363
end
6464

6565
if Sys.islinux() && Sys.which("pdflatex") nothing
66-
with(:pgfplotsx) do
66+
Plots.with(:pgfplotsx) do
6767
@test_save :tex
6868
@test_save :png
6969
@test_save :pdf
7070
end
7171

72-
with(:pythonplot) do
72+
Plots.with(:pythonplot) do
7373
@test_save :pdf
7474
@test_save :png
7575
@test_save :svg
@@ -79,14 +79,14 @@ if Sys.islinux() && Sys.which("pdflatex") ≢ nothing
7979
end
8080

8181
#=
82-
with(:gaston) do
82+
Plots.with(:gaston) do
8383
@test_save :png
8484
@test_save :pdf
8585
@test_save :eps
8686
@test_save :svg
8787
end
8888
89-
with(:inspectdr) do
89+
Plots.with(:inspectdr) do
9090
@test_save :png
9191
@test_save :pdf
9292
@test_save :eps
@@ -95,7 +95,7 @@ end
9595
=#
9696

9797
@testset "html" begin
98-
with(:gr) do
98+
Plots.with(:gr) do
9999
io = PipeBuffer()
100100
pl = plot(1:2)
101101
pl.attr[:html_output_format] = :auto

test/test_pgfplotsx.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function get_pgf_axes(pl)
1515
Plots.pgfx_axes(pl.o)
1616
end
1717

18-
with(:pgfplotsx) do
18+
Plots.with(:pgfplotsx) do
1919
pl = plot(1:5)
2020
axis = first(get_pgf_axes(pl))
2121
@test pl.o.the_plot isa PGFPlotsX.TikzDocument

test/test_plotly.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Plots, Test
2-
with(:plotly) do
2+
Plots.with(:plotly) do
33
@testset "Basic" begin
44
@test backend() == Plots.PlotlyBackend()
55

0 commit comments

Comments
 (0)