diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09424884be..7eeecd9f06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,6 @@ jobs: GKS_ENCODING: "utf8" GKSwstype: "nul" PYTHON: "Conda" # for `PyPlot` - JULIA_PYTHONCALL_EXE: "@PyCall" # for `PythonCall` name: Julia ${{ matrix.version }} - ${{ matrix.os }} runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.version == 'nightly' }} @@ -96,6 +95,7 @@ jobs: Conda.list() # configure `CondPkg` to use `Conda` setup open(ENV["GITHUB_ENV"], "a") do io + println(io, "JULIA_PYTHONCALL_EXE=", joinpath(Conda.BINDIR, "python")) println(io, "JULIA_CONDAPKG_EXE=", Conda.CONDA_EXE) println(io, "JULIA_CONDAPKG_BACKEND=Null") end diff --git a/src/backends.jl b/src/backends.jl index 3bcf69aff0..b2a9000ead 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -745,14 +745,14 @@ const _plotlyjs_scale = _plotly_scale # pyplot _post_init(::PyPlotBackend) = @eval begin - pycolors = PyPlot.pyimport("matplotlib.colors") - pypath = PyPlot.pyimport("matplotlib.path") - mplot3d = PyPlot.pyimport("mpl_toolkits.mplot3d") - axes_grid1 = PyPlot.pyimport("mpl_toolkits.axes_grid1") - pypatches = PyPlot.pyimport("matplotlib.patches") - pyticker = PyPlot.pyimport("matplotlib.ticker") - pycmap = PyPlot.pyimport("matplotlib.cm") - pynp = PyPlot.pyimport("numpy") + pycolors = PyCall.pyimport("matplotlib.colors") + pypath = PyCall.pyimport("matplotlib.path") + mplot3d = PyCall.pyimport("mpl_toolkits.mplot3d") + axes_grid1 = PyCall.pyimport("mpl_toolkits.axes_grid1") + pypatches = PyCall.pyimport("matplotlib.patches") + pyticker = PyCall.pyimport("matplotlib.ticker") + pycmap = PyCall.pyimport("matplotlib.cm") + pynp = PyCall.pyimport("numpy") pynp."seterr"(invalid = "ignore") @@ -765,7 +765,10 @@ function _initialize_backend(pkg::PyPlotBackend) export PyPlot $(_check_compat)(PyPlot) end - @eval const PyPlot = Main.PyPlot + @eval begin + const PyPlot = Main.PyPlot + const PyCall = Main.PyPlot.PyCall + end _post_init(pkg) end @@ -897,7 +900,7 @@ _post_init(::PythonPlotBackend) = @eval begin mpl = PythonCall.pyimport("matplotlib") numpy = PythonCall.pyimport("numpy") - PythonPlot.pyimport("mpl_toolkits.axes_grid1") + PythonCall.pyimport("mpl_toolkits.axes_grid1") numpy.seterr(invalid = "ignore") PythonPlot.ioff() # we don't want every command to update the figure diff --git a/src/init.jl b/src/init.jl index 6d0a6e8a96..6b5c04f941 100644 --- a/src/init.jl +++ b/src/init.jl @@ -33,11 +33,9 @@ end function _plots_plotly_defaults() if bool_env("PLOTS_HOST_DEPENDENCY_LOCAL", "false") _plotly_local_file_path[] = - joinpath(@get_scratch!("plotly"), _plotly_min_js_filename) - isfile(_plotly_local_file_path[]) || Downloads.download( - "https://cdn.plot.ly/$(_plotly_min_js_filename)", - _plotly_local_file_path[], - ) + fn = joinpath(@get_scratch!("plotly"), _plotly_min_js_filename) + isfile(fn) || + Downloads.download("https://cdn.plot.ly/$(_plotly_min_js_filename)", fn) _use_local_plotlyjs[] = true end _use_local_dependencies[] = _use_local_plotlyjs[] diff --git a/test/test_backends.jl b/test/test_backends.jl index a8e93e6631..b6f8edb324 100644 --- a/test/test_backends.jl +++ b/test/test_backends.jl @@ -12,7 +12,7 @@ const PLOTS_IMG_TOL = parse(Float64, get(ENV, "PLOTS_IMG_TOL", is_ci() ? ci_tol( # NOTE: don't use `plotly` (test hang, not surprised), test only the backends used in the docs const CONCRETE_BACKENDS = - :gr, :unicodeplots, :pyplot, :pythonplot, :pgfplotsx, :plotlyjs, :gaston, :inspectdr + :gr, :unicodeplots, :pythonplot, :pgfplotsx, :plotlyjs, :gaston, :inspectdr, :pyplot Base.eval(TESTS_MODULE, :(using Random, StableRNGs, Plots)) @@ -83,9 +83,10 @@ function image_comparison_tests( example = Plots._examples[idx] @info "Testing plot: $pkg:$idx:$(example.header)" - reffn = reference_file(pkg, Plots._current_plots_version, idx) - newfn = - joinpath(reference_path(pkg, Plots._current_plots_version), ref_name(idx) * ".png") + ver = Plots._current_plots_version + ver = VersionNumber(ver.major, ver.minor, ver.patch) + reffn = reference_file(pkg, ver, idx) + newfn = joinpath(reference_path(pkg, ver), ref_name(idx) * ".png") imports = something(example.imports, :()) exprs = quote @@ -142,64 +143,6 @@ with(:pgfplotsx) do end =# -@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 "simple restart" begin - # this test mimics a restart, which is needed after a preferences change - Plots.set_default_backend!(:unicodeplots) - script = tempname() - write( - script, - """ - ENV["PLOTS_PRECOMPILE"] = false - 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 CONCRETE_BACKENDS - (Sys.isapple() && be === :gaston) && continue # FIXME: hangs - @test_logs Plots.set_default_backend!(be) # test the absence of warnings - @test Base.compilecache(Base.module_keys[Plots]) isa String # test default precompilation - end - - Plots.set_default_backend!() # clear `Preferences` key -end - @testset "UnicodePlots" begin with(:unicodeplots) do @test backend() == Plots.UnicodePlotsBackend() @@ -262,6 +205,64 @@ end end end +@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 "simple restart" begin + # this test mimics a restart, which is needed after a preferences change + Plots.set_default_backend!(:unicodeplots) + script = tempname() + write( + script, + """ + ENV["PLOTS_PRECOMPILE"] = false + 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 CONCRETE_BACKENDS + (Sys.isapple() && be === :gaston) && continue # FIXME: hangs + @test_logs Plots.set_default_backend!(be) # test the absence of warnings + @test Base.compilecache(Base.module_keys[Plots]) isa String # test default precompilation + end + + Plots.set_default_backend!() # clear `Preferences` key +end + is_pkgeval() || @testset "PlotlyJS" begin with(:plotlyjs) do @test backend() == Plots.PlotlyJSBackend()