Skip to content

Commit fb40301

Browse files
authored
Merge pull request #187 from JuliaIO/fredrikekre-fe/0.7
Fredrikekre fe/0.7
2 parents 429b5a7 + 00f4122 commit fb40301

15 files changed

+107
-134
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.6
6+
- 0.7
77
- nightly
88
notifications:
99
email: false

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.6
2-
Compat 0.28.0
1+
julia 0.7-alpha

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
55
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
66
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
77

docs/make_docs.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ extension2string(x) = join(map(string, x), ", ")
1616
extension2string(x::AbstractString) = x
1717

1818
os2string(x::Vector) = isempty(x) ? "**all** platforms " : join(map(os2string, x), ", ")
19-
os2string{O <: OS}(os::Type{O}) = "**$(O.name.name)**"
19+
os2string(os::Type{O}) where {O <: OS} = "**$(O.name.name)**"
2020

2121
magic2string(x::Function) = "has detection function"
22-
magic2string(x::Tuple) = isempty(x) ? "only extension": string(x)
22+
magic2string(x::Tuple) = isempty(x) ? "only extension" : string(x)
2323
magic2string(x) = string(x)
2424
function loadsave2string(load_save_libraries)
2525
io = IOBuffer()
2626
loader_str, saver_str = " ", " "
2727
for predicates in load_save_libraries
28-
library = shift!(predicates)
28+
library = popfirst!(predicates)
2929

3030
os, loadsave = FileIO.split_predicates(predicates)
3131
if isempty(loadsave)
@@ -38,23 +38,23 @@ function loadsave2string(load_save_libraries)
3838
end
3939
String(take!(io))
4040
end
41-
function add_format{Sym}(::Type{DataFormat{Sym}}, magic, extension, io_libs...)
41+
function add_format(::Type{DataFormat{Sym}}, magic, extension, io_libs...) where Sym
4242
println(fs, "| $(Sym) | $(extension2string(extension)) | $(loadsave2string(io_libs)) | $(magic2string(magic)) |")
4343
end
4444

4545

46-
function add_format{sym}(fmt::Type{DataFormat{sym}}, magic::Union{Tuple,AbstractVector,String}, extension)
46+
function add_format(fmt::Type{DataFormat{sym}}, magic::Union{Tuple,AbstractVector,String}, extension) where sym
4747
println(sym)
4848
end
4949

5050
# for multiple magic bytes
51-
function add_format{sym, T <: Vector{UInt8}, N}(fmt::Type{DataFormat{sym}}, magics::NTuple{N, T}, extension)
51+
function add_format(fmt::Type{DataFormat{sym}}, magics::NTuple{N, T}, extension) where {sym, T <: Vector{UInt8}, N}
5252
println(sym)
5353
end
5454

5555
# For when "magic" is supplied as a function (see the HDF5 example in
5656
# registry.jl)
57-
function add_format{sym}(fmt::Type{DataFormat{sym}}, magic, extension)
57+
function add_format(fmt::Type{DataFormat{sym}}, magic, extension) where sym
5858
println(sym)
5959
end
6060

src/FileIO.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ __precompile__()
22

33
module FileIO
44

5-
using Compat
6-
75
export DataFormat,
86
File,
97
Formatted,
@@ -29,6 +27,7 @@ export DataFormat,
2927

3028
import Base.showerror
3129
using Base: RefValue
30+
using Pkg
3231

3332
include("query.jl")
3433
include("error_handling.jl")

src/error_handling.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Handles a list of thrown errors after no IO library was found working
6060
function handle_exceptions(exceptions::Vector, action)
6161
# first show all errors when there are more then one
6262
multiple = length(exceptions) > 1
63-
println(STDERR, "Error$(multiple ? "s" : "") encountered while $action.")
63+
println(stderr, "Error$(multiple ? "s" : "") encountered while $action.")
6464
if multiple
6565
println("All errors:")
6666
for (err, file) in exceptions
@@ -70,7 +70,7 @@ function handle_exceptions(exceptions::Vector, action)
7070
# then handle all errors.
7171
# this way first fatal exception throws and user can still see all errors
7272
# TODO, don't throw, if it contains a NotInstalledError?!
73-
println(STDERR, "Fatal error:")
73+
println(stderr, "Fatal error:")
7474
for exception in exceptions
7575
continue_ = handle_error(exception...)
7676
continue_ || break
@@ -84,13 +84,13 @@ function handle_error(e::NotInstalledError, q)
8484
!isinteractive() && rethrow(e) # if we're not in interactive mode just throw
8585
while true
8686
println("Should we install \"", e.library, "\" for you? (y/n):")
87-
input = lowercase(chomp(strip(readline(STDIN))))
87+
input = lowercase(chomp(strip(readline(stdin))))
8888
if input == "y"
89-
info(string("Start installing ", e.library, "..."))
89+
@info(string("Start installing ", e.library, "..."))
9090
Pkg.add(string(e.library))
9191
return false # don't continue
9292
elseif input == "n"
93-
info(string("Not installing ", e.library))
93+
@info(string("Not installing ", e.library))
9494
return true # User does not install, continue going through errors.
9595
else
9696
println("$input is not a valid choice. Try typing y or n")

