From 5c0b51602692dfedc37188ba6a4fc1f319634b21 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Tue, 22 Feb 2022 10:15:43 -0500 Subject: [PATCH] * First attempt to fix lmod "module" for ipython ("fix1") (dated: 2020-06-09) Sigs: # -rw------- 1 wpurwant users 915 2020-06-09 17:20 lmod_python_fix1.py # bb42b2bde01f2e235eb205fe555fab9e lmod_python_fix1.py --- lmod/ipython/startup/lmod_python_fix.py | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lmod/ipython/startup/lmod_python_fix.py diff --git a/lmod/ipython/startup/lmod_python_fix.py b/lmod/ipython/startup/lmod_python_fix.py new file mode 100644 index 0000000..39c91a3 --- /dev/null +++ b/lmod/ipython/startup/lmod_python_fix.py @@ -0,0 +1,28 @@ +# -*- python -*- +#from __future__ import print_function +#from subprocess import PIPE, Popen +import os, sys + +sys.path.append('/shared/apps/common/lmod/current/init') + +from env_modules_python import module as lmod_module + +def module(command, *arguments): + lmod_module(command, *arguments) + sys.path = os.environ.get('PYTHONPATH').split(':') + sys.path + manual_ld_library_dir = os.environ.get('LMOD_MANUAL_LD_LIBRARY_PATH') + + for search_path in os.getenv('LD_LIBRARY_PATH').split(':')[::-1]: + if not os.path.isdir(search_path): + continue + if search_path == manual_ld_library_dir: + continue + + for f in os.listdir(search_path): + if '.so' in f: + src = f'{search_path}/{f}' + tgt = f'{manual_ld_library_dir}/{f}' + if os.path.islink(tgt): + os.unlink(tgt) + + os.symlink(src, tgt)