Skip to content

Commit 4d8de84

Browse files
authored
Merge pull request #28 from dahong67/drop-bson-mod
Set compat for BSON and drop bson_mod
2 parents b0b2e6a + 0a5e295 commit 4d8de84

File tree

5 files changed

+8
-21
lines changed

5 files changed

+8
-21
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1515
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1616

1717
[compat]
18-
BSON = "0.3.4"
18+
BSON = "0.3.9"
1919
Dates = "1.10"
2020
ExpressionExplorer = "1.1.3"
2121
JLD2 = "0.6.3"

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,6 @@ end
207207
end
208208
```
209209
210-
The module context for loading BSON files can be set via the `bson_mod` keyword argument:
211-
212-
```julia
213-
cache("data.bson"; bson_mod = @__MODULE__) do
214-
# cached computations
215-
end
216-
```
217-
218-
This may be useful when working in modules or in Pluto notebooks
219-
(see the [BSON.jl documentation](https://github.com/JuliaIO/BSON.jl?tab=readme-ov-file#loading-custom-data-types-within-modules)
220-
for more detail).
221-
222210
## Example: Caching the results of a sweep
223211
224212
It can be common to need to cache the results of a large sweep (e.g., over parameters or trials of a simulation).

src/function.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Function form
22

33
"""
4-
cache(f, path; overwrite=false, bson_mod=Main)
4+
cache(f, path; overwrite=false)
55
66
Cache the output of running `f()` in a cache file at `path`.
77
The output is loaded if the file exists and is saved otherwise.
@@ -20,7 +20,6 @@ e.g., to only cache a sweep when the full set is ready.
2020
2121
If `overwrite` is set to true, existing cache files will be overwritten
2222
with the results (and metadata) from a "fresh" call to `f()`.
23-
If necessary, the module to use for BSON can be set with `bson_mod`.
2423
2524
Tip: Use a `do...end` block to cache the results of a block of code.
2625
@@ -54,7 +53,7 @@ julia> cache(nothing) do
5453
(a = "a very time-consuming quantity to compute", b = "a very long simulation to run")
5554
```
5655
"""
57-
function cache(@nospecialize(f), path::AbstractString; overwrite = false, bson_mod = Main)
56+
function cache(@nospecialize(f), path::AbstractString; overwrite = false)
5857
# Check file extension
5958
ext = splitext(path)[2]
6059
(ext == ".bson" || ext == ".jld2") ||
@@ -102,7 +101,7 @@ function cache(@nospecialize(f), path::AbstractString; overwrite = false, bson_m
102101
else
103102
# Load metadata and output
104103
if ext == ".bson"
105-
data = BSON.load(path, bson_mod)
104+
data = BSON.load(path)
106105
version = data[:version]
107106
whenrun = data[:whenrun]
108107
runtime = data[:runtime]

src/macro.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Macro form
22

33
"""
4-
@cache path begin ... end [overwrite=true, bson_mod=@__MODULE__]
4+
@cache path begin ... end [overwrite=true]
55
66
Cache the variables assigned in the `begin...end` block as well as the final result.
77
Cached values are loaded if the file exists; the code is run and values are saved if not.
@@ -79,7 +79,7 @@ end
7979

8080
function _cache_block(mod, path, block, kwexprs...)
8181
# Process keyword arguments
82-
kwdict = Dict(:overwrite => false, :bson_mod => :(@__MODULE__))
82+
kwdict = Dict{Symbol,Any}(:overwrite => false)
8383
for expr in kwexprs
8484
if @capture(expr, lhs_ = rhs_) && haskey(kwdict, lhs)
8585
kwdict[lhs] = rhs

test/items/general.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
rm(modpath)
5151

5252
# 5. Save and check the output
53-
out = cache(modpath; bson_mod = @__MODULE__) do
53+
out = cache(modpath) do
5454
return DataFrame(; a = 1:10, b = 'a':'j')
5555
end
5656
@test out == DataFrame(; a = 1:10, b = 'a':'j')
@@ -59,7 +59,7 @@ end
5959
out = nothing
6060

6161
# 7. Load and check the output
62-
out = cache(modpath; bson_mod = @__MODULE__) do
62+
out = cache(modpath) do
6363
return DataFrame(; a = 1:10, b = 'a':'j')
6464
end
6565
@test out == DataFrame(; a = 1:10, b = 'a':'j')

0 commit comments

Comments
 (0)