@@ -1774,9 +1774,10 @@ function __require(into::Module, mod::Symbol)
17741774 Package $mod not found in current path$hint_message .
17751775 - $start_sentence `import Pkg; Pkg.add($(repr (String (mod))) )` to install the $mod package.""" ))
17761776 else
1777+ manifest_warnings = collect_manifest_warnings ()
17771778 throw (ArgumentError ("""
17781779 Package $(where . name) does not have $mod in its dependencies:
1779- - You may have a partially installed environment. Try `Pkg.instantiate()`
1780+ $manifest_warnings - You may have a partially installed environment. Try `Pkg.instantiate()`
17801781 to ensure all packages in the environment are installed.
17811782 - Or, if you have $(where . name) checked out for development and have
17821783 added $mod as a dependency but haven't updated your primary
@@ -1795,6 +1796,55 @@ function __require(into::Module, mod::Symbol)
17951796 end
17961797end
17971798
1799+ function find_unsuitable_manifests_versions ()
1800+ unsuitable_manifests = String[]
1801+ dev_manifests = String[]
1802+ for env in load_path ()
1803+ project_file = env_project_file (env)
1804+ project_file isa String || continue # no project file
1805+ manifest_file = project_file_manifest_path (project_file)
1806+ manifest_file isa String || continue # no manifest file
1807+ m = parsed_toml (manifest_file)
1808+ man_julia_version = get (m, " julia_version" , nothing )
1809+ man_julia_version isa String || @goto mark
1810+ man_julia_version = VersionNumber (man_julia_version)
1811+ thispatch (man_julia_version) != thispatch (VERSION ) && @goto mark
1812+ isempty (man_julia_version. prerelease) != isempty (VERSION . prerelease) && @goto mark
1813+ isempty (man_julia_version. prerelease) && continue
1814+ man_julia_version. prerelease[1 ] != VERSION . prerelease[1 ] && @goto mark
1815+ if VERSION . prerelease[1 ] == " DEV"
1816+ # manifests don't store the 2nd part of prerelease, so cannot check further
1817+ # so treat them specially in the warning
1818+ push! (dev_manifests, manifest_file)
1819+ end
1820+ continue
1821+ @label mark
1822+ push! (unsuitable_manifests, string (manifest_file, " (v" , man_julia_version, " )" ))
1823+ end
1824+ return unsuitable_manifests, dev_manifests
1825+ end
1826+
1827+ function collect_manifest_warnings ()
1828+ unsuitable_manifests, dev_manifests = find_unsuitable_manifests_versions ()
1829+ msg = " "
1830+ if ! isempty (unsuitable_manifests)
1831+ msg *= """
1832+ - Note that the following manifests in the load path were resolved with a different
1833+ julia version, which may be the cause of the error:
1834+ $(join (unsuitable_manifests, " \n " ))
1835+ """
1836+ end
1837+ if ! isempty (dev_manifests)
1838+ msg *= """
1839+ - Note that the following manifests in the load path were resolved a potentially
1840+ different DEV version of the current version, which may be the cause
1841+ of the error:
1842+ $(join (dev_manifests, " \n " ))
1843+ """
1844+ end
1845+ return msg
1846+ end
1847+
17981848require (uuidkey:: PkgId ) = @lock require_lock _require_prelocked (uuidkey)
17991849
18001850const REPL_PKGID = PkgId (UUID (" 3fa0cd96-eef1-5676-8a61-b3b8758bbffb" ), " REPL" )
0 commit comments