Are extension packages importable?

Thanks for your reply. I was experiencing exactly that when I tried to use it in a package.

But wouldn’t it be possible to create a new import statement that would do what the macro does at compile time?

1 Like

Sorry for necroposting but a similar question has just popped up for the 100th time, and the answer relied on a long lost Slack thread. I think it’s time to put this knowledge in the docs.
Anyone want to help with this PR or review it?

2 Likes

Cross-posting a related issue: KeyError on internal use of extensions · Issue #50028 · JuliaLang/julia · GitHub

The basic idea is that you could have a package in [deps] (so it would automatically be installed; without the user needing to do it themselves), but load it as an extension, such as by calling a function:

function call_zygote_function(arg)
    Base.require(@__MODULE__, :Zygote)
    Base.invokelatest(my_zygote_function, arg)
end

which should trigger a Zygote.jl-containing extension to load. However, this does not yet work due to how the extension mechanism requires the package to be in [weakdeps]. It sounds like there’s nothing fundamental preventing this from working though, so it could be a nice way to conditionally load code from within a package while taking advantage of precompilation.

I’ve been google circling around an answer to my question and it comes near this one. It seems to me there is a valid use case for new methods in an extension.

I want to have my module have only the relevant plotting routines for Plots.jl and Makie.jl and I don’t want them loaded with the package unless the user decides to do some plotting.

I’m having a lot of difficulty getting this to work cleanly. The Makie recipes need me to predefine an empty copy of the ultimate method for plotting the object in the parent module and then import it.

I haven’t quite figured it out for the RecipesBase plot overload.

Any thoughts on the best practice for this?

2 Likes

Maybe this helps as one example GitHub - jkrumbiegel/MakiePkgExtTest

I agree here and I’ve circled too. Have you found the way to the force?

Not with the Recipes. I got the extensions to work in general though. I just didn’t use the recipes to do it. I just made up a function and called that.

1 Like