88from hpat .io .pio_api import (h5file_type , h5dataset_or_group_type , h5dataset_type ,
99 h5group_type )
1010from hpat .str_ext import string_type , gen_get_unicode_chars , gen_std_str_to_unicode
11- import h5py
11+
1212from llvmlite import ir as lir
1313import llvmlite .binding as ll
1414import hpat .io
1515if hpat .config ._has_h5py :
16+ import h5py
1617 from hpat .io import _hdf5
1718 ll .add_symbol ('hpat_h5_open' , _hdf5 .hpat_h5_open )
1819 ll .add_symbol ('hpat_h5_open_dset_or_group_obj' , _hdf5 .hpat_h5_open_dset_or_group_obj )
2930
3031h5file_lir_type = lir .IntType (64 )
3132
32- # hid_t is 32bit in 1.8 but 64bit in 1.10
33- if h5py .version .hdf5_version_tuple [1 ] == 8 :
34- h5file_lir_type = lir .IntType (32 )
35- else :
36- assert h5py .version .hdf5_version_tuple [1 ] == 10
33+ if hpat .config ._has_h5py :
34+ # hid_t is 32bit in 1.8 but 64bit in 1.10
35+ if h5py .version .hdf5_version_tuple [1 ] == 8 :
36+ h5file_lir_type = lir .IntType (32 )
37+ else :
38+ assert h5py .version .hdf5_version_tuple [1 ] == 10
3739
3840h5g_close = types .ExternalFunction ("h5g_close" , types .none (h5group_type ))
3941
@@ -48,19 +50,20 @@ def h5_open_dset_lower(context, builder, sig, args):
4850 return builder .call (fn , [fg_id , dset_name ])
4951
5052
51- @lower_builtin (h5py .File , string_type , string_type )
52- @lower_builtin (h5py .File , string_type , string_type , types .int64 )
53- def h5_open (context , builder , sig , args ):
54- fname = args [0 ]
55- mode = args [1 ]
56- fname = gen_get_unicode_chars (context , builder , fname )
57- mode = gen_get_unicode_chars (context , builder , mode )
58-
59- is_parallel = context .get_constant (types .int64 , 0 ) if len (args ) < 3 else args [2 ]
60- fnty = lir .FunctionType (h5file_lir_type , [lir .IntType (
61- 8 ).as_pointer (), lir .IntType (8 ).as_pointer (), lir .IntType (64 )])
62- fn = builder .module .get_or_insert_function (fnty , name = "hpat_h5_open" )
63- return builder .call (fn , [fname , mode , is_parallel ])
53+ if hpat .config ._has_h5py :
54+ @lower_builtin (h5py .File , string_type , string_type )
55+ @lower_builtin (h5py .File , string_type , string_type , types .int64 )
56+ def h5_open (context , builder , sig , args ):
57+ fname = args [0 ]
58+ mode = args [1 ]
59+ fname = gen_get_unicode_chars (context , builder , fname )
60+ mode = gen_get_unicode_chars (context , builder , mode )
61+
62+ is_parallel = context .get_constant (types .int64 , 0 ) if len (args ) < 3 else args [2 ]
63+ fnty = lir .FunctionType (h5file_lir_type , [lir .IntType (
64+ 8 ).as_pointer (), lir .IntType (8 ).as_pointer (), lir .IntType (64 )])
65+ fn = builder .module .get_or_insert_function (fnty , name = "hpat_h5_open" )
66+ return builder .call (fn , [fname , mode , is_parallel ])
6467
6568
6669@lower_builtin (pio_api .h5size , h5dataset_or_group_type , types .int32 )
0 commit comments