Skip to content

Commit 0a921be

Browse files
vchuravyKristofferC
authored andcommitted
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 JuliaPackaging/Preferences.jl#24 Co-authored-by: Elliot Saba <[email protected]> (cherry picked from commit 8197c41)
1 parent b54efed commit 0a921be

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

base/loading.jl

+12-1
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,8 @@ function srctext_files(f::IO, srctextpos::Int64)
16521652
end
16531653

16541654
# Test to see if this UUID is mentioned in this `Project.toml`; either as
1655-
# the top-level UUID (e.g. that of the project itself) or as a dependency.
1655+
# the top-level UUID (e.g. that of the project itself), as a dependency,
1656+
# or as a extra for Preferences.
16561657
function get_uuid_name(project::Dict{String, Any}, uuid::UUID)
16571658
uuid_p = get(project, "uuid", nothing)::Union{Nothing, String}
16581659
name = get(project, "name", nothing)::Union{Nothing, String}
@@ -1667,6 +1668,16 @@ function get_uuid_name(project::Dict{String, Any}, uuid::UUID)
16671668
end
16681669
end
16691670
end
1671+
for subkey in ("deps", "extras")
1672+
subsection = get(project, subkey, nothing)::Union{Nothing, Dict{String, Any}}
1673+
if subsection !== nothing
1674+
for (k, v) in subsection
1675+
if uuid == UUID(v::String)
1676+
return k
1677+
end
1678+
end
1679+
end
1680+
end
16701681
return nothing
16711682
end
16721683

test/loading.jl

+36
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,42 @@ end
189189
end
190190
end
191191

192+
# extras
193+
@testset "extras" begin
194+
mktempdir() do dir
195+
project_file = joinpath(dir, "Project.toml")
196+
touch(project_file) # dummy_uuid calls realpath
197+
# various UUIDs to work with
198+
proj_uuid = dummy_uuid(project_file)
199+
root_uuid = uuid4()
200+
this_uuid = uuid4()
201+
202+
old_load_path = copy(LOAD_PATH)
203+
try
204+
copy!(LOAD_PATH, [project_file])
205+
write(project_file, """
206+
name = "Root"
207+
uuid = "$root_uuid"
208+
[extras]
209+
This = "$this_uuid"
210+
""")
211+
# look up various packages by name
212+
root = Base.identify_package("Root")
213+
this = Base.identify_package("This")
214+
that = Base.identify_package("That")
215+
216+
@test root.uuid == root_uuid
217+
@test this == nothing
218+
@test that == nothing
219+
220+
@test Base.get_uuid_name(project_file, this_uuid) == "This"
221+
finally
222+
copy!(LOAD_PATH, old_load_path)
223+
end
224+
end
225+
end
226+
227+
192228
## functional testing of package identification, location & loading ##
193229

194230
saved_load_path = copy(LOAD_PATH)

0 commit comments

Comments
 (0)