Skip to content

Commit

Permalink
Drop julia-0.3 support and eliminate Docile requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Jun 17, 2016
1 parent 765ec49 commit 50d1274
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 68 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,6 @@ os:
- linux
- osx
julia:
- 0.3
- 0.4
- nightly
notifications:
Expand Down
4 changes: 1 addition & 3 deletions REQUIRE
@@ -1,4 +1,2 @@
julia 0.3
julia 0.4
Compat 0.7.19
# The rest are needed only on julia 0.3
Docile
15 changes: 3 additions & 12 deletions src/FileIO.jl
Expand Up @@ -4,16 +4,6 @@ module FileIO
using Compat
import Compat.String

if VERSION < v"0.4.0-dev"
using Docile
immutable Pair{A,B}
first::A
second::B
end
Base.first(p::Pair) = p.first
Base.last(p::Pair) = p.second
end

export DataFormat,
File,
Formatted,
Expand Down Expand Up @@ -44,7 +34,7 @@ include("error_handling.jl")
include("loadsave.jl")
include("registry.jl")

@doc """
"""
`FileIO` API (brief summary, see individual functions for more detail):
- `format"PNG"`: specifies a particular defined format
Expand All @@ -66,6 +56,7 @@ include("registry.jl")
- `add_format(fmt, magic, extension)`: register a new format
- `add_loader(fmt, :Package)`: indicate that `Package` supports loading files of type `fmt`
- `add_saver(fmt, :Package)`: indicate that `Package` supports saving files of type `fmt`
""" -> FileIO
"""
FileIO

end
30 changes: 14 additions & 16 deletions src/error_handling.jl
@@ -1,20 +1,20 @@
@doc """
"""
`LoaderError` should be thrown when loader library code fails, and other libraries should
be given the chance to recover from the error. Reports the library name and an error message:
LoaderError("ImageMagick", "Foo not available")
""" ->
"""
immutable LoaderError <: Exception
library::Compat.UTF8String
msg::Compat.UTF8String
end
Base.showerror(io::IO, e::LoaderError) = println(io, e.library, " load error: ",
msg, "\n Will try next loader.")

@doc """
"""
`WriterError` should be thrown when writer library code fails, and other libraries should
be given the chance to recover from the error. Reports the library name and an error message:
WriterError("ImageMagick", "Foo not available")
""" ->
"""
immutable WriterError <: Exception
library::Compat.UTF8String
msg::Compat.UTF8String
Expand All @@ -24,27 +24,27 @@ Base.showerror(io::IO, e::WriterError) = println(
msg, "\n Will try next writer."
)

@doc """
"""
`NotInstalledError` should be thrown when a library is currently not installed.
""" ->
"""
immutable NotInstalledError <: Exception
library::Symbol
message::Compat.UTF8String
end
Base.showerror(io::IO, e::NotInstalledError) = println(io, e.library, " is not installed.")

@doc """
"""
`UnknownFormat` gets thrown when FileIO can't recognize the format of a file.
""" ->
"""
immutable UnknownFormat{T <: Formatted} <: Exception
format::T
end
Base.showerror(io::IO, e::UnknownFormat) = println(io, e.format, " couldn't be recognized by FileIO.")


@doc """
"""
Handles error as soon as they get thrown while doing IO
""" ->
"""
function handle_current_error(e, library, islast::Bool)
bt = catch_backtrace()
bts = sprint(io->Base.show_backtrace(io, bt))
Expand All @@ -53,9 +53,9 @@ function handle_current_error(e, library, islast::Bool)
end
handle_current_error(e::NotInstalledError) = warn(string("lib ", e.library, " not installed, trying next library"))

@doc """
"""
Handles a list of thrown errors after no IO library was found working
""" ->
"""
function handle_error(exceptions::Vector)
for exception in exceptions
continue_ = handle_error(exception...)
Expand All @@ -77,12 +77,10 @@ function handle_error(e::NotInstalledError, q)
return false # don't continue
elseif input == "n"
info(string("Not installing ", e.library))
return true # User does not install, continue going through errors.
return true # User does not install, continue going through errors.
else
println("$input is not a valid choice. Try typing y or n")
end
end
true # User does not install, continue going through errors.
true # User does not install, continue going through errors.
end


