From a1dd8017d655d18582c0069f01ccf077e54f34f2 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 7 Dec 2021 17:06:45 -0500 Subject: [PATCH] Look for package name in `[extras]` for Preferences (#43361) * 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 Co-authored-by: Elliot Saba (cherry picked from commit 8197c418e1d806f5faf1fd900c78068ea8046e1d) --- base/loading.jl | 13 ++++++++++++- test/loading.jl | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index 2b1f934ff6ffeb..d406d3a409737e 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1652,7 +1652,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} @@ -1667,6 +1668,16 @@ function get_uuid_name(project::Dict{String, Any}, uuid::UUID) end end end + 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 return nothing end diff --git a/test/loading.jl b/test/loading.jl index c56f6c463a21f5..3970813fbd29b8 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -189,6 +189,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)