mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-03-31 00:09:29 +02:00
102 lines
2.5 KiB
YAML
102 lines
2.5 KiB
YAML
name: "install-python-package"
|
||
command: "/bin/bash"
|
||
args:
|
||
- "-c"
|
||
- |
|
||
set -euo pipefail
|
||
|
||
PACKAGE="$1"
|
||
ENV_NAME="${2:-default}"
|
||
ADDITIONAL_ARGS="${3:-}"
|
||
|
||
BASE_DIR="${HOME}/.cyberstrike/venvs"
|
||
|
||
detect_project_root() {
|
||
if [ -n "${CYBERSTRIKE_ROOT:-}" ] && [ -d "${CYBERSTRIKE_ROOT}" ]; then
|
||
printf '%s\n' "${CYBERSTRIKE_ROOT}"
|
||
return
|
||
fi
|
||
if command -v git >/dev/null 2>&1; then
|
||
local root_path
|
||
if root_path=$(git rev-parse --show-toplevel 2>/dev/null); then
|
||
printf '%s\n' "$root_path"
|
||
return
|
||
fi
|
||
fi
|
||
printf '%s\n' "$(pwd)"
|
||
}
|
||
|
||
resolve_env_dir() {
|
||
local requested="$1"
|
||
if [ -n "${VIRTUAL_ENV:-}" ] && { [ -z "$requested" ] || [ "$requested" = "default" ]; }; then
|
||
printf '%s\n' "$VIRTUAL_ENV"
|
||
return
|
||
fi
|
||
if [ -z "$requested" ] || [ "$requested" = "default" ]; then
|
||
local root
|
||
root="$(detect_project_root)"
|
||
printf '%s/venv\n' "$root"
|
||
return
|
||
fi
|
||
printf '%s/%s\n' "$BASE_DIR" "$requested"
|
||
}
|
||
|
||
ENV_DIR="$(resolve_env_dir "$ENV_NAME")"
|
||
mkdir -p "$(dirname "$ENV_DIR")"
|
||
if [ ! -d "$ENV_DIR" ]; then
|
||
python3 -m venv "$ENV_DIR"
|
||
fi
|
||
|
||
# shellcheck disable=SC1090
|
||
source "$ENV_DIR/bin/activate"
|
||
|
||
if [ -n "$ADDITIONAL_ARGS" ]; then
|
||
pip install "$PACKAGE" $ADDITIONAL_ARGS
|
||
else
|
||
pip install "$PACKAGE"
|
||
fi
|
||
- "_"
|
||
enabled: true
|
||
short_description: "在指定虚拟环境中创建/激活并安装Python依赖"
|
||
description: |
|
||
在虚拟环境中安装Python包。
|
||
|
||
**主要功能:**
|
||
- 安装Python包
|
||
- 虚拟环境支持
|
||
- 依赖管理
|
||
|
||
**使用场景:**
|
||
- 环境配置
|
||
- 依赖安装
|
||
- 工具安装
|
||
parameters:
|
||
- name: "package"
|
||
type: "string"
|
||
description: "要安装的Python包名"
|
||
required: true
|
||
position: 0
|
||
format: "positional"
|
||
- name: "env_name"
|
||
type: "string"
|
||
description: "虚拟环境名称(默认default)"
|
||
required: false
|
||
default: "default"
|
||
position: 1
|
||
format: "positional"
|
||
- name: "additional_args"
|
||
type: "string"
|
||
description: |
|
||
额外的install-python-package参数。用于传递未在参数列表中定义的install-python-package选项。
|
||
|
||
**示例值:**
|
||
- 根据工具特性添加常用参数示例
|
||
|
||
**注意事项:**
|
||
- 多个参数用空格分隔
|
||
- 确保参数格式正确,避免命令注入
|
||
- 此参数会直接追加到命令末尾
|
||
required: false
|
||
format: "positional"
|
||
default: ""
|