Skip to content

Commit f1eb1ec

Browse files
KristofferCtopolarity
authored andcommitted
[backports-release-1.10] allow extensions to trigger from packages in [deps] (JuliaLang#54009)
There is a use case where you have a weak dependency (for one of your extensions) that is misbehaving and you quickly want to try debug that issue. A workflow that feels reasonable for this could be: ``` pkg> dev WeakDependency julia> using Package, WeakDependency ``` This doesn't work right now for two reasons: 1. Doing the `dev WeakDependency` will add the dependency to `[deps]` but not remove it from `[weakdeps]` which means you all of a sudden are in the scenario described in https://pkgdocs.julialang.org/v1/creating-packages/#Transition-from-normal-dependency-to-extension which is not what is desired. 2. The extension will not actually load because you can right now only trigger extensions from weak deps getting loaded, not from deps getting loaded. Point 1. is fixed by JuliaLang/Pkg.jl#3865 Point 2. is fixed by this PR. (cherry picked from commit f46cb4c)
1 parent 85aecff commit f1eb1ec

File tree

13 files changed

+1125
-34
lines changed

13 files changed

+1125
-34
lines changed

base/loading.jl

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,12 +1211,13 @@ function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missi
12111211
proj_pkg = project_file_name_uuid(project_file, pkg.name)
12121212
if pkg == proj_pkg
12131213
d_proj = parsed_toml(project_file)
1214-
weakdeps = get(d_proj, "weakdeps", nothing)::Union{Nothing, Vector{String}, Dict{String,Any}}
12151214
extensions = get(d_proj, "extensions", nothing)::Union{Nothing, Dict{String, Any}}
12161215
extensions === nothing && return
1217-
weakdeps === nothing && return
1218-
if weakdeps isa Dict{String, Any}
1219-
return _insert_extension_triggers(pkg, extensions, weakdeps)
1216+
weakdeps = get(Dict{String, Any}, d_proj, "weakdeps")::Union{Vector{String}, Dict{String,Any}}
1217+
deps = get(Dict{String, Any}, d_proj, "deps")::Union{Vector{String}, Dict{String,Any}}
1218+
if weakdeps isa Dict{String,Any} && deps isa Dict{String,Any}
1219+
total_deps = merge(weakdeps, deps)
1220+
return _insert_extension_triggers(pkg, extensions, total_deps)
12201221
end
12211222
end
12221223

@@ -1231,35 +1232,43 @@ function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missi
12311232
uuid = get(entry, "uuid", nothing)::Union{String, Nothing}
12321233
uuid === nothing && continue
12331234
if UUID(uuid) == pkg.uuid
1234-
weakdeps = get(entry, "weakdeps", nothing)::Union{Nothing, Vector{String}, Dict{String,Any}}
12351235
extensions = get(entry, "extensions", nothing)::Union{Nothing, Dict{String, Any}}
12361236
extensions === nothing && return
1237-
weakdeps === nothing && return
1238-
if weakdeps isa Dict{String, Any}
1239-
return _insert_extension_triggers(pkg, extensions, weakdeps)
1237+
weakdeps = get(Dict{String, Any}, entry, "weakdeps")::Union{Vector{String}, Dict{String,Any}}
1238+
deps = get(Dict{String, Any}, entry, "deps")::Union{Vector{String}, Dict{String,Any}}
1239+
1240+
function expand_deps_list(deps′::Vector{String})
1241+
deps′_expanded = Dict{String, Any}()
1242+
for (dep_name, entries) in d
1243+
dep_name in deps′ || continue
1244+
entries::Vector{Any}
1245+
if length(entries) != 1
1246+
error("expected a single entry for $(repr(dep_name)) in $(repr(project_file))")
1247+
end
1248+
entry = first(entries)::Dict{String, Any}
1249+
uuid = entry["uuid"]::String
1250+
deps′_expanded[dep_name] = uuid
1251+
end
1252+
return deps′_expanded
12401253
end
12411254

1242-
d_weakdeps = Dict{String, Any}()
1243-
for (dep_name, entries) in d
1244-
dep_name in weakdeps || continue
1245-
entries::Vector{Any}
1246-
if length(entries) != 1
1247-
error("expected a single entry for $(repr(dep_name)) in $(repr(project_file))")
1248-
end
1249-
entry = first(entries)::Dict{String, Any}
1250-
uuid = entry["uuid"]::String
1251-
d_weakdeps[dep_name] = uuid
1255+
if weakdeps isa Vector{String}
1256+
weakdeps = expand_deps_list(weakdeps)
12521257
end
1253-
@assert length(d_weakdeps) == length(weakdeps)
1254-
return _insert_extension_triggers(pkg, extensions, d_weakdeps)
1258+
if deps isa Vector{String}
1259+
deps = expand_deps_list(deps)
1260+
end
1261+
1262+
total_deps = merge(weakdeps, deps)
1263+
return _insert_extension_triggers(pkg, extensions, total_deps)
12551264
end
12561265
end
12571266
end
12581267
end
12591268
return nothing
12601269
end
12611270

1262-
function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}, weakdeps::Dict{String, Any})
1271+
function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}, totaldeps::Dict{String, Any})
12631272
for (ext, triggers) in extensions
12641273
triggers = triggers::Union{String, Vector{String}}
12651274
triggers isa String && (triggers = [triggers])
@@ -1273,7 +1282,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}
12731282
push!(trigger1, gid)
12741283
for trigger in triggers
12751284
# TODO: Better error message if this lookup fails?
1276-
uuid_trigger = UUID(weakdeps[trigger]::String)
1285+
uuid_trigger = UUID(totaldeps[trigger]::String)
12771286
trigger_id = PkgId(uuid_trigger, trigger)
12781287
if !haskey(Base.loaded_modules, trigger_id) || haskey(package_locks, trigger_id)
12791288
trigger1 = get!(Vector{ExtensionId}, EXT_DORMITORY, trigger_id)

0 commit comments

Comments
 (0)