3 Utility script invoked from CMake to locate the BLAS directory used by NumPy. 5 The script mirrors the previous inline CMake/Python logic by trying the more 6 recent NumPy APIs first, then falling back to older mechanisms, finally 7 defaulting to the standard ``../lib`` location inside the NumPy installation. 8 It prints the detected directory to stdout. 11 from __future__
import annotations
15 from pathlib
import Path
19 """Attempt to locate BLAS directory using newer NumPy internals.""" 22 from numpy._core._multiarray_umath
import __cpu_features__
26 numpy_dir = Path(numpy_module.__file__).resolve().parent
28 numpy_dir /
".." /
"lib",
29 numpy_dir /
".." /
".." /
"lib",
31 Path(
"/usr/local/lib"),
34 for path
in candidates:
35 abs_path = path.resolve()
42 """Fallback to NumPy's configuration metadata.""" 44 blas_info = numpy_module.__config__.get_info(
"blas_opt_info")
48 libs = blas_info.get(
"library_dirs", [])
if isinstance(blas_info, dict)
else []
50 return os.path.abspath(libs[0])
55 """Final fallback: assume BLAS resides in ../lib next to NumPy.""" 56 numpy_dir = Path(numpy_module.__file__).resolve().parent
57 return str((numpy_dir /
".." /
"lib").resolve())
63 except Exception
as exc:
64 print(f
"Failed to import numpy: {exc}", file=sys.stderr)
67 for resolver
in (_try_new_api, _try_config_api):
69 result = resolver(numpy)
81 if __name__ ==
"__main__":
82 raise SystemExit(
main())
def _try_new_api(numpy_module)
def _default_path(numpy_module)
def _try_config_api(numpy_module)