11
11
12
12
_HERE = Path (__file__ ).resolve ().parent
13
13
14
- __all__ = ["get_include_dir" , "get_lib_dir" , "get_library" , "get_pkg_config" , "openblas_config" ]
14
+ __all__ = ["get_include_dir" , "get_lib_dir" , "get_library" , "get_pkg_config" ,
15
+ "get_openblas_config" ]
15
16
16
17
# Use importlib.metadata to single-source the version
17
18
@@ -61,16 +62,16 @@ def get_pkg_config():
61
62
return dedent (f"""\
62
63
libdir={ get_lib_dir ()}
63
64
includedir={ get_include_dir ()}
64
- openblas_config= { openblas_config }
65
- version={ openblas_config .split (" " )[1 ]}
65
+ openblas_config= { get_openblas_config () }
66
+ version={ get_openblas_config () .split (" " )[1 ]}
66
67
extralib={ extralib }
67
68
Name: openblas
68
69
Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version
69
70
Version: ${{version}}
70
71
URL: https://github.com/xianyi/OpenBLAS
71
- Libs: -L${ libdir } -l{ get_library ()}
72
- Libs.private: ${ extralib }
73
- Cflags: -I${ includedir }
72
+ Libs: -L${{ libdir} } -l{ get_library ()}
73
+ Libs.private: ${{ extralib} }
74
+ Cflags: -I${{ includedir} }
74
75
""" )
75
76
76
77
@@ -92,22 +93,26 @@ def write__distributor_init(target):
92
93
import scipy_openblas64
93
94
""" ))
94
95
95
- def _get_openblas_config ():
96
+ dll = None
97
+ def get_openblas_config ():
96
98
"""Use ctypes to pull out the config string from the OpenBLAS library.
97
- It will be available as `openblas_config`
98
99
"""
99
- lib_dir = get_lib_dir ()
100
- if sys .platform == "win32" :
101
- # Get libopenblas*.lib
102
- libnames = [x for x in os .listdir (lib_dir ) if x .endswith (".dll" )]
103
- else :
104
- # Get openblas*
105
- libnames = [x for x in os .listdir (lib_dir ) if x .startswith ("libopenblas" )]
100
+ # Keep the dll alive
101
+ global dll
102
+ if not dll :
103
+ lib_dir = get_lib_dir ()
104
+ if sys .platform == "win32" :
105
+ # Get libopenblas*.lib
106
+ libnames = [x for x in os .listdir (lib_dir ) if x .endswith (".dll" )]
107
+ else :
108
+ # Get openblas*
109
+ libnames = [x for x in os .listdir (lib_dir ) if x .startswith ("libopenblas" )]
106
110
107
- dll = ctypes .CDLL (os .path .join (lib_dir , libnames [0 ]))
111
+ dll = ctypes .CDLL (os .path .join (lib_dir , libnames [0 ]))
108
112
openblas_config = dll .openblas_get_config64_
109
113
openblas_config .restype = ctypes .c_char_p
110
- return openblas_config ()
111
-
112
- # This global will keep the shared object in memory
113
- openblas_config = _get_openblas_config ()
114
+ bytes = openblas_config ()
115
+ return bytes .decode ("utf8" )
116
+
117
+ # Import the DLL which will make the namespace available to NumPy/SciPy
118
+ get_openblas_config ()
0 commit comments