Skip to content

Commit

Permalink
improve require deprecation
Browse files Browse the repository at this point in the history
ref #13107
  • Loading branch information
JeffBezanson committed Sep 14, 2015
1 parent 0811704 commit 615e746
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
32 changes: 27 additions & 5 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -661,14 +661,36 @@ end

## require ##

function maybe_require_file(name::AbstractString)
isabspath(name) && return name
isfile(name) && return abspath(name)
if !endswith(name,".jl")
fname = string(name,".jl")
isfile(fname) && return abspath(fname)
end
return name
end

include("require.jl")
@noinline function require(f::AbstractString)
if !(endswith(f,".jl") || contains(f,path_separator))
# for require("Name") this function shouldn't be needed at all
error("use `using` or `import` to load packages")
end
depwarn("`require` is deprecated, use `using` or `import` instead", :require)
OldRequire.require(f)
if endswith(f,".jl") || contains(f,path_separator)
# specifying file path
OldRequire.require(f)
else
# require("Foo") --- ambiguous. might be file or package
filename = maybe_require_file(f)
if filename == f
mod = symbol(require_modname(f))
M = current_module()
if isdefined(M,mod) && isa(eval(M,mod),Module)
return
end
require(mod)
else
OldRequire.require(f)
end
end
end
@noinline function require(f::AbstractString, fs::AbstractString...)
require(f)
Expand Down
4 changes: 2 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function __precompile__(isprecompilable::Bool=true)
end
end

function require_filename(name::AbstractString)
function require_modname(name::AbstractString)
# This function can be deleted when the deprecation for `require`
# is deleted.
# While we could also strip off the absolute path, the user may be
Expand Down Expand Up @@ -192,7 +192,7 @@ function reload(name::AbstractString)
error("use `include` instead of `reload` to load source files")
else
# reload("Package") is ok
require(symbol(require_filename(name)))
require(symbol(require_modname(name)))
end
end

Expand Down
2 changes: 1 addition & 1 deletion base/require.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function find_in_path(name::AbstractString)
name = string(base,".jl")
isfile(name) && return abspath(name)
end
for prefix in [Pkg.dir(), LOAD_PATH]
for prefix in [Pkg.dir(); LOAD_PATH]
path = joinpath(prefix, name)
isfile(path) && return abspath(path)
path = joinpath(prefix, base, "src", name)
Expand Down

0 comments on commit 615e746

Please sign in to comment.