src/loadsave.jl

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
const sym2loader = Dict{Symbol,Vector{Symbol}}()
22
const sym2saver = Dict{Symbol,Vector{Symbol}}()
3-
const has_pkg3 = try
4-
using Pkg3
5-
true
6-
catch e
7-
false
8-
end
93

10-
if isdefined(Base, :find_in_path)
11-
function is_installed(pkg::Symbol)
12-
isdefined(Main, pkg) && isa(getfield(Main, pkg), Module) && return true # is a module defined in Main scope
13-
path = Base.find_in_path(string(pkg)) # hacky way to determine if a Package is installed
14-
path == nothing && return false
15-
return isfile(path)
16-
end
17-
elseif has_pkg3 && isdefined(Pkg3, :installed)
18-
is_installed(pkg::Symbol) = get(Pkg3.installed(), string(pkg), nothing) != nothing
19-
end
4+
is_installed(pkg::Symbol) = get(Pkg.installed(), string(pkg), nothing) != nothing
205

216
function checked_import(pkg::Symbol)
227
isdefined(Main, pkg) && return getfield(Main, pkg)
238
isdefined(FileIO, pkg) && return getfield(FileIO, pkg)
249
!is_installed(pkg) && throw(NotInstalledError(pkg, ""))
25-
!isdefined(Main, pkg) && eval(Main, Expr(:import, pkg))
10+
!isdefined(Main, pkg) && Core.eval(Main, Expr(:import, pkg))
2611
return getfield(Main, pkg)
2712
end
2813

@@ -31,13 +16,13 @@ for (applicable_, add_, dict_) in (
3116
(:applicable_loaders, :add_loader, :sym2loader),
3217
(:applicable_savers, :add_saver, :sym2saver))
3318
@eval begin
34-
function $applicable_{sym}(::Union{Type{DataFormat{sym}}, Formatted{DataFormat{sym}}})
19+
function $applicable_(::Union{Type{DataFormat{sym}}, Formatted{DataFormat{sym}}}) where sym
3520
if haskey($dict_, sym)
3621
return $dict_[sym]
3722
end
3823
error("No $($applicable_) found for $(sym)")
3924
end
40-
function $add_{sym}(::Type{DataFormat{sym}}, pkg::Symbol)
25+
function $add_(::Type{DataFormat{sym}}, pkg::Symbol) where sym
4126
list = get($dict_, sym, Symbol[])
4227
$dict_[sym] = push!(list, pkg)
4328
end
@@ -120,31 +105,31 @@ function save(s::Union{AbstractString,IO}; options...)
120105
end
121106

