From e7c37f34293ab12051258828884755ea116b77df Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 9 Dec 2024 14:01:04 -0500 Subject: [PATCH] status: highlight when deps have different loaded versions (#4109) --- CHANGELOG.md | 1 + src/Operations.jl | 19 +++++++++++++++++++ test/new.jl | 15 +++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 056a6f1f36..7f39463873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Pkg v1.12 Release Notes - Pkg now has support for "workspaces" which is a way to resolve multiple project files into a single manifest. The functions `Pkg.status`, `Pkg.why`, `Pkg.instantiate`, `Pkg.precompile` (and their REPL variants) have been updated to take a `workspace` option. Read more about this feature in the manual about the TOML-files. +- `status` now shows when different versions/sources of dependencies are loaded than that which is expected by the manifest ([#4109]) Pkg v1.11 Release Notes ======================= diff --git a/src/Operations.jl b/src/Operations.jl index 6d6bc94558..4ade9ae4a6 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -2736,6 +2736,25 @@ function print_status(env::EnvCache, old_env::Union{Nothing,EnvCache}, registrie printstyled(io, pkg_str; color=Base.warn_color()) end end + # show if loaded version and version in the manifest doesn't match + pkg_spec = something(pkg.new, pkg.old) + pkgid = Base.PkgId(pkg.uuid, pkg_spec.name) + m = get(Base.loaded_modules, pkgid, nothing) + if m isa Module && pkg_spec.version !== nothing + loaded_path = pathof(m) + env_path = Base.locate_package(pkgid) # nothing if not installed + if loaded_path !== nothing && env_path !== nothing &&!samefile(loaded_path, env_path) + loaded_version = pkgversion(m) + env_version = pkg_spec.version + if loaded_version !== env_version + printstyled(io, " [loaded: v$loaded_version]"; color=:light_yellow) + else + loaded_version_str = loaded_version === nothing ? "" : " (v$loaded_version)" + env_version_str = env_version === nothing ? "" : " (v$env_version)" + printstyled(io, " [loaded: `$loaded_path`$loaded_version_str expected `$env_path`$env_version_str]"; color=:light_yellow) + end + end + end if extensions && !diff && pkg.extinfo !== nothing println(io) diff --git a/test/new.jl b/test/new.jl index 1b78751b71..96debeac6f 100644 --- a/test/new.jl +++ b/test/new.jl @@ -3243,4 +3243,19 @@ end end end +@testset "status showing incompatible loaded deps" begin + cmd = addenv(`$(Base.julia_cmd()) --color=no --startup-file=no -e " + using Pkg + Pkg.activate(temp=true) + Pkg.add(Pkg.PackageSpec(name=\"Example\", version=v\"0.5.4\")) + using Example + Pkg.activate(temp=true) + Pkg.add(Pkg.PackageSpec(name=\"Example\", version=v\"0.5.5\")) + "`) + iob = IOBuffer() + run(pipeline(cmd, stderr=iob, stdout=iob)) + out = String(take!(iob)) + @test occursin("[loaded: v0.5.4]", out) +end + end #module