77Responsible for creating the appropriate platform specific path
88(e.g., `PosixPath` and `WindowsPath` for Unix and Windows systems respectively)
99"""
10- Path () = @static is_unix () ? PosixPath () : WindowsPath ()
10+ Path () = @static Compat . Sys . isunix () ? PosixPath () : WindowsPath ()
1111Path (path:: AbstractPath ) = path
12- Path (pieces:: Tuple ) = @static is_unix () ? PosixPath (pieces) : WindowsPath (pieces)
13- Path (str:: AbstractString ) = @static is_unix () ? PosixPath (str) : WindowsPath (str)
12+ Path (pieces:: Tuple ) = @static Compat . Sys . isunix () ? PosixPath (pieces) : WindowsPath (pieces)
13+ Path (str:: AbstractString ) = @static Compat . Sys . isunix () ? PosixPath (str) : WindowsPath (str)
1414
1515"""
1616 @p_str -> Path
@@ -35,7 +35,12 @@ of the file containing the macro. Returns an empty Path if run from a REPL or
3535if evaluated by julia -e <expr>.
3636"""
3737macro __PATH__ ()
38- :(Path (@__DIR__ ()=== nothing ? Path () : @__DIR__ ))
38+ if VERSION >= v " 0.7-"
39+ p = Path (dirname (string (__source__. file)))
40+ return p=== nothing ? :(Path ()) : :($ p)
41+ else
42+ return :(Path (@__DIR__ ()=== nothing ? Path () : @__DIR__ ))
43+ end
3944end
4045
4146"""
@@ -46,7 +51,12 @@ containing the macro. Returns an empty Path if run from a REPL or if
4651evaluated by julia -e <expr>.
4752"""
4853macro __FILEPATH__ ()
49- :(Path (@__FILE__ ()=== nothing ? Path () : @__FILE__ ))
54+ if VERSION >= v " 0.7-"
55+ p = Path (string (__source__. file))
56+ return p=== nothing ? :(Path ()) : :($ p)
57+ else
58+ return :(Path (@__FILE__ ()=== nothing ? Path () : @__FILE__ ))
59+ end
5060end
5161
5262"""
@@ -56,7 +66,12 @@ Construct an absolute path to `filespec` relative to the source file
5666containing the macro call.
5767"""
5868macro LOCAL (filespec)
59- :(join (@__PATH__ , Path ($ (esc (filespec)))))
69+ if VERSION >= v " 0.7-"
70+ p = join (Path (dirname (string (__source__. file))), Path (filespec))
71+ return :($ p)
72+ else
73+ return :(join (@__PATH__ , Path ($ (esc (filespec)))))
74+ end
6075end
6176
6277#=
@@ -103,7 +118,7 @@ julia> parents(p"~/.julia/v0.6/REQUIRE")
103118# Throws
104119* `ErrorException`: if `path` doesn't have a parent
105120"""
106- function parents {T<:AbstractPath} (path:: T )
121+ function parents (path:: T ) where {T <: AbstractPath }
107122 if hasparent (path)
108123 return map (1 : length (parts (path))- 1 ) do i
109124 T (parts (path)[1 : i])
@@ -228,7 +243,7 @@ Base.real(path::AbstractPath) = Path(realpath(String(path)))
228243
229244Normalizes a path by removing "." and ".." entries.
230245"""
231- function Base . norm {T<:AbstractPath} (path:: T )
246+ function Compat . LinearAlgebra . norm (path:: T ) where {T <: AbstractPath }
232247 p = parts (path)
233248 result = String[]
234249 rem = length (p)
275290
276291Creates a relative path from either the current directory or an arbitrary start directory.
277292"""
278- function relative {T<:AbstractPath} (path:: T , start:: T = T (" ." ))
293+ function relative (path:: T , start:: T = T (" ." )) where {T <: AbstractPath }
279294 curdir = " ."
280295 pardir = " .."
281296
@@ -287,7 +302,7 @@ function relative{T<:AbstractPath}(path::T, start::T=T("."))
287302 i = 0
288303 while i < min (length (p), length (s))
289304 i += 1
290- @static if is_windows ()
305+ @static if Compat . Sys . iswindows ()
291306 if lowercase (p[i]) != lowercase (s[i])
292307 i -= 1
293308 break
@@ -450,7 +465,7 @@ function Base.mkdir(path::AbstractPath; mode=0o777, recursive=false, exist_ok=fa
450465 ! exist_ok && error (" $path already exists." )
451466 else
452467 if ! hasparent (path) || exists (parent (path))
453- mkdir (String (path), mode)
468+ VERSION >= v " 0.7- " ? mkdir ( String (path), mode = mode) : mkdir (String (path), mode)
454469 elseif hasparent (path) && ! exists (parent (path)) && recursive
455470 mkdir (parent (path); mode= mode, recursive= recursive, exist_ok= exist_ok)
456471 else
@@ -522,8 +537,8 @@ function move(src::AbstractPath, dest::AbstractPath; recursive=false, exist_ok=f
522537 end
523538end
524539
525- function Base. cp (src:: AbstractPath , dest:: AbstractPath ; remove_destination :: Bool = false , follow_symlinks:: Bool = false )
526- cp (String (src), String (dest); remove_destination = remove_destination , follow_symlinks= follow_symlinks)
540+ function Base. cp (src:: AbstractPath , dest:: AbstractPath ; force :: Bool = false , follow_symlinks:: Bool = false )
541+ Compat . cp (String (src), String (dest); force = force , follow_symlinks= follow_symlinks)
527542end
528543
529544remove (path:: AbstractPath ; recursive= false ) = rm (String (path); recursive= recursive)
564579Change the `user` and `group` of the `path`.
565580"""
566581function Base. chown (path:: AbstractPath , user:: AbstractString , group:: AbstractString ; recursive= false )
567- @static if is_unix ()
582+ @static if Compat . Sys . isunix ()
568583 chown_cmd = String[" chown" ]
569584 if recursive
570585 push! (chown_cmd, " -R" )
0 commit comments