diff --git a/shell/preload/sitecustomize.js b/shell/preload/sitecustomize.js index dbb9198f..ec8704f2 100644 --- a/shell/preload/sitecustomize.js +++ b/shell/preload/sitecustomize.js @@ -28,6 +28,7 @@ function run() { numParam, file_task_before, file_task_before_js, + file_preload_js, dir_scripts, task_before, PREV_NODE_OPTIONS, @@ -40,7 +41,13 @@ function run() { const fileName = process.argv[1].replace(`${dir_scripts}/`, ''); const tempFile = `/tmp/env_${process.pid}.json`; + // Export NODE_OPTIONS so task_before can use it for any node commands + const nodeOptionsForBash = file_preload_js + ? `-r ${file_preload_js} ${PREV_NODE_OPTIONS || ''}` + : PREV_NODE_OPTIONS || ''; + const commands = [ + `export NODE_OPTIONS="${nodeOptionsForBash}"`, `source ${file_task_before} ${fileName}`, task_before ? `eval '${task_before.replace(/'/g, "'\\''")}'` : null, `echo -e '${splitStr}'`, diff --git a/shell/preload/sitecustomize.py b/shell/preload/sitecustomize.py index f4c51dd6..864a9026 100644 --- a/shell/preload/sitecustomize.py +++ b/shell/preload/sitecustomize.py @@ -44,11 +44,19 @@ def run(): split_str = "__sitecustomize__" file_name = sys.argv[0].replace(f"{os.getenv('dir_scripts')}/", "") + # Get environment variables needed for PYTHONPATH + dir_preload = os.getenv("dir_preload", "") + dir_config = os.getenv("dir_config", "") + # 创建临时文件路径 temp_file = f"/tmp/env_{os.getpid()}.json" + # Export PYTHONPATH so task_before can use it for any python commands + pythonpath_for_bash = f"{dir_preload}:{dir_config}:{prev_pythonpath}" if dir_preload else prev_pythonpath + # 构建命令数组 commands = [ + f'export PYTHONPATH="{pythonpath_for_bash}"', f'source {os.getenv("file_task_before")} {file_name}' ]