Skip to content

Commit

Permalink
Dropped Humanize, Glob and URIParser as dependencies (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
rofinn authored Dec 16, 2017
1 parent 71fe6af commit 150b24e
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ matrix:
- julia: nightly
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.init(); Pkg.clone(pwd()); Pkg.checkout("Humanize"), Pkg.test("FilePaths"; coverage=true)'
- julia -e 'Pkg.init(); Pkg.clone(pwd()); Pkg.test("FilePaths"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("FilePaths")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
3 changes: 0 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
julia 0.5
Compat 0.17.0
URIParser 0.1.8
Glob 1.1.1
Humanize 0.4.1
3 changes: 1 addition & 2 deletions src/FilePaths.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export
created,
modified,
relative,
glob,
uri,
move,
remove,
tmpname,
Expand Down Expand Up @@ -72,6 +70,7 @@ root(path::AbstractPath) = error("`root` not implemented.")
Base.convert(::Type{AbstractPath}, x::AbstractString) = Path(x)

include("constants.jl")
include("utils.jl")
include("libc.jl")
include("mode.jl")
include("status.jl")
Expand Down
2 changes: 2 additions & 0 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ const FILEMODE_TABLE = (
(S_ISVTX, "T"),
(S_IXOTH, "x"))
)

const DATA_SUFFIX = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]
45 changes: 1 addition & 44 deletions src/path.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import URIParser: URI
import Glob: glob

"""
Path()
Path(path::AbstractPath)
Expand Down Expand Up @@ -276,46 +273,6 @@ function relative{T<:AbstractPath}(path::T, start::T=T("."))
return isempty(relpath_) ? T(curdir) : T(relpath_)
end

"""
glob{T<:AbstractPath}(path::T, pattern::AbstractString) -> Array{T}
Returns all subpaths along the provided `path` which match the glob `pattern`.
# Example
```
julia> glob(p"src", "*.jl")
9-element Array{FilePaths.PosixPath,1}:
p"src/FilePaths.jl"
p"src/constants.jl"
p"src/deprecates.jl"
p"src/libc.jl"
p"src/mode.jl"
p"src/path.jl"
p"src/posix.jl"
p"src/status.jl"
p"src/windows.jl"
```
"""
function glob{T<:AbstractPath}(path::T, pattern::AbstractString)
matches = glob(pattern, String(path))
map(T, matches)
end

"""
uri(path::AbstractPath) -> AbstractPath
Creates a `file://` `URI` from the `path`.
"""
function uri(path::AbstractPath)
if isempty(root(path))
error("$path is not an absolute path")
end

uri_str = "file://$(String(path))"

return URI(uri_str)
end

#=
The following a descriptive methods for paths
built around stat
Expand Down Expand Up @@ -623,7 +580,7 @@ function Base.chmod(path::AbstractPath, mode::Mode; recursive=false)
chmod_mode = raw(mode)

if isdir(path) && recursive
for p in glob(path, "*")
for p in readdir(path)
chmod(chmod_path, chmod_mode; recursive=recursive)
end
end
Expand Down
5 changes: 2 additions & 3 deletions src/status.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Base.Dates
using Humanize

import Base.Filesystem: StatStruct

Expand Down Expand Up @@ -44,8 +43,8 @@ function Base.show(io::IO, s::Status)
" uid = $(s.user),\n" *
" gid = $(s.group),\n" *
" rdev = $(s.rdev),\n" *
" size = $(s.size) ($(datasize(s.size, style=:gnu))),\n" *
" blksize = $(s.blksize) ($(datasize(s.blksize, style=:gnu))),\n" *
" size = $(s.size) ($(_datasize(s.size))),\n" *
" blksize = $(s.blksize) ($(_datasize(s.blksize))),\n" *
" blocks = $(s.blocks),\n" *
" mtime = $(s.mtime),\n" *
" ctime = $(s.ctime),\n)"
Expand Down
18 changes: 18 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Mostly copied from https://github.com/IainNZ/Humanize.jl/blob/master/src/Humanize.jl#L27
function _datasize(bytes::Number)
base = 1024.0
nbytes = float(bytes)
unit = base
suffix = first(DATA_SUFFIX)

for (i, s) in enumerate(DATA_SUFFIX)
unit = base ^ i

if nbytes < unit
suffix = s
break
end
end

return @sprintf("%.1f%s", (base * nbytes / unit), suffix)
end
4 changes: 0 additions & 4 deletions test/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ cd(abs(parent(Path(@__FILE__)))) do
@test String(norm(p"../src/../src/FilePaths.jl")) == normpath("../src/../src/FilePaths.jl")
@test String(abs(p)) == abspath(String(p))
@test String(relative(p, home())) == relpath(String(p), homedir())
@test uri(PosixPath("/foo/bar")) == URI("file:///foo/bar")
@test_throws ErrorException uri(p"foo/bar")

@test p"../src/FilePaths.jl" in glob(p"../src", "*.jl")

s = stat(p)
lstat(p)
Expand Down
9 changes: 0 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
include_path = joinpath(
abspath(dirname(dirname(@__FILE__))),
"src/FilePaths.jl"
)
include(include_path)

using FilePaths

import URIParser: URI

using Base.Test

info("Beginning tests...")
Expand Down

0 comments on commit 150b24e

Please sign in to comment.