feat: support python virtualenv (#116)
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ functions.json
|
|||||||
/tools/code_interpreter.*
|
/tools/code_interpreter.*
|
||||||
/.env
|
/.env
|
||||||
__pycache__
|
__pycache__
|
||||||
/venv
|
/.venv
|
||||||
node_modules
|
node_modules
|
||||||
/package.json
|
/package.json
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
|
|||||||
+39
-1
@@ -3,6 +3,7 @@ set -e
|
|||||||
|
|
||||||
BIN_DIR=bin
|
BIN_DIR=bin
|
||||||
TMP_DIR="cache/tmp"
|
TMP_DIR="cache/tmp"
|
||||||
|
VENV_DIR=".venv"
|
||||||
|
|
||||||
LANG_CMDS=( \
|
LANG_CMDS=( \
|
||||||
"sh:bash" \
|
"sh:bash" \
|
||||||
@@ -116,8 +117,14 @@ build-bin@tool() {
|
|||||||
_build_win_shim tool $lang > "$bin_file"
|
_build_win_shim tool $lang > "$bin_file"
|
||||||
else
|
else
|
||||||
bin_file="$BIN_DIR/$basename"
|
bin_file="$BIN_DIR/$basename"
|
||||||
|
if [[ "$lang" == "py" && -d "$VENV_DIR" ]]; then
|
||||||
|
rm -rf "$bin_file"
|
||||||
|
_build_py_shim tool $lang > "$bin_file"
|
||||||
|
chmod +x "$bin_file"
|
||||||
|
else
|
||||||
ln -s -f "$PWD/scripts/run-tool.$lang" "$bin_file"
|
ln -s -f "$PWD/scripts/run-tool.$lang" "$bin_file"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
echo "Build bin/$basename"
|
echo "Build bin/$basename"
|
||||||
else
|
else
|
||||||
not_found_tools+=("$name")
|
not_found_tools+=("$name")
|
||||||
@@ -229,8 +236,14 @@ build-bin@agent() {
|
|||||||
_build_win_shim agent $lang > "$bin_file"
|
_build_win_shim agent $lang > "$bin_file"
|
||||||
else
|
else
|
||||||
bin_file="$BIN_DIR/$name"
|
bin_file="$BIN_DIR/$name"
|
||||||
|
if [[ "$lang" == "py" && -d "$VENV_DIR" ]]; then
|
||||||
|
rm -rf "$bin_file"
|
||||||
|
_build_py_shim tool $lang > "$bin_file"
|
||||||
|
chmod +x "$bin_file"
|
||||||
|
else
|
||||||
ln -s -f "$PWD/scripts/run-agent.$lang" "$bin_file"
|
ln -s -f "$PWD/scripts/run-agent.$lang" "$bin_file"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
echo "Build bin/$name"
|
echo "Build bin/$name"
|
||||||
tool_names_file="$agent_dir/tools.txt"
|
tool_names_file="$agent_dir/tools.txt"
|
||||||
if [[ -f "$tool_names_file" ]]; then
|
if [[ -f "$tool_names_file" ]]; then
|
||||||
@@ -539,9 +552,13 @@ _build_win_shim() {
|
|||||||
cmd="$(_lang_to_cmd "$lang")"
|
cmd="$(_lang_to_cmd "$lang")"
|
||||||
if [[ "$lang" == "sh" ]]; then
|
if [[ "$lang" == "sh" ]]; then
|
||||||
run="\"$(argc --argc-shell-path)\" --noprofile --norc"
|
run="\"$(argc --argc-shell-path)\" --noprofile --norc"
|
||||||
|
else
|
||||||
|
if [[ "$cmd" == "python" && -d "$VENV_DIR" ]]; then
|
||||||
|
run="call \"$(_normalize_path "$PWD/$VENV_DIR/Scripts/activate.bat")\" && python"
|
||||||
else
|
else
|
||||||
run="\"$(_normalize_path "$(which $cmd)")\""
|
run="\"$(_normalize_path "$(which $cmd)")\""
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
@echo off
|
@echo off
|
||||||
setlocal
|
setlocal
|
||||||
@@ -554,12 +571,27 @@ $run "%script_dir%scripts\run-$kind.$lang" "%script_name%" %*
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_build_py_shim() {
|
||||||
|
kind="$1"
|
||||||
|
lang="$2"
|
||||||
|
cat <<-'EOF' | sed -e "s|__ROOT_DIR__|$PWD|g" -e "s|__VENV_DIR__|$VENV_DIR|g" -e "s/__KIND__/$kind/g"
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [[ -d "__ROOT_DIR__/__VENV_DIR__/bin/activate" ]]; then
|
||||||
|
source "__ROOT_DIR__/__VENV_DIR__/bin/activate"
|
||||||
|
fi
|
||||||
|
|
||||||
|
python "__ROOT_DIR__/scripts/run-__KIND__.py" "$(basename "$0")" "$@"
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
_link_tool() {
|
_link_tool() {
|
||||||
from="$1"
|
from="$1"
|
||||||
to="$2.${1##*.}"
|
to="$2.${1##*.}"
|
||||||
rm -rf tools/$to
|
rm -rf tools/$to
|
||||||
if _is_win; then
|
if _is_win; then
|
||||||
(cd tools && cmd <<< "mklink $to $from" > /dev/null)
|
(cd tools && cp -f $from $to)
|
||||||
else
|
else
|
||||||
(cd tools && ln -s $from $to)
|
(cd tools && ln -s $from $to)
|
||||||
fi
|
fi
|
||||||
@@ -601,6 +633,12 @@ _is_win() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_argc_before() {
|
||||||
|
if [[ -d ".venv/bin/activate" ]]; then
|
||||||
|
source .venv/bin/activate
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
_choice_tool() {
|
_choice_tool() {
|
||||||
for item in "${LANG_CMDS[@]}"; do
|
for item in "${LANG_CMDS[@]}"; do
|
||||||
lang="${item%:*}"
|
lang="${item%:*}"
|
||||||
|
|||||||
Reference in New Issue
Block a user