Skip to content

Commit

Permalink
status: highlight when deps have different loaded versions (#4109)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Dec 9, 2024
1 parent f9ad1c0 commit e7c37f3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======================
Expand Down
19 changes: 19 additions & 0 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e7c37f3

Please sign in to comment.