and I want that when a user does using MyPackage, FirstWeakDep, when the extension is loaded the first time, a new package, say ThirdDep, gets installed. This way, I can import ThirdDep in ExtModule even though it wasn’t previously installed when the user did ]add MyPackage . After the first time, it shouldn’t install it again clearly, just import it.
In practice this would allow not installing ThirdDep when MyPackage gets installed but only when the extension is used the first time, which could be useful if ThirdDep requires a lot of time to install and it is needed just by a few users. Is there a way to do this? Should the Project.toml be changed somehow to achieve this?
Is there a solution to those extension conditional dependencies in the mean time?
Here is my scenario: I have an extension that is loaded when Makie.jl is loaded, which provides a specific density plot. This plot requires the KernelDensity package (i.e. the ThirdDep in above terms).
If I put KernelDensity into weakdeps, my extension is only loaded if KernelDensity is also imported by the user. but I want to load my extension already if only Makie is loaded.
If I put KernelDensity as denpendecy of the main package, KernelDensity is loaded also if Makie is not loaded, which creates some unnecessary overhead.
The only solution I am aware of, is to write the extension to depend on both FirstWeakDep and ThirdDep – so that turns ThirdDep into a weak dependency as well and the extension Reads
The one difference to your prescribed scenario is, that this third dependency is not loaded, when the extension is loaded but the other way around: Only if you do using MyPackage, FirstWeakDep, ThirdDep – then the extension is loaded.
You can of course also do this as a second extension: So if FirstWeakDep and MyPackage are loaded with using you have a main ExtModule like the one you have and you load “a bit more” when ThirdDep is loaded.
The biggest risk of letting an extension load non-trigger packages and possibly other extensions is an ad hoc dependency cycle, which is an error at best and a deadlock at worst: cycle creation issue with new weakdeps code · Issue #48533 · JuliaLang/julia. I don’t know if this limitation has proven to be fundamental, but there hasn’t been much movement despite demand: Dependencies of an Extension · Issue #3641 · JuliaLang/Pkg.jl. It could very well be possible that this is just another capability of packages that extensions shouldn’t have, like making importable names.