File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,8 @@ chmod | chmod (recursive unix-only)
138138chown (unix only) | chown (unix only)
139139N/A | read
140140N/A | write
141+ @__ DIR__ | @__ PATH__
142+ @__ FILE__ | @__ FILEPATH__
141143
142144## TODO:
143145* cross platform chmod and chown
Original file line number Diff line number Diff line change 4646
4747 # Macros
4848 @p_str ,
49+ @__PATH__ ,
50+ @__FILEPATH__ ,
4951
5052 # Constants
5153 READ,
Original file line number Diff line number Diff line change @@ -27,6 +27,38 @@ home() = Path(homedir())
2727
2828anchor (path:: AbstractPath ) = drive (path) * root (path)
2929
30+ """
31+ @__PATH__ -> AbstractPath
32+
33+ @__PATH__ expands to a path with the directory part of the absolute path
34+ of the file containing the macro. Returns an empty Path if run from a REPL or
35+ if evaluated by julia -e <expr>.
36+ """
37+ macro __PATH__ ()
38+ :(Path (@__DIR__ ()=== nothing ? Path () : @__DIR__ ))
39+ end
40+
41+ """
42+ @__FILEPATH__ -> AbstractPath
43+
44+ @__FILEPATH__ expands to a path with the absolute file path of the file
45+ containing the macro. Returns an empty Path if run from a REPL or if
46+ evaluated by julia -e <expr>.
47+ """
48+ macro __FILEPATH__ ()
49+ :(Path (@__FILE__ ()=== nothing ? Path () : @__FILE__ ))
50+ end
51+
52+ """
53+ @LOCAL(filespec)
54+
55+ Construct an absolute path to `filespec` relative to the source file
56+ containing the macro call.
57+ """
58+ macro LOCAL (filespec)
59+ :(join (@__PATH__ , Path ($ (esc (filespec)))))
60+ end
61+
3062#=
3163Path Modifiers
3264===============================================
Original file line number Diff line number Diff line change @@ -81,6 +81,9 @@ cd(abs(parent(Path(@__FILE__)))) do
8181 @test p4. drive == " "
8282 @test p4. root == " "
8383
84+ @test @__PATH__ () == Path (@__DIR__ )
85+ @test @__FILEPATH__ () == Path (@__FILE__ )
86+ @test FilePathsBase. @LOCAL (" foo.txt" ) == join (@__PATH__ , " foo.txt" )
8487 end
8588end
8689
You can’t perform that action at this time.
0 commit comments