diff --git a/src/extensions.jl b/src/extensions.jl index 23536837..27efd4c9 100644 --- a/src/extensions.jl +++ b/src/extensions.jl @@ -1,8 +1,28 @@ # extensions # stubs that need ArchGDAL -resample(args...; kw...) = throw(BackendException("ArchGDAL")) -warp(args...; kw...) = throw(BackendException("ArchGDAL")) +function resample(args...; kw...) + @static if isdefined(Base, :get_extension) # julia > 1.9 + if isnothing(Base.get_extension(Rasters, :RastersArchGDALExt)) + throw(BackendException("ArchGDAL")) + else + throw(MethodError(resample, args)) + end + else + throw(BackendException("ArchGDAL")) + end +end +function warp(args...; kw...) + @static if isdefined(Base, :get_extension) # julia > 1.9 + if isnothing(Base.get_extension(Rasters, :RastersArchGDALExt)) + throw(BackendException("ArchGDAL")) + else + throw(MethodError(warp, args)) + end + else + throw(BackendException("ArchGDAL")) + end +end # Other shared stubs function layerkeys end diff --git a/test/extensions.jl b/test/extensions.jl new file mode 100644 index 00000000..8d29c768 --- /dev/null +++ b/test/extensions.jl @@ -0,0 +1,11 @@ +using Test, Rasters + +# These methods should throw a BackendException +@test_throws Rasters.BackendException resample(1, 2, 3) +@test_throws Rasters.BackendException warp(1, 2, 3) + +import ArchGDAL + +# Should throw a MethodError now that ArchGDAL is loaded +@test_throws MethodError resample(1, 2, 3) +@test_throws MethodError warp(1, 2, 3) diff --git a/test/runtests.jl b/test/runtests.jl index 9bea5a10..a03c7224 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,7 @@ if VERSION >= v"1.9.0" Aqua.test_project_extras(Rasters) Aqua.test_deps_compat(Rasters) # Aqua.test_project_toml_formatting(Rasters) + @time @safetestset "extensions" begin include("extensions.jl") end end