1
1
const sym2loader = Dict {Symbol,Vector{Symbol}} ()
2
2
const sym2saver = Dict {Symbol,Vector{Symbol}} ()
3
- const has_pkg3 = try
4
- using Pkg3
5
- true
6
- catch e
7
- false
8
- end
9
3
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
20
5
21
6
function checked_import (pkg:: Symbol )
22
7
isdefined (Main, pkg) && return getfield (Main, pkg)
23
8
isdefined (FileIO, pkg) && return getfield (FileIO, pkg)
24
9
! 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))
26
11
return getfield (Main, pkg)
27
12
end
28
13
@@ -31,13 +16,13 @@ for (applicable_, add_, dict_) in (
31
16
(:applicable_loaders , :add_loader , :sym2loader ),
32
17
(:applicable_savers , :add_saver , :sym2saver ))
33
18
@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
35
20
if haskey ($ dict_, sym)
36
21
return $ dict_[sym]
37
22
end
38
23
error (" No $($ applicable_) found for $(sym) " )
39
24
end
40
- function $add_ {sym} (:: Type{DataFormat{sym}} , pkg:: Symbol )
25
+ function $add_ (:: Type{DataFormat{sym}} , pkg:: Symbol ) where sym
41
26
list = get ($ dict_, sym, Symbol[])
42
27
$ dict_[sym] = push! (list, pkg)
43
28
end
@@ -120,31 +105,31 @@ function save(s::Union{AbstractString,IO}; options...)
120
105
end
121
106
122
107
# 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
124
109
libraries = applicable_savers (df)
125
110
checked_import (libraries[1 ])
126
- eval (Main, :($ save ($ File ($ (DataFormat{sym}), $ f),
111
+ Core . eval (Main, :($ save ($ File ($ (DataFormat{sym}), $ f),
127
112
$ data... ; $ options... )))
128
113
end
129
114
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
131
116
libraries = applicable_savers (df)
132
117
checked_import (libraries[1 ])
133
- eval (Main, :($ savestreaming ($ Stream ($ (DataFormat{sym}), $ s),
118
+ Core . eval (Main, :($ savestreaming ($ Stream ($ (DataFormat{sym}), $ s),
134
119
$ data... ; $ options... )))
135
120
end
136
121
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
138
123
libraries = applicable_savers (df)
139
124
checked_import (libraries[1 ])
140
- eval (Main, :($ save ($ Stream ($ (DataFormat{sym}), $ s),
125
+ Core . eval (Main, :($ save ($ Stream ($ (DataFormat{sym}), $ s),
141
126
$ data... ; $ options... )))
142
127
end
143
128
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
145
130
libraries = applicable_savers (df)
146
131
checked_import (libraries[1 ])
147
- eval (Main, :($ savestreaming ($ File ($ (DataFormat{sym}), $ f),
132
+ Core . eval (Main, :($ savestreaming ($ File ($ (DataFormat{sym}), $ f),
148
133
$ data... ; $ options... )))
149
134
end
150
135
163
148
# Handlers for formatted files/streams
164
149
165
150
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
167
152
if unknown (q)
168
153
isfile (filename (q)) || open (filename (q)) # force systemerror
169
154
throw (UnknownFormat (q))
@@ -175,22 +160,22 @@ for fn in (:load, :loadstreaming, :metadata)
175
160
Library = checked_import (library)
176
161
gen2_func_name = Symbol (" fileio_" * $ (string (fn)))
177
162
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... )))
179
164
end
180
165
if ! has_method_from (methods (Library.$ fn), Library)
181
166
throw (LoaderError (string (library), " $($ fn) not defined" ))
182
167
end
183
- return eval (Main, :($ (Library.$ fn)($ q, $ args... ; $ options... )))
168
+ return Core . eval (Main, :($ (Library.$ fn)($ q, $ args... ; $ options... )))
184
169
catch e
185
170
push! (failures, (e, q))
186
171
end
187
172
end
188
- handle_exceptions (failures, " loading \" $( filename (q))\" " )
173
+ handle_exceptions (failures, " loading $( repr ( filename (q))) " )
189
174
end
190
175
end
191
176
192
177
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
194
179
unknown (q) && throw (UnknownFormat (q))
195
180
libraries = applicable_savers (q)
196
181
failures = Any[]
@@ -199,17 +184,17 @@ for fn in (:save, :savestreaming)
199
184
Library = checked_import (library)
200
185
gen2_func_name = Symbol (" fileio_" * $ (string (fn)))
201
186
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... )))
203
188
end
204
189
if ! has_method_from (methods (Library.$ fn), Library)
205
190
throw (WriterError (string (library), " $($ fn) not defined" ))
206
191
end
207
- return eval (Main, :($ (Library.$ fn)($ q, $ data... ; $ options... )))
192
+ return Core . eval (Main, :($ (Library.$ fn)($ q, $ data... ; $ options... )))
208
193
catch e
209
194
push! (failures, (e, q))
210
195
end
211
196
end
212
- handle_exceptions (failures, " saving \" $( filename (q))\" " )
197
+ handle_exceptions (failures, " saving $( repr ( filename (q))) " )
213
198
end
214
199
end
215
200
@@ -224,8 +209,4 @@ function has_method_from(mt, Library)
224
209
false
225
210
end
226
211
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
0 commit comments