1111
1212_HERE = Path (__file__ ).resolve ().parent
1313
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" ]
1516
1617# Use importlib.metadata to single-source the version
1718
@@ -61,16 +62,16 @@ def get_pkg_config():
6162 return dedent (f"""\
6263 libdir={ get_lib_dir ()}
6364 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 ]}
6667 extralib={ extralib }
6768 Name: openblas
6869 Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version
6970 Version: ${{version}}
7071 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} }
7475 """ )
7576
7677
@@ -92,22 +93,26 @@ def write__distributor_init(target):
9293 import scipy_openblas64
9394 """ ))
9495
95- def _get_openblas_config ():
96+ dll = None
97+ def get_openblas_config ():
9698 """Use ctypes to pull out the config string from the OpenBLAS library.
97- It will be available as `openblas_config`
9899 """
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" )]
106110
107- dll = ctypes .CDLL (os .path .join (lib_dir , libnames [0 ]))
111+ dll = ctypes .CDLL (os .path .join (lib_dir , libnames [0 ]))
108112 openblas_config = dll .openblas_get_config64_
109113 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