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
minimal hook into loading needed for Pkg3 (take 2) #20120
Conversation
Could you elaborate? That's something that this change makes happen but wasn't happening before? Are we going to want to keep that behavior, or would it be a temporary only-during-0.6 accident? |
It seems like the way julia> using ModInts
find_in_path("ModInts", nothing)
ERROR: ArgumentError: Module ModInts not found in current path.
Run `Pkg.add("ModInts")` to install the ModInts package.
Stacktrace:
[1] require(::Symbol) at ./loading.jl:403
julia> Base.find_in_path("ModInts")
find_in_path("ModInts", "/Users/stefan/projects/julia/examples")
"/Users/stefan/projects/julia/examples/ModInts.jl" However, there's a theoretical problem that doesn't happen in practice because of syntax limitations on what you can actually write after julia> eval(:(using $(Symbol(abspath("ModInts.jl")))))
find_in_path("/Users/stefan/projects/julia/examples/ModInts.jl", nothing)
WARNING: requiring "/Users/stefan/projects/julia/examples/ModInts.jl" in module "Main" did not define a corresponding module. That's a pretty contrived situation, but the point is that there are two kinds of code lookup that should be cleanly separated but are currently entangled: |
I made the test more realistic by having it call |
Thanks, that does sound mostly contrived, guess we'll see one way or another once pkgeval actually works correctly on nightly again. I think for the sake of schedules we should go for the imperfect but "good enough to do the job for now" version. Do we want to document this or is it going to be a "for Stefan's use only" feature until we do a proper cleaner version that decouples everything, post-0.6? |
Others are welcome to use this, with the caveat that we might still change it, which will break stuff :) |
I should note that custom loaders do not work when you define the custom loader in the REPL, but they do work if defined in a package that is loaded via |
Example usage via a dummy shell> cat tmp/Pkg3.jl
module Pkg3
immutable Loader; path::String; end
import Base.load_hook
load_hook(loader::Loader, name::String, found) = load_hook(loader.path, name, found)
end
julia> push!(LOAD_PATH, abspath("tmp"))
3-element Array{Any,1}:
"/Users/stefan/projects/julia/usr/local/share/julia/site/v0.6"
"/Users/stefan/projects/julia/usr/share/julia/site/v0.6"
"/Users/stefan/projects/julia/tmp"
julia> using Pkg3
julia> using ModInts
ERROR: ArgumentError: Module ModInts not found in current path.
Run `Pkg.add("ModInts")` to install the ModInts package.
Stacktrace:
[1] require(::Symbol) at ./loading.jl:403
julia> push!(LOAD_PATH, Pkg3.Loader("examples"))
4-element Array{Any,1}:
"/Users/stefan/projects/julia/usr/local/share/julia/site/v0.6"
"/Users/stefan/projects/julia/usr/share/julia/site/v0.6"
"/Users/stefan/projects/julia/tmp"
Pkg3.Loader("examples")
julia> using ModInts |
@@ -32,9 +32,9 @@ isinteractive() = (is_interactive::Bool) | |||
|
|||
An array of paths (as strings) where the `require` function looks for code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(as strings, or ... )
We seem to have a bug randomly affecting |
Tests all pass. Unless there are objections from anyone (@vtjnash?), I'll merge tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this should work
@@ -30,11 +30,22 @@ isinteractive() = (is_interactive::Bool) | |||
""" | |||
LOAD_PATH | |||
|
|||
An array of paths (as strings) where the `require` function looks for code. | |||
An array of paths as strings, or custom loader object where the `require` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
objects
lgtm. there's a comment on https://github.com/JuliaLang/julia/pull/20120/files#diff-a03d5ce5729a81495000698e643fce27R322 ( |
12edbc4
to
ac5c718
Compare
I think the comment's a little bit wrong, since (wrong button sorry) |
Overload Base.load_hook to handle special types in LOAD_PATH
The correct solution here is to serialize the code that's currently generated as a string the way that the load cache code works – i.e. using proper de/serialization.
ac5c718
to
708a757
Compare
Yeah, I'm just going to ignore that comment for now – I've undeleted that change. |
Unfortunately, I've now wiggled this around enough that I can't just trust a merge – I'll have to wait until the tests pass again. |
Arguably, the behavior that this can cause loading via
using
andimport
from the current working directory is a bug which is somewhat mitigated by this additional patch:However, I'm not sure if that's a safe change so I'm leaving it out of this. Note that the
cd
to..
and back intest/loading.jl
is to avoid what I think is a pre-existing bug infind_in_path
. If packages and/or edit are relying on this, they should stop doing so.edit by tkelman: closes #8059