From 232cc5cafb22800c2c2013d6c3e0105bd93ad646 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Tue, 22 Feb 2022 10:22:45 -0500 Subject: [PATCH] * Second attempt to fix lmod "module" for ipython ("fix2") (dated: 2020-06-09). WIP: Prevent indefinite lengthening of sys.path but not complete fix yet. Sigs: # -rw------- 1 wpurwant users 1290 2020-06-09 19:28 lmod_python_fix2.py # e218a4ac73762e0380c4bbe2290906b1 lmod_python_fix2.py --- lmod/ipython/startup/lmod_python_fix.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lmod/ipython/startup/lmod_python_fix.py b/lmod/ipython/startup/lmod_python_fix.py index 39c91a3..c72e300 100644 --- a/lmod/ipython/startup/lmod_python_fix.py +++ b/lmod/ipython/startup/lmod_python_fix.py @@ -9,8 +9,19 @@ 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 + # BAD: This will cause alteration of PYTHONPATH in a way that may not be desirable. + sys_path_orig = sys.path + PYTHONPATH = os.environ.get('PYTHONPATH') + sys_path_new = PYTHONPATH.split(':') if PYTHONPATH is not None else [] + for p in sys_path_orig: + if p not in sys_path_new: + sys_path_new.append(p) + print(sys_path_new) + sys.path = sys_path_new + manual_ld_library_dir = os.environ.get('LMOD_MANUAL_LD_LIBRARY_PATH') + if manual_ld_library_dir is None: + return for search_path in os.getenv('LD_LIBRARY_PATH').split(':')[::-1]: if not os.path.isdir(search_path):