-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make @__DIR__ return pwd() when being run without a file #21759
Conversation
Wouldn't this also change what this means inside packages? |
As currently written, yes, which was an oversight on my part. But I think that can be fixed easily. |
base/loading.jl
Outdated
@@ -517,8 +517,13 @@ function source_path(default::Union{AbstractString,Void}="") | |||
end | |||
|
|||
function source_dir() | |||
isinteractive() && return pwd() |
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.
Leftover 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.
Yes, thanks!
test/loading.jl
Outdated
@@ -14,6 +14,9 @@ include_string_test_func = include_string("include_string_test() = @__FILE__", t | |||
|
|||
@test isdir(@__DIR__) | |||
@test @__DIR__() == dirname(@__FILE__) | |||
let exename = `$(Base.julia_cmd()) --precompiled=yes --startup-file=no` | |||
@test readchomp(`$exename -E "@__DIR__" -i`) == string('"', pwd(), '"') | |||
end |
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.
Test that you don't get pwd() when running in a script? E.g. by doing cd("/tmp") do @__DIR__; end
?
a14769a
to
c31f4d0
Compare
The Windows failure is perplexing to me:
The already escaped backslashes get escaped again, which is wrong. I'm not sure whether that's related to the changes here. Input from any Windows experts would be much appreciated. |
test/loading.jl
Outdated
@@ -14,6 +14,12 @@ include_string_test_func = include_string("include_string_test() = @__FILE__", t | |||
|
|||
@test isdir(@__DIR__) | |||
@test @__DIR__() == dirname(@__FILE__) | |||
let exename = `$(Base.julia_cmd()) --precompiled=yes --startup-file=no` | |||
wd = string('"', pwd(), '"') | |||
@test readchomp(`$exename -E "@__DIR__" -i`) == 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.
use println(@__DIR__)
, so that it doesn't get handed to show
to escape all of the characters (or set wd
to sprint(show, pwd())
)
Cool, now the macOS and 64-bit Windows failures are unrelated, and the relevant tests are passing on all platforms. |
I'm feeling a little iffy about how patchy the behavior is with this change – I like that we return pwd now in the REPL, I'm saying that we should perhaps do so unconditionally and/or return the empty string unconditionally. |
You mean omit the interactivity check and just always return |
Yes, although I guess the worry is that could be breaking. But I'm not sure what checking or |
This should also go in NEWS, but I'll wait until CI finishes then put that in a CI skipped commit. |
is there no other case where source_path can return nothing? |
Based on my understanding of the function's logic, I don't believe so. |
Fixes #21753