1+ """
2+
3+ """
4+
15import ctypes
26import os
37from pathlib import Path
2630
2731
2832def get_include_dir ():
33+ """Return the include directory needed for compilation
34+ """
2935 return os .path .join (_HERE , "include" )
3036
3137
3238def get_lib_dir ():
39+ """Return the lib directory needed for linking
40+ """
3341 return os .path .join (_HERE , "lib" )
3442
3543
3644def get_library ():
45+ """Return the lib name needed for linking
46+ """
3747 if sys .platform == "win32" :
3848 libs = [x for x in os .listdir (get_lib_dir ()) if x .endswith (".lib" )]
3949 return os .path .splitext (libs [0 ])[0 ]
4050 else :
4151 return "openblas_python"
4252
4353def get_pkg_config ():
54+ """Return a multi-line string that, when saved to a file, can be used with
55+ pkg-config for build systems like meson
56+ """
4457 if sys .platform == "win32" :
4558 extralib = "-defaultlib:advapi32 -lgfortran -defaultlib:advapi32 -lgfortran"
4659 else :
4760 extralib = "-lm -lpthread -lgfortran -lm -lpthread -lgfortran"
48- return f"""\
61+ return dedent ( f"""\
4962 libdir={ get_lib_dir ()}
5063 includedir={ get_include_dir ()}
5164 openblas_config= { openblas_config }
@@ -58,15 +71,27 @@ def get_pkg_config():
5871 Libs: -L${ libdir } -l{ get_library ()}
5972 Libs.private: ${ extralib }
6073 Cflags: -I${ includedir }
61- """
74+ """ )
6275
6376
6477if sys .platform == "win32" :
6578 os .add_dll_directory (get_lib_dir ())
6679
67-
80+ def write__distributor_init (target ):
81+ """Accepts a Pathlib or string of a directory.
82+ Write a pre-import file that will import scipy_openblas64 before
83+ continuing to import the library. This will load OpenBLAS into the
84+ executable's namespace and make the functions available for use.
85+ """
86+ fname = os .path .join (target , "_distributor_init.py" )
87+ with open (fname , "wt" , encoding = "utf8" ) as fid :
88+ fid .write (dedent (f"""\
89+ """ )
6890
6991def _get_openblas_config ():
92+ """Use ctypes to pull out the config string from the OpenBLAS library.
93+ It will be available as `openblas_config`
94+ """
7095 lib_dir = get_lib_dir ()
7196 if sys .platform == "win32" :
7297 # Get libopenblas*.lib
@@ -78,6 +103,6 @@ def _get_openblas_config():
78103 dll = ctypes .CDLL (os .path .join (lib_dir , libnames [0 ]))
79104 openblas_config = dll .openblas_get_config64_
80105 openblas_config .restype = ctypes .c_char_p
81- return openblas_config
106+ return openblas_config ()
82107
83108openblas_config = _get_openblas_config ()
0 commit comments