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

Highlight manifests from other versions when failing to find packages #51613

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1774,9 +1774,10 @@ function __require(into::Module, mod::Symbol)
Package $mod not found in current path$hint_message.
- $start_sentence `import Pkg; Pkg.add($(repr(String(mod))))` to install the $mod package."""))
else
manifest_warnings = collect_manifest_warnings()
throw(ArgumentError("""
Package $(where.name) does not have $mod in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()`
$manifest_warnings- You may have a partially installed environment. Try `Pkg.instantiate()`
to ensure all packages in the environment are installed.
- Or, if you have $(where.name) checked out for development and have
added $mod as a dependency but haven't updated your primary
Expand All @@ -1795,6 +1796,55 @@ function __require(into::Module, mod::Symbol)
end
end

function find_unsuitable_manifests_versions()
unsuitable_manifests = String[]
dev_manifests = String[]
for env in load_path()
project_file = env_project_file(env)
project_file isa String || continue # no project file
manifest_file = project_file_manifest_path(project_file)
manifest_file isa String || continue # no manifest file
m = parsed_toml(manifest_file)
man_julia_version = get(m, "julia_version", nothing)
man_julia_version isa String || @goto mark
man_julia_version = VersionNumber(man_julia_version)
thispatch(man_julia_version) != thispatch(VERSION) && @goto mark
isempty(man_julia_version.prerelease) != isempty(VERSION.prerelease) && @goto mark
isempty(man_julia_version.prerelease) && continue
man_julia_version.prerelease[1] != VERSION.prerelease[1] && @goto mark
if VERSION.prerelease[1] == "DEV"
# manifests don't store the 2nd part of prerelease, so cannot check further
# so treat them specially in the warning
push!(dev_manifests, manifest_file)
end
continue
@label mark
push!(unsuitable_manifests, string(manifest_file, " (v", man_julia_version, ")"))
end
return unsuitable_manifests, dev_manifests
end

function collect_manifest_warnings()
unsuitable_manifests, dev_manifests = find_unsuitable_manifests_versions()
msg = ""
if !isempty(unsuitable_manifests)
msg *= """
- Note that the following manifests in the load path were resolved with a different
julia version, which may be the cause of the error:
$(join(unsuitable_manifests, "\n "))
"""
end
if !isempty(dev_manifests)
msg *= """
- Note that the following manifests in the load path were resolved a potentially
different DEV version of the current version, which may be the cause
of the error:
$(join(dev_manifests, "\n "))
"""
end
return msg
end

require(uuidkey::PkgId) = @lock require_lock _require_prelocked(uuidkey)

const REPL_PKGID = PkgId(UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL")
Expand Down