is it possible to re-export names defined in a package extension from within the main package itself?
For example, the hypothetical main package “Optimizer” defines an optimization structure allowing for gradient based optimization, but the user would have to provide derivatives by hand. I could now think of offering optional ForwardDiff support via Requires.jl or the new extension system.
With the Requires approach, I was able to load the sub-module like so:
function __init__()
require ForwardDiff="f6369f11-7733-5829-9624-2563aa707210" begin
include("../ext/ForwardDiffBackendExt.jl")
using .ForwardDiffBackendExt: ForwardDiffBackend
export ForwardDiffBackend
end
end
Now, if ForwardDiff has been loaded, a user could conveniently use ForwardDiffBackend.
Can I achieve something similar with extensions? That is, load the extension in the main package and maybe even export names from it?
I tried
function __init__()
m = Base.get_extension(@__MODULE__, :ForwardDiffBackendExt)
global ForwardDiffBackend = isnothing(m) ? m : m.ForwardDiffBackend
end
But this gives
ERROR: LoadError: InitError: UndefVarError: `ForwardDiffBackend` not defined
and
Error: Error during loading of extension ForwardDiffBackendExt of Optimizer, use `Base.retry_load_extensions()` to retry.
Thanks! From looking at it, what I have in mind is not supported/recommended as of yet (?)
Current workaround is a getter-function that I export instead.