Understanding dependencies of packages extensions

I have a package and I’m extending a function to create plots. The main package depends on another third package, let’s say StaticArrays for simplicity, and the extension also uses the functions of StaticArrays. Should StaticArrays be also a weakdep for the extension?

Something like:

module MainPkg
    using StaticArrays
    export f
    function f end


module MyPkgExtension
    using Plots # the heavy weakdep
    using StaticArrays # should this be also a weakdep? Is it available?
    using MyPkg
    MyPkg.f(x::SVector) = plot(x)

I’m unsure if StaticArrays should be also a weakdep, and also if it is automatically “available” in the MyPkgExtension module for being a hard dependency of MyPkg.

From my tests it seems to be available, but I feel like doing something that can break easily.

I’m bumping this to understand better how extensions are implemented: are they to be seen as “nested modules” within the main package?

All the packages that are dependencies of the main package are already part of the environment of the extension?

It seems to be, but this is not explicitly written in the docs, so it feels now like trial-and-error.

I think one is only supposed to load the targets for the extension. Other dependencies are to be loaded transitively, e.g. as using MainPkg.StaticArrays, instead of using StaticArrays. This avoids cycles in package loading.

Although I’ve not kept up with the development, and this may not be necessary anymore.

1 Like

Uhm, in my package where I do not do this “properly”, meaning, I don’t load the dependency by MainPkg.StaticArrays, I don’t get any warning or error message on Julia nightly, and the dev docs don’t mention that either. So it is unclear there if one should be careful with that, or no.

Yes, this is somewhat of a new development, and it’s not documented at all. I guess this is because the behaviour is still in flux

1 Like

Nevertheless, when I changed my package to import the packages from the main package, I started getting these warnings:

[ Info: Precompiling ComplexMixturesPlotting [72ee4039-6c6c-5d3e-ab5f-b48662531fd4]
┌ Warning: Module ComplexMixtures with build ID fafbfcfd-adc6-8079-0006-28dffa1c20f0 is missing from the cache.
│ This may mean ComplexMixtures [6f35c628-ac57-5bae-8ea9-703a8964f6e9] does not support precompilation but is imported by a module that does.
└ @ Base loading.jl:1948
[ Info: Skipping precompilation since __precompile__(false). Importing ComplexMixturesPlotting [72ee4039-6c6c-5d3e-ab5f-b48662531fd4].