Skip to content

Commit

Permalink
improve @using for package-like dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Apr 23, 2024
1 parent f67ca74 commit d1a53dd
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Loader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ function _findpackage(package::String)
package = splitext(package)[1]

basedir, parentdir = splitdir(path)
# if it is a package structure use the parent directory of the package as LOAD_PATH
# if it is a package structure prepend parent directory of the package as LOAD_PATH to path
if parentdir == "src" && basename(basedir) == package
path = dirname(basedir)
path = "$(dirname(basedir));$path"
end

path, package
Expand Down Expand Up @@ -440,13 +440,20 @@ macro _using(package)
package_symbol = Symbol(package_name)

quote
pushfirst!(LOAD_PATH, $path)
@debug "using $($package_name) (from '$($path)')"
try
using $package_symbol
catch
finally
popfirst!(LOAD_PATH)
let pp = split($path, ';')
for p in pp
pushfirst!(LOAD_PATH, p)
end

@debug "using $($package_name) (from '$($path)')"
try
using $package_symbol
catch
finally
for _ in pp
popfirst!(LOAD_PATH)
end
end
end
nothing
end
Expand Down

0 comments on commit d1a53dd

Please sign in to comment.