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

**URL:** <https://discourse.julialang.org/t/which-environment-do-dependencies-need-to-be-loaded-from-to-trigger-loading-package-extensions/101952>\
**Category:** General Usage\
**Tags:** pkg, package-extensions\
**Created:** [July 23, 2023, 8:48am UTC](https://discourse.julialang.org/t/which-environment-do-dependencies-need-to-be-loaded-from-to-trigger-loading-package-extensions/101952 "2023-07-23T08:48:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [July 23, 2023, 8:48am UTC](https://discourse.julialang.org/t/which-environment-do-dependencies-need-to-be-loaded-from-to-trigger-loading-package-extensions/101952/1 "2023-07-23T08:48:16Z")

</div>

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`:

```julia
module temp

struct Temp end

end # module temp

```

`ext/tempPlotsExt.jl`:

```julia
module tempPlotsExt

using Plots
using temp

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

end

```

`Project.toml`:

```julia
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
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?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [July 23, 2023, 8:54am UTC](https://discourse.julialang.org/t/which-environment-do-dependencies-need-to-be-loaded-from-to-trigger-loading-package-extensions/101952/2 "2023-07-23T08:54:27Z")

</div>

It seems this behavior has been changed in

> <https://github.com/JuliaLang/julia/pull/49701>
>
> @topolarity has convinced me that this makes sense.
> 
> As it is right now, an ex…tension gets loaded only if the trigger is above (or at the same place) as the parent in the load path. 
> This is kind of a symmetry break because, from the extension's point of view, there isn't really any difference between the parent and one of the triggers. Both of these are just dependencies.
> The extension could be shifted from the parent to the trigger without any change of functionality.
> So then why does code loading differ between these two cases?
> 
> With this PR, the extension will load no matter the relationship of load paths between the parent and triggers.
> 
> This also avoids the complication in https://github.com/JuliaLang/julia/pull/49681.
> 
> cc @vtjnash, @topolarity 
> 
> ~Also, a TODO is that extensions should probably be loadable if the parent is the active project (which would need to add some code to look up extensions in Project.toml files, right now it only looks in \`Manifest.toml\`). Fortunately, I envisioned maybe having to do this so I saved some code I ripped out earlier that implements this: https://gist.github.com/KristofferC/e5c9e80db0f056ab1f72714c46477a02.~
> 
> ^Done
> 
> Fixes https://github.com/JuliaLang/julia/issues/49656

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.
