24
24
25
25
## Keywords
26
26
* `suffix = "jld2", prefix = default_prefix(config)` : Used in [`savename`](@ref).
27
- * `tag::Bool = istaggable(suffix)` : Save the file using [`tagsave`](@ref) if `true`.
27
+ * `tag::Bool = get(ENV, "DRWATSON_TAG", istaggable(suffix))` : Save the file
28
+ using [`tagsave`](@ref) if `true` (which is the default).
28
29
* `gitpath, storepatch` : Given to [`tagsave`](@ref) if `tag` is `true`.
29
30
* `force = false` : If `true` then don't check if file `s` exists and produce
30
31
it and save it anyway.
@@ -41,9 +42,13 @@ produce_or_load(c, f; kwargs...) = produce_or_load("", c, f; kwargs...)
41
42
produce_or_load (f:: Function , c; kwargs... ) = produce_or_load (c, f; kwargs... )
42
43
produce_or_load (f:: Function , path, c; kwargs... ) = produce_or_load (path, c, f; kwargs... )
43
44
function produce_or_load (path, c, f:: Function ;
44
- suffix = " jld2" , prefix = default_prefix (c),
45
- tag:: Bool = istaggable (suffix), gitpath = projectdir (), loadfile = true ,
46
- force = false , verbose = true , storepatch = true , wsave_kwargs = Dict (), kwargs... )
45
+ suffix = " jld2" , prefix = default_prefix (c),
46
+ tag:: Bool = get (ENV , " DRWATSON_TAG" , istaggable (suffix)),
47
+ gitpath = projectdir (), loadfile = true ,
48
+ storepatch:: Bool = get (ENV , " DRWATSON_STOREPATCH" , true ),
49
+ force = false , verbose = true , wsave_kwargs = Dict (),
50
+ kwargs...
51
+ )
47
52
48
53
s = joinpath (path, savename (prefix, c, suffix; kwargs... ))
49
54
@@ -118,21 +123,29 @@ end
118
123
# tag saving #
119
124
# ###############################################################################
120
125
"""
121
- tagsave(file::String, d::AbstractDict; safe = false, gitpath = projectdir(), storepatch = true, force = false, kwargs...)
126
+ tagsave(file::String, d::AbstractDict; kwargs...)
122
127
First [`tag!`](@ref) dictionary `d` and then save `d` in `file`.
123
- If `safe = true` save the file using [`safesave`](@ref).
124
128
125
129
"Tagging" means that when saving the dictionary, an extra field
126
130
`:gitcommit` is added to establish reproducibility of results using
127
- Git. If the Git repository is dirty, one more field `:gitpatch` is
128
- added that stores the difference string. If a dictionary already
129
- contains a key `:gitcommit`, it is not overwritten, unless,
131
+ Git. If the Git repository is dirty and `storepatch=true` , one more field `:gitpatch` is
132
+ added that stores the difference string. If a dictionary already
133
+ contains a key `:gitcommit`, it is not overwritten, unless
130
134
`force=true`. For more details, see [`tag!`](@ref).
131
135
136
+ Keywords `gitpath, storepatch, force,` are propagated to [`tag!`](@ref).
132
137
Any additional keyword arguments are propagated to `wsave`, to e.g.
133
138
enable compression.
139
+
140
+ The keyword `safe = get(ENV, "DRWATSON_SAFESAVE", false)` decides whether
141
+ to save the file using [`safesave`](@ref).
134
142
"""
135
- function tagsave (file, d; safe:: Bool = false , gitpath = projectdir (), storepatch = true , force = false , source = nothing , kwargs... )
143
+ function tagsave (file, d;
144
+ gitpath = projectdir (),
145
+ safe:: Bool = get (ENV , " DRWATSON_SAFESAVE" , false ),
146
+ storepatch:: Bool = get (ENV , " DRWATSON_STOREPATCH" , true ),
147
+ force = false , source = nothing , kwargs...
148
+ )
136
149
d2 = tag! (d, gitpath= gitpath, storepatch= storepatch, force= force, source= source)
137
150
if safe
138
151
safesave (file, copy (d2); kwargs... )
@@ -200,7 +213,7 @@ function increment_backup_num(filepath)
200
213
path, filename = splitdir (filepath)
201
214
fname, suffix = splitext (filename)
202
215
m = match (r" ^(.*)_#([0-9]+)$" , fname)
203
- if m == nothing
216
+ if m === nothing
204
217
return joinpath (path, " $(fname) _#1$(suffix) " )
205
218
end
206
219
newnum = string (parse (Int, m. captures[2 ]) + 1 )
@@ -228,7 +241,7 @@ Save each entry in `dicts` into a unique temporary file in the directory `tmp`.
228
241
Then return the list of file names (relative to `tmp`) that were used
229
242
for saving each dictionary. Each dictionary can then be loaded back by calling
230
243
231
- FileIO.load (nth_tmpfilename, "params")
244
+ wload (nth_tmpfilename, "params")
232
245
233
246
`tmp` defaults to `projectdir("_research", "tmp")`.
234
247
0 commit comments