Skip to content

Package extensions not loaded when loading dependency from main environment? #49497

Closed
JuliaLang/Pkg.jl
#3451
@ranocha

Description

@ranocha

The new feature of package extensions is really nice. Thanks a lot to everybody involved!

The documentation describes package extensions basically as Requires.jl with additional benefits. However, it looks like package extensions are not loaded when loading their dependency from the main environment. I noticed this in SciML/RootedTrees.jl#111
There, I have the following code in the main package

if !isdefined(Base, :get_extension)
    using Requires: @require
end

# more code...

function _distinguishable_colors end

# more code...

function __init__()
    # more code...

    @static if !isdefined(Base, :get_extension)
        @require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" begin include("../ext/PlotsExt.jl") end
    end

    return nothing
end

and the following package extension code

module PlotsExt

if isdefined(Base, :get_extension)
    using Plots: Plots
else
    import ..Plots: Plots
end

using RootedTrees: RootedTrees

RootedTrees._distinguishable_colors(n) = Plots.distinguishable_colors(n)

end # module

The extension is loaded correctly when I set up an environment (Project.toml, Manifest.toml) including Plots.jl and RootedTrees.jl. However, when I activate the environment of RootedTrees.jl itself (julia --project=. in the development directory of this package) and load Plots.jl from my default environment, the package extension is not loaded properly. In this case, I get

julia> using Plots

julia> using RootedTrees

julia> RootedTrees._distinguishable_colors
_distinguishable_colors (generic function with 0 methods)

(RootedTrees) pkg> status --extensions
Project RootedTrees v2.18.1
Status `~/.julia/dev/RootedTrees/Project.toml`
  [23fbe1c1] Latexify v0.16.0
              ├─ DataFramesExt [DataFrames]
              └─ SymEngineExt [SymEngine]

using Julia v1.9.0-rc1. I get the expected result

julia> RootedTrees._distinguishable_colors
_distinguishable_colors (generic function with 1 method)

using Julia v1.8.5 or Julia v1.9.0-rc1 with a project environment including both RootedTrees and Plots.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions