Skip to content

Commit 506109c

Browse files
pjgorskiDatseris
andauthored
Removing double prefixes bug in produce_or_load (#393)
* Removing double prefixes bug in produce_or_load * correcting test when default_prefix was modified * Correcting produce_or_load: filename as function * Update Project.toml * Update CHANGELOG.md --------- Co-authored-by: George Datseris <[email protected]>
1 parent ab87902 commit 506109c

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 2.12.6
2+
- Crucial bugfix to `produce_or_load`. When used with a prefix, it attached double prefix to the file (one coming as a duplicate from `savename`). This is now fixed, but it means that some files produced with prefix and `produce_or_load` in v2.12 may be re-produced after this update.
3+
14
# 2.12.0
25
- Arbitrary functions extracting strings from data can be used in `produce_or_load` instead of `savename`. `hash` is the most useful function here. An example in Real World Examples highlights this.
36
- Additional keywords in `produce_or_load` propagated to `savename` are deprecated.

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DrWatson"
22
uuid = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
33
repo = "https://github.com/JuliaDynamics/DrWatson.jl.git"
4-
version = "2.12.5"
4+
version = "2.12.6"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/saving_files.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ function produce_or_load(f::Function, config, path::String = "";
7979
for the keyword `filename` as `filename = config -> savename(config; kwargs...)`
8080
"""
8181
end
82-
if filename === nothing
83-
filename = config -> savename(config; kwargs...)
84-
end
8582
# Prepare absolute file name
86-
if filename isa AbstractString
87-
name = filename
88-
else
83+
if filename === nothing
84+
filename = config -> savename(prefix, config, suffix; kwargs...)
85+
name = filename(config)
86+
elseif filename isa AbstractString
87+
name = append_prefix_suffix(filename, prefix, suffix)
88+
else #if filename isa Function
8989
name = string(filename(config))
90+
name = append_prefix_suffix(name, prefix, suffix)
9091
end
91-
name = append_prefix_suffix(name, prefix, suffix)
9292
file = joinpath(path, name)
9393
# Run the remaining logic on whether to produce or load
9494
if !force && isfile(file)

test/savefiles_tests.jl

+17
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,23 @@ end
307307
rm(path; recursive = true, force = true)
308308
end
309309

310+
# Testing proper filenames when default_prefix was modified. See https://github.com/JuliaDynamics/DrWatson.jl/issues/392
311+
@testset "@produce_or_load with default_prefix modified" begin
312+
path = mktempdir()
313+
314+
struct Dummy
315+
x
316+
y
317+
end
318+
simulation = Dummy(1,2)
319+
DrWatson.default_prefix(d::Dummy) = "Prefix_"
320+
321+
sim, path = produce_or_load(f, simulation, "")
322+
@test path == savename(simulation, "jld2")
323+
324+
rm(path)
325+
DrWatson.default_prefix(ntuple::NamedTuple) = ""
326+
end
310327

311328

312329
################################################################################

0 commit comments

Comments
 (0)