From 50a7a304ebf48fc61afd722b3935f49f50b097cd Mon Sep 17 00:00:00 2001 From: Joost van Zwieten Date: Wed, 14 Apr 2021 14:35:03 +0200 Subject: [PATCH] fix MKL tests in Github Actions The most recent version of MKL on PyPI ships only `libmkl_rt.so.1`, not `libmkl_rt.so`. In Nutils we load the latter. This causes two problems: in Github Actions we cannot find the location of the library directory where MKL is being installed, because we explicitly look for `libmkl_rt.so` and Nutils can't load the library because we explicitly load the missing unversioned library. This patch fixes both problems by searching for the versioned library and adding a symlink to the unversioned library. --- .github/workflows/test.yaml | 7 +++---- devtools/gha/configure_mkl.py | 25 +++++++++++++++++++++++++ devtools/gha/get_lib_dir.py | 16 ---------------- 3 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 devtools/gha/configure_mkl.py delete mode 100644 devtools/gha/get_lib_dir.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 603953625..4a0d36531 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -100,13 +100,12 @@ jobs: # Install Nutils from `dist` dir created in job # `build-python-package`. python -um pip install --no-index --find-links ./dist nutils - - name: Get library directory - id: get-lib-dir + - name: Configure MKL + id: configure-mkl if: ${{ matrix.matrix-backend == 'mkl' }} - run: python -um devtools.gha.get_lib_dir + run: python -um devtools.gha.configure_mkl - name: Test env: - LD_LIBRARY_PATH: ${{ steps.get-lib-dir.outputs.libdir }} NUTILS_DEBUG: all run: | mkdir testenv diff --git a/devtools/gha/configure_mkl.py b/devtools/gha/configure_mkl.py new file mode 100644 index 000000000..9ecff944e --- /dev/null +++ b/devtools/gha/configure_mkl.py @@ -0,0 +1,25 @@ +from .. import log +import sys, site, os + +libsubdir = 'lib' +prefixes = list(site.PREFIXES) +if hasattr(site, 'getuserbase'): + prefixes.append(site.getuserbase()) +for prefix in prefixes: + libdir = os.path.join(prefix, libsubdir) + if not os.path.exists(os.path.join(libdir, 'libmkl_rt.so.1')): + continue + log.set_output('libdir', libdir) + break +else: + log.error('cannot find {} in any of the following dirs: {}'.format('libmkl_rt.so.1', ' '.join(prefixes))) + +lib = os.path.join(libdir, 'libmkl_rt.so') +if not os.path.exists(lib): + os.symlink('libmkl_rt.so.1', lib) + +github_env = os.environ.get('GITHUB_ENV') +assert github_env +ld_library_path = ':'.join(filter(None, (os.environ.get('LD_LIBRARY_PATH', ''), libdir))) +with open(github_env, 'a') as f: + print('LD_LIBRARY_PATH={}'.format(ld_library_path), file=f) diff --git a/devtools/gha/get_lib_dir.py b/devtools/gha/get_lib_dir.py deleted file mode 100644 index 9e411ab92..000000000 --- a/devtools/gha/get_lib_dir.py +++ /dev/null @@ -1,16 +0,0 @@ -from .. import log -import sys, site, os - -libname = 'libmkl_rt.so' -libsubdir = 'lib' -prefixes = list(site.PREFIXES) -if hasattr(site, 'getuserbase'): - prefixes.append(site.getuserbase()) -for prefix in prefixes: - libdir = os.path.join(prefix, libsubdir) - if not os.path.exists(os.path.join(libdir, libname)): - continue - log.set_output('libdir', libdir) - break -else: - log.error('cannot find {} in any of the following dirs: {}'.format(libname, ' '.join(prefixes)))