Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status: highlight when deps have different loaded versions #4109

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are so many ways to get the path to a package, could also for example use pkgorigins but this should be fine as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkgorigins only works for loaded packages? This line's the src as found based on the env, i.e. what loading would find. I thought locate_package would be the closest to the actual loading mechanics? If there's a more proper way then let's use it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading