Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = "0.8.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Expand Down
13 changes: 8 additions & 5 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is machine-generated - editing it directly is not advised

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

Expand All @@ -6,7 +8,7 @@ deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[Distributed]]
deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[DocStringExtensions]]
Expand All @@ -22,13 +24,13 @@ uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.22.6"

[[FilePathsBase]]
deps = ["Dates", "LinearAlgebra", "Printf", "Test", "UUIDs"]
deps = ["Dates", "Printf", "Test", "UUIDs"]
path = ".."
uuid = "48062228-2e41-5def-b9a4-89aafe57970f"
version = "0.8.0"

[[InteractiveUtils]]
deps = ["LinearAlgebra", "Markdown"]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JSON]]
Expand All @@ -38,6 +40,7 @@ uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.20.0"

[[LibGit2]]
deps = ["Printf"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[Libdl]]
Expand All @@ -58,7 +61,7 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
Expand Down Expand Up @@ -87,7 +90,7 @@ deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[UUIDs]]
deps = ["Random"]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
Expand Down
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[compat]
Documenter = "~0.22.4"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Documenter, FilePathsBase, FilePathsBase.TestPaths, LinearAlgebra
using Documenter, FilePathsBase, FilePathsBase.TestPaths

makedocs(
modules=[FilePathsBase],
Expand Down
15 changes: 8 additions & 7 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ N/A | extension
N/A | extensions
ispath | exists
realpath | real
normpath | norm
abspath | abs
normpath | normalize
abspath | absolute
relpath | relative
stat | stat
lstat | lstat
Expand All @@ -37,7 +37,7 @@ isexecutable (deprecated) | isexecutable
iswritable (deprecated) | iswritable
isreadable (deprecated) | isreadable
ismount | ismount
isabspath | isabs
isabspath | isabsolute
splitdrive()[1] | drive
N/A | root (property)
split(p, "/") | segments (property)
Expand Down Expand Up @@ -94,11 +94,12 @@ FilePathsBase.filename(::AbstractPath)
FilePathsBase.extension(::AbstractPath)
FilePathsBase.extensions(::AbstractPath)
Base.isempty(::AbstractPath)
LinearAlgebra.norm(::T) where {T <: AbstractPath}
Base.abs(::AbstractPath)
FilePathsBase.isabs(::AbstractPath)
normalize(::T) where {T <: AbstractPath}
absolute(::AbstractPath)
FilePathsBase.isabsolute(::AbstractPath)
FilePathsBase.relative(::T, ::T) where {T <: AbstractPath}
Base.real(::AbstractPath)
Base.readlink(::AbstractPath)
FilePathsBase.canonicalize(::AbstractPath)
FilePathsBase.mode(::AbstractPath)
FilePathsBase.modified(::AbstractPath)
FilePathsBase.created(::AbstractPath)
Expand Down
7 changes: 5 additions & 2 deletions src/FilePathsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ __precompile__()
module FilePathsBase

using Dates
using LinearAlgebra
using Printf
using UUIDs

Expand All @@ -30,10 +29,13 @@ export
extension,
extensions,
exists,
isabs,
absolute,
isabsolute,
mode,
created,
modified,
normalize,
canonicalize,
relative,
isrelative,
ismount,
Expand Down Expand Up @@ -129,5 +131,6 @@ include("posix.jl")
include("windows.jl")
include("system.jl")
include("test.jl")
include("deprecates.jl")

end # end of module
29 changes: 4 additions & 25 deletions src/deprecates.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
import Base.@deprecate

import Base:
dirname,
ispath,
realpath,
normpath,
abspath,
relpath,
filemode,
isabspath,
mkpath,
mv,
rm
import Base: real, abs, size

@deprecate dirname(fp::AbstractPath) parent(fp)
@deprecate ispath(fp::AbstractPath) exists(fp)
@deprecate realpath(fp::AbstractPath) real(fp)
@deprecate normpath(fp::AbstractPath) norm(fp)
@deprecate abspath(fp::AbstractPath) abs(fp)
@deprecate relpath(fp::AbstractPath) relative(fp)
@deprecate filemode(fp::AbstractPath) mode(fp)
@deprecate isabspath(fp::AbstractPath) isabs(fp)
@deprecate mkpath(fp::AbstractPath) mkdir(fp; recursive=true, exist_ok=true)
@deprecate parts(fp::AbstractPath) fp.segments
@deprecate drive(fp::Abstractpath) fp.drive
@deprecate root(fp::AbstractPath) fp.root
@deprecate anchor(fp::AbstractPath) fp.anchor
@deprecate real(fp::AbstractPath) canonicalize(fp)
@deprecate abs(fp::AbstractPath) absolute(fp)
@deprecate isabs(fp::AbstractPath) isabsolute(fp)
49 changes: 28 additions & 21 deletions src/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ Returns true if `fp.root` is empty, indicating that it is a relative path.
"""
isrelative(fp::AbstractPath) = isempty(fp.root)

"""
isabsolute(fp::AbstractPath) -> Bool

Returns true if `fp.root` is not empty, indicating that it is an absolute path.
"""
isabsolute(fp::AbstractPath) = !isempty(fp.root)

# Support immutable indexing API
Base.getindex(fp::AbstractPath, idx) = fp.segments[idx]
Base.firstindex(::AbstractPath) = 1
Expand Down Expand Up @@ -344,11 +351,11 @@ default to using the current directory (or `p"."`).
Base.isempty(fp::AbstractPath) = isempty(fp.segments)

"""
norm(fp::AbstractPath) -> AbstractPath
normalize(fp::AbstractPath) -> AbstractPath

Normalizes a path by removing "." and ".." entries.
normalizes a path by removing "." and ".." entries.
"""
function LinearAlgebra.norm(fp::T) where {T <: AbstractPath}
function normalize(fp::T) where {T <: AbstractPath}
p = fp.segments
result = String[]
rem = length(p)
Expand Down Expand Up @@ -376,24 +383,20 @@ function LinearAlgebra.norm(fp::T) where {T <: AbstractPath}
end

"""
abs(fp::AbstractPath) -> AbstractPath
absolute(fp::AbstractPath) -> AbstractPath

Creates an absolute path by adding the current working directory if necessary.
"""
function Base.abs(fp::AbstractPath)
function absolute(fp::AbstractPath)
result = expanduser(fp)

if isabs(result)
return norm(result)
if isabsolute(result)
return normalize(result)
else
return norm(join(cwd(), result))
return normalize(join(cwd(), result))
end
end

function isabs(fp::AbstractPath)
return !isempty(fp.drive) && !isempty(fp.root)
end

"""
relative{T<:AbstractPath}(fp::T, start::T=T("."))

Expand All @@ -403,8 +406,8 @@ function relative(fp::T, start::T=T(".")) where {T <: AbstractPath}
curdir = "."
pardir = ".."

p = abs(fp).segments
s = abs(start).segments
p = absolute(fp).segments
s = absolute(start).segments

p == s && return T(curdir)

Expand Down Expand Up @@ -437,11 +440,15 @@ function relative(fp::T, start::T=T(".")) where {T <: AbstractPath}
end

"""
real(path::AbstractPath) -> AbstractPath
canonicalize(path::AbstractPath) -> AbstractPath

Canonicalize a path by making it absolute, `.` or `..` segments and resolving any symlinks
if applicable.

Canonicalize a path by expanding symbolic links and removing "." and ".." entries.
WARNING: Fallback behaviour ignores symlinks and should be extended for paths where
symlinks are permitted (e.g., `SystemPath`s).
"""
Base.real(fp::AbstractPath) = fp
canonicalize(fp::AbstractPath) = normalize(absolute(fp))

Base.lstat(fp::AbstractPath) = stat(fp)

Expand Down Expand Up @@ -773,12 +780,12 @@ mktmpdir(arg1, args...) = mktempdir(arg1, args...)
# ALIASES for base filesystem API
Base.dirname(fp::AbstractPath) = parent(fp)
Base.ispath(fp::AbstractPath) = exists(fp)
Base.realpath(fp::AbstractPath) = real(fp)
Base.normpath(fp::AbstractPath) = norm(fp)
Base.abspath(fp::AbstractPath) = abs(fp)
Base.realpath(fp::AbstractPath) = canonicalize(fp)
Base.normpath(fp::AbstractPath) = normalize(fp)
Base.abspath(fp::AbstractPath) = absolute(fp)
Base.relpath(fp::AbstractPath) = relative(fp)
Base.filemode(fp::AbstractPath) = mode(fp)
Base.isabspath(fp::AbstractPath) = isabs(fp)
Base.isabspath(fp::AbstractPath) = isabsolute(fp)
Base.mkpath(fp::AbstractPath) = mkdir(fp; recursive=true)

# ALIASES for now old FilePaths API
Expand Down
1 change: 0 additions & 1 deletion src/posix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function PosixPath(str::AbstractString)
end

ispathtype(::Type{PosixPath}, str::AbstractString) = Sys.isunix()
isabs(fp::PosixPath) = !isempty(fp.root)

function Base.expanduser(fp::PosixPath)::PosixPath
p = fp.segments
Expand Down
2 changes: 1 addition & 1 deletion src/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ macro LOCAL(filespec)
end

exists(fp::SystemPath) = ispath(string(fp))
Base.real(fp::P) where {P <: SystemPath} = P(realpath(string(fp)))

#=
The following a descriptive methods for paths
Expand Down Expand Up @@ -379,3 +378,4 @@ end
Base.readdir(fp::SystemPath) = readdir(string(fp))
Base.download(url::AbstractString, dest::SystemPath) = download(url, string(dest))
Base.readlink(fp::SystemPath) = Path(readlink(string(fp)))
canonicalize(fp::SystemPath) = Path(realpath(string(fp)))
Loading