Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ name = "JLSO"
uuid = "9da8a3cd-07a3-59c0-a743-3fdc52c30d11"
license = "MIT"
authors = ["Invenia Technical Computing Corperation"]
version = "2.6.0"
version = "2.7.0"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
Memento = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[compat]
BSON = "0.2.4, 0.3"
CodecZlib = "0.6, 0.7"
FilePathsBase = "0.7, 0.8, 0.9"
Memento = "0.10, 0.11, 0.12, 0.13, 1"
TimeZones = "0.9, 0.10, 0.11, 1"
TimeZones = "0.9, 0.10, 0.11, ~1.0, ~1.1, ~1.2, ~1.3, ~1.4, ~1.5"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to this PR.
CI has actually been broken for ages.
https://github.com/invenia/JLSO.jl/actions/runs/1428133005

This is because we have specimen files that were saved with TimeZones prior to v1.5.

julia = "0.7, 1.0"

[extras]
Expand Down
3 changes: 0 additions & 3 deletions src/JLSO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ module JLSO
using BSON
using CodecZlib
using FilePathsBase: AbstractPath
using Memento
using Pkg: Pkg
using Pkg.Types: semver_spec
using Serialization
Expand All @@ -59,8 +58,6 @@ export JLSOFile
const READABLE_VERSIONS = semver_spec("1, 2, 3, 4")
const WRITEABLE_VERSIONS = semver_spec("3, 4")

const LOGGER = getlogger(@__MODULE__)
__init__() = Memento.register(LOGGER)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

include("JLSOFile.jl")
include("upgrade.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/file_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function Base.read(io::IO, ::Type{JLSOFile})
)
)
catch e
warn(LOGGER, e)
@warn exception=e
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@warn exception=e
@warn exception = e

Dict("raw" => d["metadata"]["manifest"])
end

