From 16757cd7dd8cbff31e175c11e676be28a2648bce Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 7 Dec 2021 12:45:46 -0500 Subject: [PATCH 1/2] Look for package name in `[extras]` When Preferences.jl set's a preferences in a non-top-level package, it adds that package to the `[extras]` entries in the project path. Package loading should have used thhose entries to map the module uuid to the key name in the Preferences.toml Fixes https://github.com/JuliaPackaging/Preferences.jl/issues/24 --- base/loading.jl | 11 ++++++++++- test/loading.jl | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index e3352d0d0b4ae..8bb48ee55be67 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1707,7 +1707,8 @@ function srctext_files(f::IO, srctextpos::Int64) end # Test to see if this UUID is mentioned in this `Project.toml`; either as -# the top-level UUID (e.g. that of the project itself) or as a dependency. +# the top-level UUID (e.g. that of the project itself), as a dependency, +# or as a extra for Preferences. function get_uuid_name(project::Dict{String, Any}, uuid::UUID) uuid_p = get(project, "uuid", nothing)::Union{Nothing, String} name = get(project, "name", nothing)::Union{Nothing, String} @@ -1722,6 +1723,14 @@ function get_uuid_name(project::Dict{String, Any}, uuid::UUID) end end end + extras = get(project, "extras", nothing)::Union{Nothing, Dict{String, Any}} + if extras !== nothing + for (k, v) in extras + if uuid == UUID(v::String) + return k + end + end + end return nothing end diff --git a/test/loading.jl b/test/loading.jl index 89d61207e33d9..b9fb50a3287c1 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -178,6 +178,42 @@ end end end +# extras +@testset "extras" begin + mktempdir() do dir + project_file = joinpath(dir, "Project.toml") + touch(project_file) # dummy_uuid calls realpath + # various UUIDs to work with + proj_uuid = dummy_uuid(project_file) + root_uuid = uuid4() + this_uuid = uuid4() + + old_load_path = copy(LOAD_PATH) + try + copy!(LOAD_PATH, [project_file]) + write(project_file, """ + name = "Root" + uuid = "$root_uuid" + [extras] + This = "$this_uuid" + """) + # look up various packages by name + root = Base.identify_package("Root") + this = Base.identify_package("This") + that = Base.identify_package("That") + + @test root.uuid == root_uuid + @test this == nothing + @test that == nothing + + @test Base.get_uuid_name(project_file, this_uuid) == "This" + finally + copy!(LOAD_PATH, old_load_path) + end + end +end + + ## functional testing of package identification, location & loading ## saved_load_path = copy(LOAD_PATH) From 40142b60182a15a807784e5773fda03d0abd0058 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 7 Dec 2021 14:36:33 -0500 Subject: [PATCH 2/2] Update base/loading.jl Co-authored-by: Elliot Saba --- base/loading.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index 8bb48ee55be67..0cbf0a52b9e68 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1723,11 +1723,13 @@ function get_uuid_name(project::Dict{String, Any}, uuid::UUID) end end end - extras = get(project, "extras", nothing)::Union{Nothing, Dict{String, Any}} - if extras !== nothing - for (k, v) in extras - if uuid == UUID(v::String) - return k + for subkey in ("deps", "extras") + subsection = get(project, subkey, nothing)::Union{Nothing, Dict{String, Any}} + if subsection !== nothing + for (k, v) in subsection + if uuid == UUID(v::String) + return k + end end end end