diff --git a/Project.toml b/Project.toml index b73284b1d..d682b7d18 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -64,7 +63,7 @@ FixedPointNumbers = "0.6 - 0.8" GR = "0.69.5 - 0.73" Gaston = "1" HDF5 = "0.16" -InspectDR = "0.4" +InspectDR = "0.5" JLFzf = "0.1" JSON = "0.21, 1" LaTeXStrings = "1" @@ -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" @@ -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" @@ -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"] diff --git a/src/Plots.jl b/src/Plots.jl index 3c8e6b942..e3610d9bd 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -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 diff --git a/src/backends.jl b/src/backends.jl index 6b803858b..faa104efe 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -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`" diff --git a/src/examples.jl b/src/examples.jl index 230368392..2fe65b1d6 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -937,7 +937,7 @@ const _examples = PlotExample[ "3D axis flip / mirror", :(using LinearAlgebra), quote - with(scalefonts = 0.5) do + Plots.with(scalefonts = 0.5) do x, y = collect(-6:0.5:10), collect(-8:0.5:8) args = x, y, (x, y) -> sinc(norm([x, y]) / π) @@ -1198,7 +1198,7 @@ const _examples = PlotExample[ legs, ) w, h = Plots._plot_defaults[:size] - with(scalefonts = 0.5, size = (2w, 2h)) do + Plots.with(scalefonts = 0.5, size = (2w, 2h)) do plot(leg_plots()..., leg_plots(legend_column = -1)...; layout = (6, 3)) end end, @@ -1230,7 +1230,7 @@ const _examples = PlotExample[ legs, ) w, h = Plots._plot_defaults[:size] - with(scalefonts = 0.5, size = (2w, 2h)) do + Plots.with(scalefonts = 0.5, size = (2w, 2h)) do plot(leg_plots()..., leg_plots(legend_column = -1)...; layout = (6, 3)) end end, diff --git a/src/init.jl b/src/init.jl index aa58c2bb9..b962a843f 100644 --- a/src/init.jl +++ b/src/init.jl @@ -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) @@ -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) diff --git a/src/utils.jl b/src/utils.jl index 74878824f..faf7b1880 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -634,7 +634,7 @@ allFunctions(arg) = trueOrAllTrue(a -> isa(a, Function), arg) """ Allows temporary setting of backend and defaults for Plots. Settings apply only for the `do` block. Example: ``` -with(:gr, size=(400,400), type=:histogram) do +Plots.with(:gr, size=(400,400), type=:histogram) do plot(rand(10)) plot(rand(10)) end diff --git a/test/runtests.jl b/test/runtests.jl index f568f6d5e..cb98dbfa1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,7 +13,6 @@ using VisualRegressionTests using RecipesPipeline using FilePathsBase using LaTeXStrings -using Preferences using RecipesBase using TestImages using Unitful @@ -23,12 +22,8 @@ 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 +const TEST_BACKENDS = :gr, :unicodeplots, :pythonplot, :pgfplotsx, :plotlyjs, :gaston # initial load - required for `should_warn_on_unsupported` unicodeplots() @@ -61,7 +56,6 @@ for name in ( "plotly", "animations", "output", - "preferences", "backends", ) @testset "$name" begin @@ -73,9 +67,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 diff --git a/test/test_axes.jl b/test/test_axes.jl index 62092ac5b..01df32ecd 100644 --- a/test/test_axes.jl +++ b/test/test_axes.jl @@ -28,7 +28,7 @@ ["500.×10^{0}", "1.00×10^{3}", "1.50×10^{3}"] @test Plots.get_labels(:latex, 1:3, :identity) == ["\$1\$", "\$2\$", "\$3\$"] # GR is used during tests and it correctly overrides labelfunc(), but PGFPlotsX did not - with(:pgfplotsx) do + Plots.with(:pgfplotsx) do @test Plots.get_labels(:auto, 1:3, :log10) == ["10^{1}", "10^{2}", "10^{3}"] end @test Plots.get_labels(:auto, 1:3, :log10) == ["10^{1}", "10^{2}", "10^{3}"] diff --git a/test/test_backends.jl b/test/test_backends.jl index d6e1c3c04..7a8b0ba8d 100644 --- a/test/test_backends.jl +++ b/test/test_backends.jl @@ -122,25 +122,25 @@ end ## Uncomment the following lines to update reference images for different backends #= -with(:gr) do +Plots.with(:gr) do image_comparison_facts(:gr, tol = PLOTS_IMG_TOL, skip = Plots._backend_skips[:gr]) end -with(:plotlyjs) do +Plots.with(:plotlyjs) do image_comparison_facts(:plotlyjs, tol = PLOTS_IMG_TOL, skip = Plots._backend_skips[:plotlyjs]) end -with(:pyplot) do +Plots.with(:pyplot) do image_comparison_facts(:pyplot, tol = PLOTS_IMG_TOL, skip = Plots._backend_skips[:pyplot]) end -with(:pgfplotsx) do +Plots.with(:pgfplotsx) do image_comparison_facts(:pgfplotsx, tol = PLOTS_IMG_TOL, skip = Plots._backend_skips[:pgfplotsx]) end =# @testset "UnicodePlots" begin - with(:unicodeplots) do + Plots.with(:unicodeplots) do @test backend() == Plots.UnicodePlotsBackend() io = IOContext(IOBuffer(), :color => true) @@ -190,7 +190,7 @@ end push!(blacklist, 50) # NOTE: remove when github.com/jheinen/GR.jl/issues/507 is resolved @testset "GR - reference images" begin - with(:gr) do + Plots.with(:gr) do # NOTE: use `ENV["VISUAL_REGRESSION_TESTS_AUTO"] = true;` to automatically replace reference images @test backend() == Plots.GRBackend() @test backend_name() === :gr @@ -203,7 +203,7 @@ push!(blacklist, 50) # NOTE: remove when github.com/jheinen/GR.jl/issues/507 i end is_pkgeval() || @testset "PlotlyJS" begin - with(:plotlyjs) do + Plots.with(:plotlyjs) do @test backend() == Plots.PlotlyJSBackend() pl = plot(rand(10)) @test pl isa Plot diff --git a/test/test_misc.jl b/test/test_misc.jl index 9559b4fc7..172aee38c 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -20,7 +20,7 @@ end end @testset "NoFail" begin - with(:unicodeplots) do + Plots.with(:unicodeplots) do @test backend() == Plots.UnicodePlotsBackend() dsp = TextDisplay(IOContext(IOBuffer(), :color => true)) @@ -223,7 +223,7 @@ end @testset "wrap" begin # not sure what is intended here ... - wrapped = wrap([:red, :blue]) + wrapped = Plots.wrap([:red, :blue]) @test !isempty(wrapped) @test scatter(1:2, color = wrapped) isa Plots.Plot end @@ -241,7 +241,7 @@ end @test plot(skipmissing(1:5)) isa Plots.Plot end -with(:gr) do +Plots.with(:gr) do @testset "text" begin io = PipeBuffer() x = y = range(-3, 3, length = 10) diff --git a/test/test_output.jl b/test/test_output.jl index 12f3270a3..5fb80018f 100644 --- a/test/test_output.jl +++ b/test/test_output.jl @@ -29,7 +29,7 @@ macro test_save(fmt) end |> esc end -with(:gr) do +Plots.with(:gr) do @test Plots.defaultOutputFormat(plot()) == "png" @test Plots.addExtension("foo", "bar") == "foo.bar" @@ -39,14 +39,14 @@ with(:gr) do @test_save :ps end -with(:unicodeplots) do +Plots.with(:unicodeplots) do @test_save :txt if Plots.UnicodePlots.get_font_face() ≢ nothing @test_save :png end end -with(:plotlyjs) do +Plots.with(:plotlyjs) do @test_save :html @test_save :json @test_save :pdf @@ -55,7 +55,7 @@ with(:plotlyjs) do # @test_save :eps end -with(:plotly) do +Plots.with(:plotly) do @test_save :pdf @test_save :png @test_save :svg @@ -63,13 +63,13 @@ with(:plotly) do end if Sys.islinux() && Sys.which("pdflatex") ≢ nothing - with(:pgfplotsx) do + Plots.with(:pgfplotsx) do @test_save :tex @test_save :png @test_save :pdf end - with(:pythonplot) do + Plots.with(:pythonplot) do @test_save :pdf @test_save :png @test_save :svg @@ -79,14 +79,14 @@ if Sys.islinux() && Sys.which("pdflatex") ≢ nothing end #= -with(:gaston) do +Plots.with(:gaston) do @test_save :png @test_save :pdf @test_save :eps @test_save :svg end -with(:inspectdr) do +Plots.with(:inspectdr) do @test_save :png @test_save :pdf @test_save :eps @@ -95,7 +95,7 @@ end =# @testset "html" begin - with(:gr) do + Plots.with(:gr) do io = PipeBuffer() pl = plot(1:2) pl.attr[:html_output_format] = :auto diff --git a/test/test_pgfplotsx.jl b/test/test_pgfplotsx.jl index 5d178603a..12069b740 100644 --- a/test/test_pgfplotsx.jl +++ b/test/test_pgfplotsx.jl @@ -15,7 +15,7 @@ function get_pgf_axes(pl) Plots.pgfx_axes(pl.o) end -with(:pgfplotsx) do +Plots.with(:pgfplotsx) do pl = plot(1:5) axis = first(get_pgf_axes(pl)) @test pl.o.the_plot isa PGFPlotsX.TikzDocument diff --git a/test/test_plotly.jl b/test/test_plotly.jl index dedc72e36..8b172d2a6 100644 --- a/test/test_plotly.jl +++ b/test/test_plotly.jl @@ -1,5 +1,5 @@ using Plots, Test -with(:plotly) do +Plots.with(:plotly) do @testset "Basic" begin @test backend() == Plots.PlotlyBackend() diff --git a/test/test_preferences.jl b/test/test_preferences.jl deleted file mode 100644 index 033087001..000000000 --- a/test/test_preferences.jl +++ /dev/null @@ -1,59 +0,0 @@ - -@testset "Preferences" begin - Plots.set_default_backend!() # start with empty preferences - - withenv("PLOTS_DEFAULT_BACKEND" => "invalid") do - @test_logs (:warn, r".*is not a supported backend") Plots.load_default_backend() - end - @test_logs (:warn, r".*is not a supported backend") backend(:invalid) - - @test Plots.load_default_backend() == Plots.GRBackend() - - withenv("PLOTS_DEFAULT_BACKEND" => "unicodeplots") do - @test_logs (:info, r".*environment variable") Plots.diagnostics(devnull) - @test Plots.load_default_backend() == Plots.UnicodePlotsBackend() - end - - @test Plots.load_default_backend() == Plots.GRBackend() - @test Plots.backend_package_name() === :GR - @test Plots.backend_name() === :gr - - @test_logs (:info, r".*fallback") Plots.diagnostics(devnull) - - @test Plots.merge_with_base_supported([:annotations, :guide]) isa Set - @test Plots.CurrentBackend(:gr).sym === :gr - - @test_logs (:warn, r".*is not compatible with") Plots.set_default_backend!(:invalid) - - @testset "persistent backend" begin - # this test mimics a restart, which is needed after a preferences change - Plots.set_default_backend!(:unicodeplots) - script = tempname() - write( - script, - """ - using Pkg, Test; io = (devnull, stdout)[1] # toggle for debugging - Pkg.activate(; temp = true, io) - Pkg.develop(; path = "$(escape_string(pkgdir(Plots)))", io) - Pkg.add("UnicodePlots"; io) # checked by Plots - using Plots - res = @testset "Prefs" begin - @test_logs (:info, r".*Preferences") Plots.diagnostics(io) - @test backend() == Plots.UnicodePlotsBackend() - end - exit(res.n_passed == 2 ? 0 : 1) - """, - ) - @test success(run(```$(Base.julia_cmd()) $script```)) - end - - is_pkgeval() || for be in TEST_BACKENDS - (Sys.isapple() && be === :gaston) && continue # FIXME: hangs - (Sys.iswindows() && be === :plotlyjs && is_ci()) && continue # OutOfMemory - @test_logs Plots.set_default_backend!(be) # test the absence of warnings - rm.(Base.find_all_in_cache_path(Base.module_keys[Plots])) # make sure the compiled cache is removed - @test success(run(```$(Base.julia_cmd()) -e 'using Plots'```)) # test default precompilation - end - - Plots.set_default_backend!() # clear `Preferences` key -end diff --git a/test/test_recipes.jl b/test/test_recipes.jl index 34273b172..a7fe5007f 100644 --- a/test/test_recipes.jl +++ b/test/test_recipes.jl @@ -99,7 +99,7 @@ end @test Plots.seriestype_supported(Plots.NoBackend(), :line) === :no end -with(:gr) do +Plots.with(:gr) do @testset "error bars" begin x = y = 1:10 yerror = fill(1, length(y)) diff --git a/test/test_unitful.jl b/test/test_unitful.jl index efcde6e2d..b0d79fdee 100644 --- a/test/test_unitful.jl +++ b/test/test_unitful.jl @@ -400,7 +400,7 @@ end if Sys.islinux() && Sys.which("pdflatex") ≢ nothing @testset "pgfplotsx exponents" begin # github.com/JuliaPlots/Plots.jl/issues/4722 - with(:pgfplotsx) do + Plots.with(:pgfplotsx) do pl = plot([1u"s", 2u"s"], [1u"m/s^2", 2u"m/s^2"]) savefig(pl, tempname() * ".pdf") diff --git a/test/test_utils.jl b/test/test_utils.jl index e597c90c2..adf07c2a3 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -80,7 +80,7 @@ show(devnull, pl[1][:xaxis]) # bounding boxes - with(:gr) do + Plots.with(:gr) do show(devnull, plot(1:2)) end @@ -297,7 +297,7 @@ end end @testset "dispatch" begin - with(:gr) do + Plots.with(:gr) do pl = heatmap(rand(10, 10); xscale = :log10, yscale = :log10) @test show(devnull, pl) isa Nothing