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 committed Jul 5, 2024
1 parent 661dffb commit 361615f
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 @@ -1484,6 +1484,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 @@ -1546,6 +1547,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 @@ -2404,6 +2406,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 @@ -2414,10 +2417,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 361615f

Please sign in to comment.