14 changes: 8 additions & 6 deletions src/loadsave.jl
Expand Up @@ -28,27 +28,29 @@ for (applicable_, add_, dict_) in (
end


@doc "`add_loader(fmt, :Package)` triggers `using Package` before loading format `fmt`" -> add_loader
@doc "`add_saver(fmt, :Package)` triggers `using Package` before saving format `fmt`" -> add_saver
"`add_loader(fmt, :Package)` triggers `using Package` before loading format `fmt`"
add_loader
"`add_saver(fmt, :Package)` triggers `using Package` before saving format `fmt`"
add_saver


@doc """
"""
- `load(filename)` loads the contents of a formatted file, trying to infer
the format from `filename` and/or magic bytes in the file.
- `load(strm)` loads from an `IOStream` or similar object. In this case,
the magic bytes are essential.
- `load(File(format"PNG",filename))` specifies the format directly, and bypasses inference.
- `load(f; options...)` passes keyword arguments on to the loader.
""" ->
"""
load(s::@compat(Union{AbstractString,IO}), args...; options...) =
load(query(s), args...; options...)

@doc """
"""
- `save(filename, data...)` saves the contents of a formatted file,
trying to infer the format from `filename`.
- `save(Stream(format"PNG",io), data...)` specifies the format directly, and bypasses inference.
- `save(f, data...; options...)` passes keyword arguments on to the saver.
""" ->
"""
save(s::@compat(Union{AbstractString,IO}), data...; options...) =
save(query(s), data...; options...)

Expand Down
60 changes: 30 additions & 30 deletions src/query.jl
Expand Up @@ -30,13 +30,13 @@ function add_loadsave(format, predicates)
end
end

@doc """
"""
`DataFormat{sym}()` indicates a known binary or text format of kind `sym`,
where `sym` is always a symbol. For example, a .csv file might have
`DataFormat{:CSV}()`.
An easy way to write `DataFormat{:CSV}` is `format"CSV"`.
""" ->
"""
immutable DataFormat{sym} end

macro format_str(s)
Expand All @@ -45,8 +45,8 @@ end

const unknown_df = DataFormat{:UNKNOWN}

@doc """
`unknown(f)` returns true if the format of `f` is unknown.""" ->
"""
`unknown(f)` returns true if the format of `f` is unknown."""
unknown(::Type{format"UNKNOWN"}) = true
unknown{sym}(::Type{DataFormat{sym}}) = false

Expand All @@ -64,7 +64,7 @@ function add_format(fmt, magic, extension, load_save_libraries...)
fmt
end

@doc """
"""
`add_format(fmt, magic, extention)` registers a new `DataFormat`.
For example:
Expand All @@ -73,7 +73,7 @@ For example:
add_format(format"NRRD", "NRRD", [".nrrd",".nhdr"])
Note that extensions, magic numbers, and format-identifiers are case-sensitive.
""" ->
"""
function add_format{sym}(fmt::Type{DataFormat{sym}}, magic::@compat(Union{Tuple,AbstractVector,String}), extension)
haskey(sym2info, sym) && error("format ", fmt, " is already registered")
m = canonicalize_magic(magic)
Expand Down Expand Up @@ -113,9 +113,9 @@ function add_format{sym}(fmt::Type{DataFormat{sym}}, magic, extension)
fmt
end

@doc """
"""
`del_format(fmt::DataFormat)` deletes `fmt` from the format registry.
""" ->
"""
function del_format{sym}(fmt::Type{DataFormat{sym}})
magic, extension = sym2info[sym]
del_magic(magic, sym)
Expand Down Expand Up @@ -148,9 +148,9 @@ function del_magic{N}(magic::NTuple{N, UInt8}, sym)
nothing
end

@doc """
"""
`info(fmt)` returns the magic bytes/extension information for
`DataFormat` `fmt`.""" ->
`DataFormat` `fmt`."""
Base.info{sym}(::Type{DataFormat{sym}}) = sym2info[sym]


Expand Down Expand Up @@ -209,32 +209,32 @@ end

abstract Formatted{F<:DataFormat} # A specific file or stream

@doc """
"""
`File(fmt, filename)` indicates that `filename` is a file of known
DataFormat `fmt`. For example, `File{fmtpng}(filename)` would indicate a PNG
file.""" ->
file."""
immutable File{F<:DataFormat} <: Formatted{F}
filename::Compat.UTF8String
end
File{sym}(fmt::Type{DataFormat{sym}}, filename) = File{fmt}(filename)

@doc """
"""
`filename(file)` returns the filename associated with `File` `file`.
""" ->
"""
filename(f::File) = f.filename

@doc """
"""
`file_extension(file)` returns the file extension associated with `File` `file`.
""" ->
"""
file_extension(f::File) = splitext(filename(f))[2]



@doc """
"""
`Stream(fmt, io, [filename])` indicates that the stream `io` is
written in known `Format`. For example, `Stream{PNG}(io)` would
indicate PNG format. If known, the optional `filename` argument can
be used to improve error messages, etc.""" ->
be used to improve error messages, etc."""
immutable Stream{F<:DataFormat,IOtype<:IO} <: Formatted{F}
io::IOtype
filename::Nullable{Compat.UTF8String}
Expand All @@ -245,17 +245,17 @@ Stream{F<:DataFormat}(::Type{F}, io::IO, filename::AbstractString) = Stream{F,ty
Stream{F<:DataFormat}(::Type{F}, io::IO, filename) = Stream{F,typeof(io)}(io,filename)
Stream{F}(file::File{F}, io::IO) = Stream{F,typeof(io)}(io,filename(file))

@doc "`stream(s)` returns the stream associated with `Stream` `s`" ->
"`stream(s)` returns the stream associated with `Stream` `s`"
stream(s::Stream) = s.io

@doc """
"""
`filename(stream)` returns a nullable-string of the filename
associated with `Stream` `stream`.""" ->
associated with `Stream` `stream`."""
filename(s::Stream) = s.filename

@doc """
"""
`file_extension(file)` returns a nullable-string for the file extension associated with `Stream` `stream`.
""" ->
"""
function file_extension(f::Stream)
isnull(filename(f)) && return filename(f)
splitext(get(filename(f)))[2]
Expand Down Expand Up @@ -301,13 +301,13 @@ Base.readbytes(s::Stream, nb) = read(stream(s), nb)
Base.isreadonly(s::Stream) = isreadonly(stream(s))
Base.isopen(s::Stream) = isopen(stream(s))

@doc "`magic(fmt)` returns the magic bytes of format `fmt`" ->
"`magic(fmt)` returns the magic bytes of format `fmt`"
magic{F<:DataFormat}(fmt::Type{F}) = UInt8[info(fmt)[1]...]

@doc """
"""
`skipmagic(s)` sets the position of `Stream` `s` to be just after the magic bytes.
For a plain IO object, you can use `skipmagic(io, fmt)`.
""" ->
"""
skipmagic{F}(s::Stream{F}) = (skipmagic(stream(s), F); s)
function skipmagic{sym}(io, fmt::Type{DataFormat{sym}})
magic, _ = sym2info[sym]
Expand Down Expand Up @@ -345,9 +345,9 @@ end
unknown{F}(::File{F}) = unknown(F)
unknown{F}(::Stream{F}) = unknown(F)

@doc """
"""
`query(filename)` returns a `File` object with information about the
format inferred from the file's extension and/or magic bytes.""" ->
format inferred from the file's extension and/or magic bytes."""
function query(filename::AbstractString)
_, ext = splitext(filename)
if haskey(ext2sym, ext)
Expand Down Expand Up @@ -381,9 +381,9 @@ hasfunction(v::Vector) = any(hasfunction, v)
hasfunction(s::Any) = true #has function
hasfunction(s::Tuple) = false #has magic

@doc """
"""
`query(io, [filename])` returns a `Stream` object with information about the
format inferred from the magic bytes.""" ->
format inferred from the magic bytes."""
query(io::IO, filename) = query(io, Nullable(Compat.UTF8String(filename)))

function query(io::IO, filename::Nullable{Compat.UTF8String}=Nullable{Compat.UTF8String}())
Expand Down

0 comments on commit 50d1274

Please sign in to comment.