From 7c02045fa1bd7f1511e1a0cb921e340a0fcc0405 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Tue, 22 Feb 2022 09:55:55 -0500 Subject: [PATCH] * Saved the original lmod_python.py and ~/.ipython/profile_default/startup/000-odurc-lmod.py from Wahab cluster on the "legacy" lmod-based ipython/jupyter session. Last update: 2020-06-09. Sigs: # -rw-r--r-- 1 wpurwant users 179 2020-06-03 15:49 000-odurc-lmod.py # -rw-r--r-- 1 wpurwant users 843 2020-03-17 14:02 lmod_python.py # 8718a2d7a7d6d152701e6c31254f7168 000-odurc-lmod.py # 24a740e83656875bd39f942529378414 lmod_python.py --- lmod/ipython/startup/000-odurc-lmod.py.orig | 6 +++++ lmod/ipython/startup/lmod_python.py.orig | 26 +++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 lmod/ipython/startup/000-odurc-lmod.py.orig create mode 100644 lmod/ipython/startup/lmod_python.py.orig diff --git a/lmod/ipython/startup/000-odurc-lmod.py.orig b/lmod/ipython/startup/000-odurc-lmod.py.orig new file mode 100644 index 0000000..13763a5 --- /dev/null +++ b/lmod/ipython/startup/000-odurc-lmod.py.orig @@ -0,0 +1,6 @@ +try: + from lmod_python import module +except ModuleNotFoundError: + import sys + sys.path.append('/shared/apps/common/lmod/scripts/init') + from lmod_python import module diff --git a/lmod/ipython/startup/lmod_python.py.orig b/lmod/ipython/startup/lmod_python.py.orig new file mode 100644 index 0000000..b4cc2f8 --- /dev/null +++ b/lmod/ipython/startup/lmod_python.py.orig @@ -0,0 +1,26 @@ +# -*- 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 + + 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)