122107
# Allow format to be overridden with first argument
123-
function save{sym}(df::Type{DataFormat{sym}}, f::AbstractString, data...; options...)
108+
function save(df::Type{DataFormat{sym}}, f::AbstractString, data...; options...) where sym
124109
libraries = applicable_savers(df)
125110
checked_import(libraries[1])
126-
eval(Main, :($save($File($(DataFormat{sym}), $f),
111+
Core.eval(Main, :($save($File($(DataFormat{sym}), $f),
127112
$data...; $options...)))
128113
end
129114

130-
function savestreaming{sym}(df::Type{DataFormat{sym}}, s::IO, data...; options...)
115+
function savestreaming(df::Type{DataFormat{sym}}, s::IO, data...; options...) where sym
131116
libraries = applicable_savers(df)
132117
checked_import(libraries[1])
133-
eval(Main, :($savestreaming($Stream($(DataFormat{sym}), $s),
118+
Core.eval(Main, :($savestreaming($Stream($(DataFormat{sym}), $s),
134119
$data...; $options...)))
135120
end
136121

137-
function save{sym}(df::Type{DataFormat{sym}}, s::IO, data...; options...)
122+
function save(df::Type{DataFormat{sym}}, s::IO, data...; options...) where sym
138123
libraries = applicable_savers(df)
139124
checked_import(libraries[1])
140-
eval(Main, :($save($Stream($(DataFormat{sym}), $s),
125+
Core.eval(Main, :($save($Stream($(DataFormat{sym}), $s),
141126
$data...; $options...)))
142127
end
143128

144-
function savestreaming{sym}(df::Type{DataFormat{sym}}, f::AbstractString, data...; options...)
129+
function savestreaming(df::Type{DataFormat{sym}}, f::AbstractString, data...; options...) where sym
145130
libraries = applicable_savers(df)
146131
checked_import(libraries[1])
147-
eval(Main, :($savestreaming($File($(DataFormat{sym}), $f),
132+
Core.eval(Main, :($savestreaming($File($(DataFormat{sym}), $f),
148133
$data...; $options...)))
149134
end
150135

@@ -163,7 +148,7 @@ end
163148
# Handlers for formatted files/streams
164149

165150
for fn in (:load, :loadstreaming, :metadata)
166-
@eval function $fn{F}(q::Formatted{F}, args...; options...)
151+
@eval function $fn(q::Formatted{F}, args...; options...) where F
167152
if unknown(q)
168153
isfile(filename(q)) || open(filename(q)) # force systemerror
169154
throw(UnknownFormat(q))
@@ -175,22 +160,22 @@ for fn in (:load, :loadstreaming, :metadata)
175160
Library = checked_import(library)
176161
gen2_func_name = Symbol("fileio_" * $(string(fn)))
177162
if isdefined(Library, gen2_func_name)
178-
return eval(Library, :($gen2_func_name($q, $args...; $options...)))
163+
return Core.eval(Library, :($gen2_func_name($q, $args...; $options...)))
179164
end
180165
if !has_method_from(methods(Library.$fn), Library)
181166
throw(LoaderError(string(library), "$($fn) not defined"))
182167
end
183-
return eval(Main, :($(Library.$fn)($q, $args...; $options...)))
168+
return Core.eval(Main, :($(Library.$fn)($q, $args...; $options...)))
184169
catch e
185170
push!(failures, (e, q))
186171
end
187172
end
188-
handle_exceptions(failures, "loading \"$(filename(q))\"")
173+
handle_exceptions(failures, "loading $(repr(filename(q)))")
189174
end
190175
end
191176

192177
for fn in (:save, :savestreaming)
193-
@eval function $fn{F}(q::Formatted{F}, data...; options...)
178+
@eval function $fn(q::Formatted{F}, data...; options...) where F
194179
unknown(q) && throw(UnknownFormat(q))
195180
libraries = applicable_savers(q)
196181
failures = Any[]
@@ -199,17 +184,17 @@ for fn in (:save, :savestreaming)
199184
Library = checked_import(library)
200185
gen2_func_name = Symbol("fileio_" * $(string(fn)))
201186
if isdefined(Library, gen2_func_name)
202-
return eval(Library, :($gen2_func_name($q, $data...; $options...)))
187+
return Core.eval(Library, :($gen2_func_name($q, $data...; $options...)))
203188
end
204189
if !has_method_from(methods(Library.$fn), Library)
205190
throw(WriterError(string(library), "$($fn) not defined"))
206191
end
207-
return eval(Main, :($(Library.$fn)($q, $data...; $options...)))
192+
return Core.eval(Main, :($(Library.$fn)($q, $data...; $options...)))
208193
catch e
209194
push!(failures, (e, q))
210195
end
211196
end
212-
handle_exceptions(failures, "saving \"$(filename(q))\"")
197+
handle_exceptions(failures, "saving $(repr(filename(q)))")
213198
end
214199
end
215200

@@ -224,8 +209,4 @@ function has_method_from(mt, Library)
224209
false
225210
end
226211

227-
if VERSION < v"0.5.0-dev+3543"
228-
getmodule(m) = m.func.code.module
229-
else
230-
getmodule(m) = m.module
231-
end
212+
getmodule(m) = m.module

src/mimesave.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module MimeWriter
33
using ..FileIO: File, @format_str
44

55
function save(file::File{format"PNG"}, data)
6-
if mimewritable("image/png", data)
6+
if showable("image/png", data)
77
open(file.filename, "w") do s
88
show(IOContext(s, :full_fidelity=>true), "image/png", data)
99
end
@@ -13,7 +13,7 @@ function save(file::File{format"PNG"}, data)
1313
end
1414

1515
function save(file::File{format"SVG"}, data)
16-
if mimewritable("image/svg+xml", data)
16+
if showable("image/svg+xml", data)
1717
open(file.filename, "w") do s
1818
show(IOContext(s, :full_fidelity=>true), "image/svg+xml", data)
1919
end
@@ -23,7 +23,7 @@ function save(file::File{format"SVG"}, data)
2323
end
2424

2525
function save(file::File{format"PDF"}, data)
26-
if mimewritable("application/pdf", data)
26+
if showable("application/pdf", data)
2727
open(file.filename, "w") do s
2828
show(IOContext(s, :full_fidelity=>true), "application/pdf", data)
2929
end
@@ -33,7 +33,7 @@ function save(file::File{format"PDF"}, data)
3333
end
3434

3535
function save(file::File{format"EPS"}, data)
36-
if mimewritable("application/eps", data)
36+
if showable("application/eps", data)
3737
open(file.filename, "w") do s
3838
show(IOContext(s, :full_fidelity=>true), "application/eps", data)
3939
end

0 commit comments

Comments
 (0)