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

minimal hook into loading necessary for Pkg3 #20008

Closed
wants to merge 4 commits into from
Closed

Conversation

StefanKarpinski
Copy link
Sponsor Member

@StefanKarpinski StefanKarpinski commented Jan 13, 2017

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 for Base.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.

@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Jan 13, 2017
@@ -32,9 +32,9 @@ isinteractive() = (is_interactive::Bool)

An array of paths (as strings) where the `require` function looks for code.
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Sponsor Member Author

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.

Copy link
Contributor

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)
Copy link
Contributor

@tkelman tkelman Jan 13, 2017

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?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do.

@kshyatt kshyatt added the packages Package management and loading label Jan 13, 2017
@tkelman tkelman added the needs docs Documentation for this change is required label Jan 14, 2017
Copy link
Contributor

@tkelman tkelman left a 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.
@StefanKarpinski
Copy link
Sponsor Member Author

Closed in favor of #20120

@tkelman tkelman deleted the sk/loadhook branch February 11, 2017 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs docs Documentation for this change is required packages Package management and loading
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants