Which environment do dependencies need to be loaded from to trigger loading package extensions?

I’m a bit confused about how package extensions are loaded. The Pkg docs state

An extension will only be loaded if the extension dependencies are loaded from the same environment or environments higher in the environment stack than the package itself.

To me, this suggests that if I have activated a package’s environment, and try loading a package from the default environment which lies below the current one in the load path, the package extension won’t be loaded. To try this out, I have installed Plots in my default (v1.9) environment, and have created a shell package as

src/temp.jl:

module temp

struct Temp end

end # module temp

ext/tempPlotsExt.jl:

module tempPlotsExt

using Plots
using temp

Plots.plot(::temp.Temp) = plot(1:3)

end

Project.toml:

name = "temp"
uuid = "cdfd31ad-e272-4ac9-9e50-4addabb390bb"
version = "0.1.0"

[weakdeps]
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[extensions]
tempPlotsExt = "Plots"

[compat]
Plots = "1"

Now, I have activated the temp environment, and find that

julia> using temp

julia> using Plots
[ Info: Precompiling tempPlotsExt [4fe59103-d0cf-5388-a243-d7b63099fc07]

julia> plot(temp.Temp()) # generates the plot
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

julia> Base.load_path()
4-element Vector{String}:
 "/home/jishnu/Dropbox/JuliaPackages/temp/Project.toml"
 "/tmp/jl_RgAHq2"
 "/home/jishnu/.julia/environments/v1.9/Project.toml" # Plots is here
 "/home/jishnu/packages/julias/julia-1.9/share/julia/stdlib/v1.9"

The extension is loaded! Why is this working, when Plots is lower in the stack?

It seems this behavior has been changed in

but the docs have not been updated. The Pkg docs point to v1.9.0, and not v1.9.1+ that implements this feature. In fact, there doesn’t appear to be Pkg tags for v1.9.1+ which leads to this documentation issue.

1 Like