From d9a02ccb677475adc9f392463ad60ddfee03ce6d Mon Sep 17 00:00:00 2001 From: KristofferC Date: Tue, 15 Sep 2020 16:57:20 +0200 Subject: [PATCH] store the path to where a package got loaded --- base/loading.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index b5f44d37ca766..823e6449cc9fd 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -250,7 +250,9 @@ to get the file name part of the path. function pathof(m::Module) pkgid = get(Base.module_keys, m, nothing) pkgid === nothing && return nothing - return Base.locate_package(pkgid) + origin = get(Base.pkgorigins, pkgid, nothing) + origin === nothing && return nothing + return origin.path end """ @@ -824,18 +826,19 @@ function require(into::Module, mod::Symbol) return require(uuidkey, cache) end -struct PkgOrigin +mutable struct PkgOrigin # version::VersionNumber - # path::String + path::Union{String,Nothing} cachepath::Union{String,Nothing} end +PkgOrigin() = PkgOrigin(nothing, nothing) const pkgorigins = Dict{PkgId,PkgOrigin}() function require(uuidkey::PkgId, cache::TOMLCache=TOMLCache()) if !root_module_exists(uuidkey) cachefile = _require(uuidkey, cache) if cachefile !== nothing - pkgorigins[uuidkey] = PkgOrigin(cachefile) + get!(PkgOrigin, pkgorigins, uuidkey).cachepath = cachefile end # After successfully loading, notify downstream consumers for callback in package_callbacks @@ -907,6 +910,7 @@ function _require(pkg::PkgId, cache::TOMLCache) toplevel_load[] = false # perform the search operation to select the module file require intends to load path = locate_package(pkg, cache) + get!(PkgOrigin, pkgorigins, pkg).path = path if path === nothing throw(ArgumentError(""" Package $pkg is required but does not seem to be installed: @@ -1496,7 +1500,7 @@ function stale_cachefile(modpath::String, cachefile::String, cache::TOMLCache) end if isa(id, PkgId) - pkgorigins[id] = PkgOrigin(cachefile) + get!(PkgOrigin, pkgorigins, id).cachepath = cachefile end return depmods # fresh cachefile