Skip to content

Commit

Permalink
make add and dev on a package remove it from the set of weak depe…
Browse files Browse the repository at this point in the history
…ndencies (#3865)

* make `add` and `dev` on a package remove it from the weakdeps section
  • Loading branch information
KristofferC authored Apr 10, 2024
1 parent 9210a1d commit 88c38b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=Set{UUID}();
assert_can_add(ctx, pkgs)
# load manifest data
for (i, pkg) in pairs(pkgs)
delete!(ctx.env.project.weakdeps, pkg.name)
entry = manifest_info(ctx.env.manifest, pkg.uuid)
is_dep = any(uuid -> uuid == pkg.uuid, [uuid for (name, uuid) in ctx.env.project.deps])
source_path, source_repo = get_path_repo(ctx.env.project, pkg.name)
Expand Down Expand Up @@ -1545,6 +1546,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}, new_git::Set{UUID};
assert_can_add(ctx, pkgs)
# no need to look at manifest.. dev will just nuke whatever is there before
for pkg in pkgs
delete!(ctx.env.project.weakdeps, pkg.name)
ctx.env.project.deps[pkg.name] = pkg.uuid
end
# resolve & apply package versions
Expand Down Expand Up @@ -2403,6 +2405,7 @@ function status_ext_info(pkg::PackageSpec, env::EnvCache)
manifest = env.manifest
manifest_info = get(manifest, pkg.uuid, nothing)
manifest_info === nothing && return nothing
depses = manifest_info.deps
weakdepses = manifest_info.weakdeps
exts = manifest_info.exts
if !isempty(weakdepses) && !isempty(exts)
Expand All @@ -2413,10 +2416,14 @@ function status_ext_info(pkg::PackageSpec, env::EnvCache)
# Check if deps are loaded
extdeps_info= Tuple{String, Bool}[]
for extdep in extdeps
haskey(weakdepses, extdep) ||
pkgerror(isnothing(pkg.name) ? "M" : "$(pkg.name) has a m",
"alformed Project.toml, the extension package $extdep is not listed in [weakdeps]")
uuid = weakdepses[extdep]
if !(haskey(weakdepses, extdep) || haskey(depses, extdep))
pkgerror(isnothing(pkg.name) ? "M" : "$(pkg.name) has a malformed Project.toml, ",
"the extension package $extdep is not listed in [weakdeps] or [deps]")
end
uuid = get(weakdepses, extdep, nothing)
if uuid === nothing
uuid = depses[extdep]
end
loaded = haskey(Base.loaded_modules, Base.PkgId(uuid, extdep))
push!(extdeps_info, (extdep, loaded))
end
Expand Down
9 changes: 9 additions & 0 deletions test/extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ using UUIDs
Pkg.activate(joinpath(dir, "TestWeakDepProject"))
Pkg.resolve()
@test Pkg.dependencies()[UUID("2ab3a3ac-af41-5b50-aa03-7779005ae688")].version == v"0.3.26"

# Check that explicitly adding a package that is a weak dep removes it from the set of weak deps
ctx = Pkg.Types.Context()
@test "LogExpFunctions" in keys(ctx.env.project.weakdeps)
@test !("LogExpFunctions" in keys(ctx.env.project.deps))
Pkg.add("LogExpFunctions")
ctx = Pkg.Types.Context()
@test "LogExpFunctions" in keys(ctx.env.project.deps)
@test !("LogExpFunctions" in keys(ctx.env.project.weakdeps))
end
end
end

0 comments on commit 88c38b2

Please sign in to comment.