I have found a small inconsistency in the google group lists. When you type “julia get directory of script” into a google search box (finding a way to programmatically determine the file path of the currently executing source code), you get this answer: Redirecting to Google Groups
However, this method fails if you call it from code that gets passed into a macro in another file. I had this problem when I used Base.source_path() in a function that was called from within a testset. However, @FILE does not have this problem. I wanted to suggest this to the user on the google group, but it is locked, so I decided to tell you.
Minimal example of what I mean:
foo.jl:
function foo()
println(Base.source_path())
end
bar.jl:
include("foo.jl")
using Base.Test
@testset "my_testset" begin
foo()
end
Anyways, maybe this is the desired behavior of Base.source_path(), but I was confused at the behavior I saw given the description given in the google group.
So, for new julia users directed here from google, to get the path of the currently executing file, you should use @FILE. Somebody please correct me if I’m wrong.