Skip to content

Commit

Permalink
Actually check if the loaded backend version mets the compat entries (#…
Browse files Browse the repository at this point in the history
…4137)

* implement checking backend compat

* format

* handle backends without compat entry

* get version for julia 1.6
  • Loading branch information
BeastyBlacksmith authored Mar 11, 2022
1 parent 4ebadb7 commit 092fb67
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlotThemes = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand Down Expand Up @@ -45,11 +46,11 @@ JSON = "0.21, 1"
Latexify = "0.14 - 0.15"
Measures = "0.3"
NaNMath = "0.3, 1"
PGFPlotsX = "1"
PlotThemes = "2"
PlotUtils = "1"
PlotlyBase = "0.7"
PlotlyJS = "0.18"
PGFPlotsX = "1"
PyPlot = "2"
RecipesBase = "1.2"
RecipesPipeline = "0.5"
Expand Down
33 changes: 22 additions & 11 deletions src/Plots.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
module Plots

using Pkg

if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@optlevel"))
@eval Base.Experimental.@optlevel 1
end
if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_methods"))
@eval Base.Experimental.@max_methods 1
end

const _current_plots_version = VersionNumber(
split(
first(
filter(
line -> occursin("version", line),
readlines(normpath(@__DIR__, "..", "Project.toml")),
),
),
"\"",
)[2],
)
const _plots_project = Pkg.Types.read_project(normpath(@__DIR__, "..", "Project.toml"))
const _current_plots_version = _plots_project.version
const _plots_compats = _plots_project.compat
function _check_compat(sim::Module)
sim_str = string(sim)
if !haskey(_plots_compats, sim_str)
return nothing
end
be_v = Pkg.Types.read_project(joinpath(Base.pkgdir(sim), "Project.toml")).version
be_c = _plots_compats[sim_str]
if be_c isa String # julia 1.6
if be_v in Pkg.Types.semver_spec(be_c)

This comment has been minimized.

Copy link
@t-bltg

t-bltg Mar 11, 2022

Member

@BeastyBlacksmith , shouldn't the condition be negated: if !(be_v in Pkg.Types.semver_spec(be_c)) @warn ... ?

This comment has been minimized.

Copy link
@BeastyBlacksmith

BeastyBlacksmith Mar 11, 2022

Author Member

Thats true, I'll fix it

@warn "$sim $be_v is not compatible with this version of Plots. The declared compatibility is $(be_c)."
end
else
if isempty(intersect(be_v, be_c.val))
@warn "$sim $be_v is not compatible with this version of Plots. The declared compatibility is $(be_c.str)."
end
end
end

using Reexport

Expand Down
22 changes: 12 additions & 10 deletions src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,23 @@ function _initialize_backend(pkg::AbstractBackend)
@eval Main begin
import $sym
export $sym
Plots._check_compat($sym)
end
end

_initialize_backend(pkg::GRBackend) = nothing

function _initialize_backend(pkg::PlotlyBackend)
try
@eval Main begin
import PlotlyBase
end
_check_compat(PlotlyBase)
catch
@info "For saving to png with the Plotly backend PlotlyBase has to be installed."
end
end

# ------------------------------------------------------------------------------
# gr

Expand Down Expand Up @@ -423,16 +435,6 @@ is_marker_supported(::GRBackend, shape::Shape) = true
# ------------------------------------------------------------------------------
# plotly

function _initialize_backend(pkg::PlotlyBackend)
try
@eval Main begin
import PlotlyBase
end
catch
@info "For saving to png with the Plotly backend PlotlyBase has to be installed."
end
end

const _plotly_attr = merge_with_base_supported([
:annotations,
:legend_background_color,
Expand Down

0 comments on commit 092fb67

Please sign in to comment.