Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for package name in [extras] for Preferences #43361

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -1722,6 +1723,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 @@ -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)
Expand Down