diff --git a/Project.toml b/Project.toml index d27dbd6b4..5cd103edd 100644 --- a/Project.toml +++ b/Project.toml @@ -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] diff --git a/src/fileio.jl b/ext/FileIOExt.jl similarity index 89% rename from src/fileio.jl rename to ext/FileIOExt.jl index 468ba19cb..6674f1e51 100644 --- a/src/fileio.jl +++ b/ext/FileIOExt.jl @@ -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) @@ -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"}; @@ -75,3 +72,5 @@ function fileio_save( end end end + +end diff --git a/ext/OrderedCollectionsFileIOExt.jl b/ext/OrderedCollectionsFileIOExt.jl new file mode 100644 index 000000000..7f3cf4fcf --- /dev/null +++ b/ext/OrderedCollectionsFileIOExt.jl @@ -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 diff --git a/src/HDF5.jl b/src/HDF5.jl index b533d84a0..8689fd32c 100644 --- a/src/HDF5.jl +++ b/src/HDF5.jl @@ -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 # @@ -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())