@@ -35,6 +35,11 @@ def localpath(*args):
35
35
localpath ("lzf/lzf/lzf_c.c" ),
36
36
localpath ("lzf/lzf/lzf_d.c" )]}
37
37
38
+ FALLBACK_PATHS = {
39
+ 'include_dirs' : [],
40
+ 'library_dirs' : []
41
+ }
42
+
38
43
COMPILER_SETTINGS = {
39
44
'libraries' : ['hdf5' , 'hdf5_hl' ],
40
45
'include_dirs' : [localpath ('lzf' )],
@@ -49,8 +54,8 @@ def localpath(*args):
49
54
('H5_BUILT_AS_DYNAMIC_LIB' , None )
50
55
])
51
56
else :
52
- COMPILER_SETTINGS ['include_dirs' ].extend (['/opt/local/include' , '/usr/local/include' ])
53
- COMPILER_SETTINGS ['library_dirs' ].extend (['/opt/local/include ' , '/usr/local/include ' ])
57
+ FALLBACK_PATHS ['include_dirs' ].extend (['/opt/local/include' , '/usr/local/include' ])
58
+ FALLBACK_PATHS ['library_dirs' ].extend (['/opt/local/lib ' , '/usr/local/lib ' ])
54
59
55
60
56
61
class h5py_build_ext (build_ext ):
@@ -76,14 +81,22 @@ def _make_extensions(config):
76
81
77
82
settings = COMPILER_SETTINGS .copy ()
78
83
79
- try :
80
- if pkgconfig .exists ('hdf5' ):
81
- pkgcfg = pkgconfig .parse ("hdf5" )
82
- settings ['include_dirs' ].extend (pkgcfg ['include_dirs' ])
83
- settings ['library_dirs' ].extend (pkgcfg ['library_dirs' ])
84
- settings ['define_macros' ].extend (pkgcfg ['define_macros' ])
85
- except EnvironmentError :
86
- pass
84
+ # Ensure that if a custom HDF5 location is specified, prevent
85
+ # pkg-config and fallback locations from appearing in the settings
86
+ if config .hdf5 is not None :
87
+ settings ['include_dirs' ].insert (0 , op .join (config .hdf5 , 'include' ))
88
+ settings ['library_dirs' ].insert (0 , op .join (config .hdf5 , 'lib' ))
89
+ else :
90
+ try :
91
+ if pkgconfig .exists ('hdf5' ):
92
+ pkgcfg = pkgconfig .parse ("hdf5" )
93
+ settings ['include_dirs' ].extend (pkgcfg ['include_dirs' ])
94
+ settings ['library_dirs' ].extend (pkgcfg ['library_dirs' ])
95
+ settings ['define_macros' ].extend (pkgcfg ['define_macros' ])
96
+ except EnvironmentError :
97
+ pass
98
+ settings ['include_dirs' ].extend (FALLBACK_PATHS ['include_dirs' ])
99
+ settings ['library_dirs' ].extend (FALLBACK_PATHS ['library_dirs' ])
87
100
88
101
try :
89
102
numpy_includes = numpy .get_include ()
@@ -97,12 +110,6 @@ def _make_extensions(config):
97
110
import mpi4py
98
111
settings ['include_dirs' ] += [mpi4py .get_include ()]
99
112
100
- # Ensure a custom location appears first, so we don't get a copy of
101
- # HDF5 from some default location in COMPILER_SETTINGS
102
- if config .hdf5 is not None :
103
- settings ['include_dirs' ].insert (0 , op .join (config .hdf5 , 'include' ))
104
- settings ['library_dirs' ].insert (0 , op .join (config .hdf5 , 'lib' ))
105
-
106
113
# TODO: should this only be done on UNIX?
107
114
if os .name != 'nt' :
108
115
settings ['runtime_library_dirs' ] = settings ['library_dirs' ]
0 commit comments