Skip to content

Commit

Permalink
use Requires.jl to make weak dependencies work
Browse files Browse the repository at this point in the history
Based on
https://pkgdocs.julialang.org/v1/creating-packages/#Backwards-compatibility
this uses Requires.jl to bring the weak dependency feature to Julia <1.9
  • Loading branch information
PaulDebus committed Nov 20, 2023
1 parent 1620d15 commit fb36d68
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
17 changes: 10 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"

[extensions]
ImageProjectiveGeometryPyPlotExt = "PyPlot"

[compat]
DSP = "0.5 - 0.7"
FileIO = "1"
Expand All @@ -30,3 +24,12 @@ Images = "0.20 - 0.25"
Interpolations = "0.10 - 0.14"
PyPlot = "2.5 - 2.11"
julia = "1.4"

[extensions]
ImageProjectiveGeometryPyPlotExt = "PyPlot"

[extras]
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"

[weakdeps]
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
3 changes: 2 additions & 1 deletion ext/ImageProjectiveGeometryPyPlotExt.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module ImageProjectiveGeometryPyPlotExt
using LinearAlgebra
using ImageProjectiveGeometry
using PyPlot

isdefined(Base, :get_extension) ? (using ImageProjectiveGeometry) : (using ..ImageProjectiveGeometry)

include("ransacdemo.jl")


Expand Down
10 changes: 7 additions & 3 deletions src/ImageProjectiveGeometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,15 @@ include("ransac.jl")
include("cornerfeatures.jl")
include("utilities.jl")
include("geometry.jl")
include("plotting.jl")

# to keep compatibility with older Julia Versions, include this if we cannot do weak deps
# This symbol is only defined on Julia versions that support extensions
if !isdefined(Base, :get_extension)
include("../ext/ImageProjectiveGeometryPyPlotExt.jl")
using Requires
end
if !isdefined(Base, :get_extension)
function __init__()
Requires.@require PyPlot="d330b81b-6aea-500a-939a-2ce795aea3ee" include("../ext/ImageProjectiveGeometryPyPlotExt.jl")
end
end

end # module

0 comments on commit fb36d68

Please sign in to comment.