mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修复任务执行初始化环境变量 PYTHONPATH 和 NODE_OPTIONS 被清空
This commit is contained in:
parent
926ad067c1
commit
3d719baa54
|
@ -216,12 +216,12 @@ check_file() {
|
||||||
if [[ -f $file_env ]]; then
|
if [[ -f $file_env ]]; then
|
||||||
get_env_array
|
get_env_array
|
||||||
if [[ $isJsOrPythonFile == 'true' ]]; then
|
if [[ $isJsOrPythonFile == 'true' ]]; then
|
||||||
PREV_NODE_OPTIONS="${NODE_OPTIONS:=}"
|
export PREV_NODE_OPTIONS="${NODE_OPTIONS:=}"
|
||||||
PREV_PYTHONPATH="${PYTHONPATH:=}"
|
export PREV_PYTHONPATH="${PYTHONPATH:=}"
|
||||||
if [[ $1 == *.js ]] || [[ $1 == *.ts ]] || [[ $1 == *.mjs ]]; then
|
if [[ $1 == *.js ]] || [[ $1 == *.ts ]] || [[ $1 == *.mjs ]]; then
|
||||||
export NODE_OPTIONS="${NODE_OPTIONS} -r ${file_preload_js}"
|
export NODE_OPTIONS="-r ${file_preload_js} ${NODE_OPTIONS}"
|
||||||
else
|
else
|
||||||
export PYTHONPATH="${PYTHONPATH}:${dir_preload}:${dir_config}"
|
export PYTHONPATH="${dir_preload}:${dir_config}:${PYTHONPATH}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
. $file_env
|
. $file_env
|
||||||
|
|
|
@ -29,9 +29,12 @@ function run() {
|
||||||
file_task_before_js,
|
file_task_before_js,
|
||||||
dir_scripts,
|
dir_scripts,
|
||||||
task_before,
|
task_before,
|
||||||
|
PREV_NODE_OPTIONS
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
process.env.NODE_OPTIONS = PREV_NODE_OPTIONS;
|
||||||
|
|
||||||
const splitStr = '__sitecustomize__';
|
const splitStr = '__sitecustomize__';
|
||||||
const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
|
const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
|
||||||
let command = `bash -c "source ${file_task_before} ${fileName}`;
|
let command = `bash -c "source ${file_task_before} ${fileName}`;
|
||||||
|
@ -43,7 +46,7 @@ function run() {
|
||||||
console.log('执行前置命令\n');
|
console.log('执行前置命令\n');
|
||||||
}
|
}
|
||||||
const res = execSync(
|
const res = execSync(
|
||||||
`${command} && echo -e '${splitStr}' && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`,
|
`${command} && echo -e '${splitStr}' && node -p 'JSON.stringify(process.env)'"`,
|
||||||
{
|
{
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
},
|
},
|
||||||
|
|
|
@ -36,6 +36,9 @@ def expand_range(range_str, max_value):
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
try:
|
try:
|
||||||
|
prev_pythonpath = os.getenv("PREV_PYTHONPATH", "")
|
||||||
|
os.environ["PYTHONPATH"] = prev_pythonpath
|
||||||
|
|
||||||
split_str = "__sitecustomize__"
|
split_str = "__sitecustomize__"
|
||||||
file_name = sys.argv[0].replace(f"{os.getenv('dir_scripts')}/", "")
|
file_name = sys.argv[0].replace(f"{os.getenv('dir_scripts')}/", "")
|
||||||
command = f'bash -c "source {os.getenv("file_task_before")} {file_name}'
|
command = f'bash -c "source {os.getenv("file_task_before")} {file_name}'
|
||||||
|
@ -46,7 +49,10 @@ def run():
|
||||||
command += f" && eval '{escape_task_before}'"
|
command += f" && eval '{escape_task_before}'"
|
||||||
print("执行前置命令\n")
|
print("执行前置命令\n")
|
||||||
|
|
||||||
python_command = "PYTHONPATH= python3 -c 'import os, json; print(json.dumps(dict(os.environ)))'"
|
prev_pythonpath = os.getenv("PREV_PYTHONPATH", "")
|
||||||
|
python_command = (
|
||||||
|
"python3 -c 'import os, json; print(json.dumps(dict(os.environ)))'"
|
||||||
|
)
|
||||||
command += f" && echo -e '{split_str}' && {python_command}\""
|
command += f" && echo -e '{split_str}' && {python_command}\""
|
||||||
|
|
||||||
res = subprocess.check_output(command, shell=True, encoding="utf-8")
|
res = subprocess.check_output(command, shell=True, encoding="utf-8")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user