diff --git a/.travis.yml b/.travis.yml index 40b89dd..c351ab5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,7 +86,9 @@ install: script: # Build library and collect into libs subdirectory - build_lib "$PLAT" "$INTERFACE64" - - source travis-ci/build_wheel.sh + - libc=${MB_ML_LIBC:-manylinux} + - docker_image=quay.io/pypa/${libc}${MB_ML_VER}_${PLAT} + - docker run --rm -e INTERFACE64="${INTERFACE64}" -v $(pwd):/openblas $docker_image /bin/bash -xe /openblas/travis-ci/build_wheel.sh after_success: # Upload libraries to the shared staging area on anaconda.org diff --git a/local/scipy_openblas64/__init__.py b/local/scipy_openblas64/__init__.py index 752569a..a870fc5 100644 --- a/local/scipy_openblas64/__init__.py +++ b/local/scipy_openblas64/__init__.py @@ -11,7 +11,8 @@ _HERE = Path(__file__).resolve().parent -__all__ = ["get_include_dir", "get_lib_dir", "get_library", "get_pkg_config", "openblas_config"] +__all__ = ["get_include_dir", "get_lib_dir", "get_library", "get_pkg_config", + "get_openblas_config"] # Use importlib.metadata to single-source the version @@ -61,16 +62,16 @@ def get_pkg_config(): return dedent(f"""\ libdir={get_lib_dir()} includedir={get_include_dir()} - openblas_config= {openblas_config} - version={openblas_config.split(" ")[1]} + openblas_config= {get_openblas_config()} + version={get_openblas_config().split(" ")[1]} extralib={extralib} Name: openblas Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version Version: ${{version}} URL: https://github.com/xianyi/OpenBLAS - Libs: -L${libdir} -l{get_library()} - Libs.private: ${extralib} - Cflags: -I${includedir} + Libs: -L${{libdir}} -l{get_library()} + Libs.private: ${{extralib}} + Cflags: -I${{includedir}} """) @@ -92,22 +93,26 @@ def write__distributor_init(target): import scipy_openblas64 """)) -def _get_openblas_config(): +dll = None +def get_openblas_config(): """Use ctypes to pull out the config string from the OpenBLAS library. - It will be available as `openblas_config` """ - lib_dir = get_lib_dir() - if sys.platform == "win32": - # Get libopenblas*.lib - libnames = [x for x in os.listdir(lib_dir) if x.endswith(".dll")] - else: - # Get openblas* - libnames = [x for x in os.listdir(lib_dir) if x.startswith("libopenblas")] + # Keep the dll alive + global dll + if not dll: + lib_dir = get_lib_dir() + if sys.platform == "win32": + # Get libopenblas*.lib + libnames = [x for x in os.listdir(lib_dir) if x.endswith(".dll")] + else: + # Get openblas* + libnames = [x for x in os.listdir(lib_dir) if x.startswith("libopenblas")] - dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0])) + dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0])) openblas_config = dll.openblas_get_config64_ openblas_config.restype = ctypes.c_char_p - return openblas_config() - -# This global will keep the shared object in memory -openblas_config = _get_openblas_config() + bytes = openblas_config() + return bytes.decode("utf8") + +# Import the DLL which will make the namespace available to NumPy/SciPy +get_openblas_config() diff --git a/local/scipy_openblas64/__main__.py b/local/scipy_openblas64/__main__.py index ec7c4e0..f35d32e 100644 --- a/local/scipy_openblas64/__main__.py +++ b/local/scipy_openblas64/__main__.py @@ -1,4 +1,4 @@ import scipy_openblas64 if __name__ == "__main__": - print(f"OpenBLAS using '{scipy_openblas64.openblas_config}'") + print(f"OpenBLAS using '{scipy_openblas64.get_openblas_config()}'") diff --git a/travis-ci/build_wheel.sh b/travis-ci/build_wheel.sh index 5b7a5d1..a9db971 100644 --- a/travis-ci/build_wheel.sh +++ b/travis-ci/build_wheel.sh @@ -46,6 +46,7 @@ if [ "${INTERFACE64}" != "1" ]; then rm local/scipy_openblas32/*.bak fi +rm -rf dist/* python3.7 -m pip wheel -w dist -vv . if [ $(uname) == "Darwin" ]; then @@ -56,6 +57,11 @@ if [ $(uname) == "Darwin" ]; then else auditwheel repair -w dist --lib-sdir /lib dist/*.whl rm dist/scipy_openblas*-none-any.whl + # Add an RPATH to libgfortran: + # https://github.com/pypa/auditwheel/issues/451 + unzip dist/*.whl "*libgfortran*" + patchelf --force-rpath --set-rpath '$ORIGIN' */lib/libgfortran* + zip dist/*.whl */lib/libgfortran* fi if [ "${PLAT}" == "arm64" ]; then