@@ -411,6 +411,16 @@ const project_names = ("JuliaProject.toml", "Project.toml")
411411const manifest_names = (" JuliaManifest.toml" , " Manifest.toml" )
412412const preferences_names = (" JuliaLocalPreferences.toml" , " LocalPreferences.toml" )
413413
414+ function locate_project_file (env:: String )
415+ for proj in project_names
416+ project_file = joinpath (env, proj)
417+ if isfile_casesensitive (project_file)
418+ return project_file
419+ end
420+ end
421+ return true
422+ end
423+
414424# classify the LOAD_PATH entry to be one of:
415425# - `false`: nonexistant / nothing to see here
416426# - `true`: `env` is an implicit environment
@@ -423,14 +433,7 @@ function env_project_file(env::String)::Union{Bool,String}
423433 project_file === nothing || return project_file
424434 end
425435 if isdir (env)
426- for proj in project_names
427- maybe_project_file = joinpath (env, proj)
428- if isfile_casesensitive (maybe_project_file)
429- project_file = maybe_project_file
430- break
431- end
432- end
433- project_file = true
436+ project_file = locate_project_file (env)
434437 elseif basename (env) in project_names && isfile_casesensitive (env)
435438 project_file = env
436439 else
@@ -1069,11 +1072,11 @@ function require(into::Module, mod::Symbol)
10691072end
10701073
10711074mutable struct PkgOrigin
1072- # version::VersionNumber
10731075 path:: Union{String,Nothing}
10741076 cachepath:: Union{String,Nothing}
1077+ version:: Union{VersionNumber,Nothing}
10751078end
1076- PkgOrigin () = PkgOrigin (nothing , nothing )
1079+ PkgOrigin () = PkgOrigin (nothing , nothing , nothing )
10771080const pkgorigins = Dict {PkgId,PkgOrigin} ()
10781081
10791082require (uuidkey:: PkgId ) = @lock require_lock _require_prelocked (uuidkey)
@@ -1147,6 +1150,19 @@ function unreference_module(key::PkgId)
11471150 end
11481151end
11491152
1153+ function set_pkgorigin_version_path (pkg, path)
1154+ pkgorigin = get! (PkgOrigin, pkgorigins, pkg)
1155+ project_file = locate_project_file (joinpath (dirname (path), " .." ))
1156+ if project_file isa String
1157+ d = parsed_toml (project_file)
1158+ v = get (d, " version" , nothing )
1159+ if v != = nothing
1160+ pkgorigin. version = VersionNumber (v)
1161+ end
1162+ end
1163+ pkgorigin. path = path
1164+ end
1165+
11501166# Returns `nothing` or the name of the newly-created cachefile
11511167function _require (pkg:: PkgId )
11521168 # handle recursive calls to require
@@ -1163,7 +1179,7 @@ function _require(pkg::PkgId)
11631179 toplevel_load[] = false
11641180 # perform the search operation to select the module file require intends to load
11651181 path = locate_package (pkg)
1166- get! (PkgOrigin, pkgorigins, pkg) . path = path
1182+ set_pkgorigin_version_path (pkg, path)
11671183 if path === nothing
11681184 throw (ArgumentError ("""
11691185 Package $pkg is required but does not seem to be installed:
@@ -1930,7 +1946,7 @@ get_compiletime_preferences(::Nothing) = String[]
19301946 else
19311947 @label locate_branch
19321948 path = locate_package (req_key)
1933- get! (PkgOrigin, pkgorigins, req_key) . path = path
1949+ set_pkgorigin_version_path (req_key, path)
19341950 if path === nothing
19351951 @debug " Rejecting cache file $cachefile because dependency $req_key not found."
19361952 return true # Won't be able to fulfill dependency
0 commit comments