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

store the path to where a package got loaded #37586

Merged
merged 1 commit into from
Sep 16, 2020
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
14 changes: 9 additions & 5 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down