Skip to content

Commit 8197c41

Browse files
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]>
1 parent 2e9bbda commit 8197c41

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

base/loading.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,8 @@ function srctext_files(f::IO, srctextpos::Int64)
17071707
end
17081708

17091709
# Test to see if this UUID is mentioned in this `Project.toml`; either as
1710-
# the top-level UUID (e.g. that of the project itself) or as a dependency.
1710+
# the top-level UUID (e.g. that of the project itself), as a dependency,
1711+
# or as a extra for Preferences.
17111712
function get_uuid_name(project::Dict{String, Any}, uuid::UUID)
17121713
uuid_p = get(project, "uuid", nothing)::Union{Nothing, String}
17131714
name = get(project, "name", nothing)::Union{Nothing, String}
@@ -1722,6 +1723,16 @@ function get_uuid_name(project::Dict{String, Any}, uuid::UUID)
17221723
end
17231724
end
17241725
end
1726+
for subkey in ("deps", "extras")
1727+
subsection = get(project, subkey, nothing)::Union{Nothing, Dict{String, Any}}
1728+
if subsection !== nothing
1729+
for (k, v) in subsection
1730+
if uuid == UUID(v::String)
1731+
return k
1732+
end
1733+
end
1734+
end
1735+
end
17251736
return nothing
17261737
end
17271738

test/loading.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,42 @@ end
178178
end
179179
end
180180

181+
# extras
182+
@testset "extras" begin
183+
mktempdir() do dir
184+
project_file = joinpath(dir, "Project.toml")
185+
touch(project_file) # dummy_uuid calls realpath
186+
# various UUIDs to work with
187+
proj_uuid = dummy_uuid(project_file)
188+
root_uuid = uuid4()
189+
this_uuid = uuid4()
190+
191+
old_load_path = copy(LOAD_PATH)
192+
try
193+
copy!(LOAD_PATH, [project_file])
194+
write(project_file, """
195+
name = "Root"
196+
uuid = "$root_uuid"
197+
[extras]
198+
This = "$this_uuid"
199+
""")
200+
# look up various packages by name
201+
root = Base.identify_package("Root")
202+
this = Base.identify_package("This")
203+
that = Base.identify_package("That")
204+
205+
@test root.uuid == root_uuid
206+
@test this == nothing
207+
@test that == nothing
208+
209+
@test Base.get_uuid_name(project_file, this_uuid) == "This"
210+
finally
211+
copy!(LOAD_PATH, old_load_path)
212+
end
213+
end
214+
end
215+
216+
181217
## functional testing of package identification, location & loading ##
182218

183219
saved_load_path = copy(LOAD_PATH)

0 commit comments

Comments
 (0)