Skip to content

Commit

Permalink
Move FileIO support into extension
Browse files Browse the repository at this point in the history
  • Loading branch information
topolarity committed Oct 9, 2024
1 parent fbcd95d commit 6416915
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
MPIPreferences = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267"

[weakdeps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"

[extensions]
FileIOExt = "FileIO"
OrderedCollectionsFileIOExt = ["FileIO", "OrderedCollections"]
MPIExt = "MPI"

[compat]
Expand Down
13 changes: 6 additions & 7 deletions src/fileio.jl → ext/FileIOExt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import .FileIO
module FileIOExt

import HDF5: File, Group, h5open, fileio_save, fileio_load, _infer_track_order
import FileIO

function loadtodict!(d::AbstractDict, g::Union{File,Group}, prefix::String="")
for k in keys(g)
Expand All @@ -14,12 +17,6 @@ end
_infer_track_order(track_order::Union{Nothing,Bool}, dict::AbstractDict) =
something(track_order, false)

@require OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" begin
_infer_track_order(
track_order::Union{Nothing,Bool}, dict::OrderedCollections.OrderedDict
) = something(track_order, true)
end

# load with just a filename returns a flat dictionary containing all the variables
function fileio_load(
f::FileIO.File{FileIO.format"HDF5"};
Expand Down Expand Up @@ -75,3 +72,5 @@ function fileio_save(
end
end
end

end
10 changes: 10 additions & 0 deletions ext/OrderedCollectionsFileIOExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module OrderedCollectionsFileIOExt
import HDF5
import OrderedCollections

function HDF5._infer_track_order(
track_order::Union{Nothing,Bool}, dict::OrderedCollections.OrderedDict
)
return something(track_order, true)
end
end
7 changes: 5 additions & 2 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ Returns `true` if the HDF5 libraries were compiled with ros3 support
"""
has_ros3() = HAS_ROS3[]

# Functions implemented by extensions
function _infer_track_order end
function fileio_save end
function fileio_load end

function __init__()
# HDF5.API.__init__() is run first
#
Expand All @@ -118,8 +123,6 @@ function __init__()
ASCII_ATTRIBUTE_PROPERTIES.char_encoding = :ascii
UTF8_ATTRIBUTE_PROPERTIES.char_encoding = :utf8

@require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" include("fileio.jl")

@require H5Zblosc = "c8ec2601-a99c-407f-b158-e79c03c2f5f7" begin
set_blosc!(p::Properties, val::Bool) =
val && push!(Filters.FilterPipeline(p), H5Zblosc.BloscFilter())
Expand Down

0 comments on commit 6416915

Please sign in to comment.