Skip to content

Commit

Permalink
Look for package name in [extras] for Preferences (#43361)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
vchuravy authored and KristofferC committed Dec 9, 2021
1 parent 2844d96 commit a1dd801
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
13 changes: 12 additions & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

Expand Down
36 changes: 36 additions & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a1dd801

Please sign in to comment.