Skip to content

Commit 038f96c

Browse files
topolaritymkitti
andauthored
Move FileIO support into extension (#1166)
Co-authored-by: Mark Kittisopikul <mkitti@users.noreply.github.com>
1 parent 08d030f commit 038f96c

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ BloscExt = "Blosc"
3333
CodecBzip2Ext = "CodecBzip2"
3434
CodecLz4Ext = "CodecLz4"
3535
CodecZstdExt = "CodecZstd"
36+
FileIOExt = "FileIO"
3637
MPIExt = "MPI"
38+
OrderedCollectionsFileIOExt = ["FileIO", "OrderedCollections"]
3739
bitshuffle_jll_ext = "bitshuffle_jll"
3840

3941
[extras]
@@ -63,5 +65,7 @@ Blosc = "a74b3585-a348-5f62-a45c-50e91977d574"
6365
CodecBzip2 = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
6466
CodecLz4 = "5ba52731-8f18-5e0d-9241-30f10d1ec561"
6567
CodecZstd = "6b39b394-51ab-5f42-8807-6242bab2b4c2"
68+
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
6669
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
70+
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
6771
bitshuffle_jll = "228fe19c-1b83-5282-a626-13744502a320"

src/fileio.jl renamed to ext/FileIOExt.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import .FileIO
1+
module FileIOExt
2+
3+
import HDF5: File, Group, h5open, fileio_save, fileio_load, _infer_track_order
4+
@static if isdefined(Base, :get_extension)
5+
import FileIO
6+
else
7+
import ..FileIO
8+
import Requires: @require
9+
end
210

311
function loadtodict!(d::AbstractDict, g::Union{File,Group}, prefix::String="")
412
for k in keys(g)
@@ -14,10 +22,10 @@ end
1422
_infer_track_order(track_order::Union{Nothing,Bool}, dict::AbstractDict) =
1523
something(track_order, false)
1624

17-
@require OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" begin
18-
_infer_track_order(
19-
track_order::Union{Nothing,Bool}, dict::OrderedCollections.OrderedDict
20-
) = something(track_order, true)
25+
@static if !isdefined(Base, :get_extension)
26+
@require OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" include(
27+
"OrderedCollectionsFileIOExt.jl"
28+
)
2129
end
2230

2331
# load with just a filename returns a flat dictionary containing all the variables
@@ -75,3 +83,5 @@ function fileio_save(
7583
end
7684
end
7785
end
86+
87+
end

ext/OrderedCollectionsFileIOExt.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module OrderedCollectionsFileIOExt
2+
3+
import HDF5: _infer_track_order
4+
@static if isdefined(Base, :get_extension)
5+
import OrderedCollections
6+
else
7+
import ..OrderedCollections
8+
end
9+
10+
function _infer_track_order(
11+
track_order::Union{Nothing,Bool}, dict::OrderedCollections.OrderedDict
12+
)
13+
return something(track_order, true)
14+
end
15+
16+
end

src/HDF5.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ Returns `true` if the HDF5 libraries were compiled with ros3 support
107107
"""
108108
has_ros3() = HAS_ROS3[]
109109

110+
# Functions implemented by extensions
111+
function _infer_track_order end
112+
function fileio_save end
113+
function fileio_load end
114+
110115
function __init__()
111116
# HDF5.API.__init__() is run first
112117
#
@@ -118,7 +123,11 @@ function __init__()
118123
ASCII_ATTRIBUTE_PROPERTIES.char_encoding = :ascii
119124
UTF8_ATTRIBUTE_PROPERTIES.char_encoding = :utf8
120125

121-
@require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" include("fileio.jl")
126+
@static if !isdefined(Base, :get_extension)
127+
@require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" include(
128+
"../ext/FileIOExt.jl"
129+
)
130+
end
122131

123132
@require H5Zblosc = "c8ec2601-a99c-407f-b158-e79c03c2f5f7" begin
124133
set_blosc!(p::Properties, val::Bool) =

0 commit comments

Comments
 (0)