From 361615f229f6a8d5772779bd16ea72e5eb25043c Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Wed, 10 Apr 2024 11:17:16 +0200 Subject: [PATCH] make `add` and `dev` on a package remove it from the set of weak dependencies (#3865) * make `add` and `dev` on a package remove it from the weakdeps section --- src/Operations.jl | 15 +++++++++++---- test/extensions.jl | 9 +++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index d6273769b9..4b19c50bb5 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -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) @@ -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 @@ -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) @@ -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 diff --git a/test/extensions.jl b/test/extensions.jl index d46b358bb6..f80265bf37 100644 --- a/test/extensions.jl +++ b/test/extensions.jl @@ -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