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 necessary for Pkg3 #20008
Conversation
@@ -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.
needs some doc updating
let paddedname = "Ztest_sourcepath.jl" | ||
filename = SubString(paddedname, 2, length(paddedname)) | ||
@test Base.find_in_path(filename) == abspath(paddedname[2:end]) | ||
empty!(LOAD_PATH) |
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.
should probably restore prior value when done?
@@ -720,6 +720,12 @@ Get the name of a generic `Function` as a symbol, or `:anonymous`. | |||
""" | |||
function_name(f::Function) = typeof(f).name.mt.name | |||
|
|||
function find_source_file(file::String) |
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.
does this get called on package 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.
No, it's only used in this file and, as far as I can tell, doesn't actually rely on find in path behavior at all in practice anymore.
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.
calling edit on a method from a package?
|
||
# `wd` is a working directory to search. defaults to current working directory. | ||
# if `wd === nothing`, no extra path is searched. | ||
function find_in_path(name::String, wd) |
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.
Blink, PkgDev, and node-julia are using the 2 arg version of this. And ClobberingReload is using find_in_node_path. deprecate?
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.
Ok, will do.
0851bf6
to
e655337
Compare
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.
The change to find_source_file
breaks edit("Example.jl")
. 2-arg find_in_path
, and find_in_node_path
should be deprecated.
This is used by the generic Base.find_in_path function to look up a name in each successive entry in [Pkg.dir(); LOAD_PATH]. In this commit, this doesn't allow any custom loading since LOAD_PATH can still only contain values of type String.
To implement custom module loading, define Base.load_hook method for a custom type that returns a path to the file to be loaded. This mechanism can, for example, be used to allow Pkg3 to hook into code loading, organizing files quite differently from Base. Note that unlike standard LOAD_PATH search, which uses the first possible path found, custom mechanisms can continue searching.
e655337
to
9bdf42e
Compare
Closed in favor of #20120 |
This is a less disruptive alternative to #19910 and #19866. Doesn't really change anything, just makes how code gets loaded extensible via putting things that aren't Strings in
LOAD_PATH
and defining appropriate methods forBase.load_hook
.It does also remove searching for files relative to the current directory behavior, but I don't think that was used by anything except for the reflection code, I've now factored out.