Expand Down
7 changes: 2 additions & 5 deletions src/metadata.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
function _versioncheck(version::VersionNumber, valid_versions)
supported = version ∈ valid_versions
supported || error(LOGGER, ArgumentError(
string(
"Unsupported version ($version). ",
"Expected a value between ($valid_versions)."
)
supported || throw(ArgumentError(
"Unsupported version ($version). Expected a value between ($valid_versions)."
))
Comment on lines +3 to 5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
supported || throw(ArgumentError(
"Unsupported version ($version). Expected a value between ($valid_versions)."
))
return supported || throw(
ArgumentError(
"Unsupported version ($version). Expected a value between ($valid_versions).",
),
)

end

Expand Down
2 changes: 1 addition & 1 deletion src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getindex(jlso::JLSOFile, name::Symbol)
decompressing_buffer = decompress(jlso.compression, buffer)
return deserialize(jlso.format, decompressing_buffer)
catch e
warn(LOGGER, e)
@warn exception=e
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@warn exception=e
@warn exception = e

return jlso.objects[name]
end
end
Expand Down
16 changes: 9 additions & 7 deletions src/upgrade.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ upgrade step. Won't be needed once the v2 file format is dropped.
The project generated is accurate, except for duplicated names (no UUID) and custom branchs.
"""
function upgrade(src, dest)
info(LOGGER, "Upgrading $src -> $dest")
@info "Upgrading" src dest
jlso = open(io -> read(io, JLSOFile), src)
write(dest, jlso)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
write(dest, jlso)
return write(dest, jlso)

end

function upgrade(src, dest, project, manifest)
info(LOGGER, "Upgrading $src -> $dest")
@info "Upgrading" src dest
parsed = BSON.load(string(src))
haskey(parsed["metadata"], "pkgs") && empty!(parsed["metadata"]["pkgs"])
d = upgrade_jlso(parsed)
Expand Down Expand Up @@ -81,7 +81,7 @@ version_number(x::String) = VersionNumber(x)

# Metadata changes to upgrade file from v1 to v2
function upgrade_jlso(raw_dict::AbstractDict, ::Val{1})
info(LOGGER, "Upgrading JLSO format from v1 to v2")
@info "Upgrading JLSO format from v1 to v2"
metadata = copy(raw_dict["metadata"])
version = version_number(metadata["version"])
@assert version ∈ semver_spec("1")
Expand All @@ -98,7 +98,7 @@ end

# Metadata changes to upgrade from v2 to v3
function upgrade_jlso(raw_dict::AbstractDict, ::Val{2})
info(LOGGER, "Upgrading JLSO format from v2 to v3")
@info "Upgrading JLSO format from v2 to v3"
metadata = copy(raw_dict["metadata"])
version = version_number(metadata["version"])
@assert version ∈ semver_spec("2")
Expand Down Expand Up @@ -154,10 +154,12 @@ function _upgrade_env(pkgs::Dict{String, VersionNumber})
catch e
# Warn about failure and fallback to simply trying to install the pacakges
# without version constraints.
warn(LOGGER) do
@warn(
"Failed to construct an environment with the provide package version " *
"($pkgs): $e.\n Falling back to simply adding the packages."
end
"\nFalling back to simply adding the packages.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
"\nFalling back to simply adding the packages.",
"\nFalling back to simply adding the packages.",

pkgs,
exception=e
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
exception=e
exception = e

)
Pkg.add([Pkg.PackageSpec(; name=key) for (key, value) in pkgs])
end

Expand Down
7 changes: 1 addition & 6 deletions test/JLSOFile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@
end

@testset "unknown format" begin
@test_throws(
LOGGER,
MethodError,
JLSOFile("String" => "Hello World!", format=:unknown)
)
@test_throws MethodError JLSOFile("String" => "Hello World!", format=:unknown)
end

@testset "show" begin
jlso = JLSOFile(:string => datas[:String])
expected = string(
Expand Down
4 changes: 2 additions & 2 deletions test/backwards_compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
@testset "$fn" for fn in readdir(dir)
if Int === Int32 && occursin("_serialize", fn)
# Julia 64-bit serializations won't load on 32-bit systems
@test_warn(JLSO.LOGGER, r"MethodError*", JLSO.load(joinpath(dir, fn)))
@test_logs (:warn, "MethodError") JLSO.load(joinpath(dir, fn))
else
jlso_data = @suppress_out JLSO.load(joinpath(dir, fn))
@test jlso_data == datas
Expand All @@ -81,7 +81,7 @@

if Int === Int32 && occursin("_serialize", fn)
# Julia 64-bit serializations won't load on 32-bit systems
@test_warn(JLSO.LOGGER, r"MethodError*", JLSO.load(dest))
@test_logs (:warn, "MethodError") JLSO.load(dest)
else
jlso_data = JLSO.load(dest)
@test jlso_data == datas
Expand Down
12 changes: 3 additions & 9 deletions test/file_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ end

# Test failing to deserialize data because of incompatible julia versions
# will return the raw bytes
result = if VERSION < v"1.2"
@test_warn(LOGGER, r"MethodError*", jlso[:data])
else
@test_warn(LOGGER, r"TypeError*", jlso[:data])
end

result = @test_logs (:warn,) jlso[:data]
@test result == hw_5

# TODO: Test that BSON works across julia versions using external files?
Expand Down Expand Up @@ -100,7 +95,7 @@ end

# Test failing to deserailize data because of missing modules will
# still return the raw bytes
result = @test_warn(LOGGER, r"KeyError*", jlso[:data])
result = @test_logs (:warn,) jlso[:data]
@test result == bytes
end

Expand Down Expand Up @@ -137,7 +132,7 @@ end

# Test failing to deserailize data because of missing modules will
# still return the raw bytes
result = @test_warn(LOGGER, r"UndefVarError*", jlso[:data])
result = @test_logs (:warn,) jlso[:data]

@test result == bytes
end
Expand Down Expand Up @@ -165,7 +160,6 @@ end
end
@testset "keys are not Symbols" begin
@test_throws(
getlogger(JLSO),
MethodError,
JLSO.save("breakfast.jlso", "food" => "☕️🥓🍳", "time" => Time(9, 0)),
)
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ using Distributed
using Documenter
using FilePathsBase: SystemPath
using InteractiveUtils
using Memento
using Pkg
using Random
using Serialization
using Suppressor
using Test

using JLSO
using JLSO: JLSOFile, LOGGER, upgrade_jlso
using JLSO: JLSOFile, upgrade_jlso

# To test different types from common external packages
using DataFrames
Expand Down