Skip to content

Commit 3028ade

Browse files
authored
store the path to where a package got loaded (#37586)
1 parent bfa7261 commit 3028ade

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

base/loading.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ to get the file name part of the path.
250250
function pathof(m::Module)
251251
pkgid = get(Base.module_keys, m, nothing)
252252
pkgid === nothing && return nothing
253-
return Base.locate_package(pkgid)
253+
origin = get(Base.pkgorigins, pkgid, nothing)
254+
origin === nothing && return nothing
255+
return origin.path
254256
end
255257

256258
"""
@@ -824,18 +826,19 @@ function require(into::Module, mod::Symbol)
824826
return require(uuidkey, cache)
825827
end
826828

827-
struct PkgOrigin
829+
mutable struct PkgOrigin
828830
# version::VersionNumber
829-
# path::String
831+
path::Union{String,Nothing}
830832
cachepath::Union{String,Nothing}
831833
end
834+
PkgOrigin() = PkgOrigin(nothing, nothing)
832835
const pkgorigins = Dict{PkgId,PkgOrigin}()
833836

834837
function require(uuidkey::PkgId, cache::TOMLCache=TOMLCache())
835838
if !root_module_exists(uuidkey)
836839
cachefile = _require(uuidkey, cache)
837840
if cachefile !== nothing
838-
pkgorigins[uuidkey] = PkgOrigin(cachefile)
841+
get!(PkgOrigin, pkgorigins, uuidkey).cachepath = cachefile
839842
end
840843
# After successfully loading, notify downstream consumers
841844
for callback in package_callbacks
@@ -907,6 +910,7 @@ function _require(pkg::PkgId, cache::TOMLCache)
907910
toplevel_load[] = false
908911
# perform the search operation to select the module file require intends to load
909912
path = locate_package(pkg, cache)
913+
get!(PkgOrigin, pkgorigins, pkg).path = path
910914
if path === nothing
911915
throw(ArgumentError("""
912916
Package $pkg is required but does not seem to be installed:
@@ -1496,7 +1500,7 @@ function stale_cachefile(modpath::String, cachefile::String, cache::TOMLCache)
14961500
end
14971501

14981502
if isa(id, PkgId)
1499-
pkgorigins[id] = PkgOrigin(cachefile)
1503+
get!(PkgOrigin, pkgorigins, id).cachepath = cachefile
15001504
end
15011505

15021506
return depmods # fresh cachefile

0 commit comments

Comments
 (0)