22# -*- coding: utf-8 -*-
33
44# Axvisor Bootstrap Script
5- # 此脚本用于创建 Python 虚拟环境并安装 task.py 所需的依赖
5+ # This script creates a Python virtual environment and installs task.py dependencies
66
7- set -e # 遇到错误时退出
7+ set -e # Exit on error
88
9- # 颜色输出
9+ # Colored output
1010RED=' \033[0;31m'
1111GREEN=' \033[0;32m'
1212YELLOW=' \033[1;33m'
1313BLUE=' \033[0;34m'
1414NC=' \033[0m' # No Color
1515
16- # 输出函数
16+ # Output helpers
1717info () { echo -e " ${BLUE} ℹ${NC} $1 " ; }
1818success () { echo -e " ${GREEN} ✓${NC} $1 " ; }
1919warning () { echo -e " ${YELLOW} ⚠${NC} $1 " ; }
2020error () { echo -e " ${RED} ✗${NC} $1 " ; }
2121
22- # 获取项目根目录
22+ # Get project root directory
2323SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
2424PROJECT_ROOT=" $( cd " $SCRIPT_DIR /.." && pwd) "
2525cd " $PROJECT_ROOT "
2626
27- # 检查是否已经在虚拟环境中
27+ # If already inside a virtual environment, just update deps
2828if [[ -n " $VIRTUAL_ENV " ]]; then
29- info " 检测到已在虚拟环境中 : $VIRTUAL_ENV "
29+ info " Detected active virtual environment : $VIRTUAL_ENV "
3030
31- # 检查 requirements.txt 文件是否存在
31+ # Ensure requirements.txt exists
3232 if [[ ! -f " scripts/requirements.txt" ]]; then
33- error " scripts/requirements.txt 文件未找到 "
33+ error " scripts/requirements.txt not found "
3434 exit 1
3535 fi
3636
37- # 安装/更新依赖
38- info " 更新 Python 依赖 ..."
37+ # Install / update dependencies
38+ info " Updating Python dependencies ..."
3939 pip install -q -r scripts/requirements.txt -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
40- success " 依赖更新完成 "
40+ success " Dependencies updated "
4141 exit 0
4242fi
4343
44- # 虚拟环境和标记文件
44+ # Virtual environment and marker file
4545VENV_DIR=" venv"
4646MARKER_FILE=" $VENV_DIR /.bootstrapped"
4747REQUIREMENTS_FILE=" scripts/requirements.txt"
4848
49- # 计算依赖哈希值
49+ # Compute dependency hash
5050compute_dep_hash () {
5151 local pyver
5252 pyver=$( python3 --version 2> /dev/null || echo " unknown" )
@@ -60,128 +60,128 @@ compute_dep_hash() {
6060 fi
6161}
6262
63- # 检查是否需要重新引导
63+ # Decide if bootstrap is needed
6464check_bootstrap_needed () {
65- # 如果虚拟环境不存在,需要引导
65+ # Need bootstrap if venv directory missing
6666 if [[ ! -d " $VENV_DIR " ]]; then
67- return 0 # 需要引导
67+ return 0 # need bootstrap
6868 fi
6969
70- # 如果标记文件不存在,需要引导
70+ # Need bootstrap if marker file missing
7171 if [[ ! -f " $MARKER_FILE " ]]; then
72- return 0 # 需要引导
72+ return 0 # need bootstrap
7373 fi
7474
75- # 检查哈希值是否匹配
75+ # Check dependency hash
7676 local existing_hash current_hash
7777 existing_hash=$( awk -F" :" ' /^hash:/ {print $2}' " $MARKER_FILE " 2> /dev/null | tr -d ' [:space:]' ) || existing_hash=" "
7878 current_hash=$( compute_dep_hash)
7979
8080 if [[ " $existing_hash " != " $current_hash " ]]; then
81- info " 检测到依赖变更,需要重新引导 "
82- return 0 # 需要引导
81+ info " Dependency changes detected, re-bootstrap required "
82+ return 0 # need bootstrap
8383 fi
8484
85- # 检查虚拟环境的Python是否可用
85+ # Ensure python executable exists in venv
8686 if [[ ! -x " $VENV_DIR /bin/python3" ]]; then
87- warning " 虚拟环境的 Python 不可用,需要重新引导 "
88- return 0 # 需要引导
87+ warning " Python in virtual env not available, re-bootstrap required "
88+ return 0 # need bootstrap
8989 fi
9090
91- return 1 # 不需要引导
91+ return 1 # bootstrap not needed
9292}
93- # 快速检查并退出
93+ # Fast path: already bootstrapped
9494if ! check_bootstrap_needed; then
95- success " 引导已完成且依赖未更改,跳过引导 "
95+ success " Bootstrap already done and dependencies unchanged, skipping "
9696 exit 0
9797fi
9898
99- info " 开始设置 Python 虚拟环境 ..."
99+ info " Starting Python virtual environment setup ..."
100100
101- # 检查系统依赖
101+ # Check system dependencies
102102check_system_deps () {
103- info " 检查系统依赖 ..."
103+ info " Checking system dependencies ..."
104104
105- # 检查 Python 3
105+ # Check python3 exists
106106 if ! command -v python3 > /dev/null 2>&1 ; then
107- error " python3 未找到,请先安装 Python 3"
107+ error " python3 not found. Please install Python 3"
108108 exit 1
109109 fi
110110
111- # 检查 Python 版本
111+ # Report Python version
112112 local pyver
113113 pyver=$( python3 --version 2>&1 | awk ' {print $2}' | cut -d. -f1,2)
114- info " 检测到 Python 版本 : $pyver "
114+ info " Detected Python version : $pyver "
115115
116- # 检查 venv 模块
116+ # Check venv module
117117 if ! python3 -c " import venv" 2> /dev/null; then
118- error " python3-venv 模块未找到 "
119- echo " 请安装 python3-venv:"
120- echo " Ubuntu/Debian: sudo apt install python3-venv"
121- echo " CentOS/RHEL: sudo yum install python3-venv"
122- echo " Fedora: sudo dnf install python3-venv"
118+ error " python3-venv module not found "
119+ echo " Install python3-venv via your package manager :"
120+ echo " Ubuntu/Debian: sudo apt install python3-venv"
121+ echo " CentOS/RHEL: sudo yum install python3-venv"
122+ echo " Fedora: sudo dnf install python3-venv"
123123 exit 1
124124 fi
125125
126- # 检查 requirements.txt
126+ # Check requirements.txt exists
127127 if [[ ! -f " $REQUIREMENTS_FILE " ]]; then
128- error " $REQUIREMENTS_FILE 文件未找到 "
128+ error " $REQUIREMENTS_FILE not found "
129129 exit 1
130130 fi
131131
132- success " 系统依赖检查完成 "
132+ success " System dependency check passed "
133133}
134134
135- # 创建虚拟环境
135+ # Create virtual environment
136136setup_venv () {
137- info " 设置虚拟环境 ..."
137+ info " Preparing virtual environment ..."
138138
139- # 如果虚拟环境已存在但损坏,删除它
139+ # Remove broken venv
140140 if [[ -d " $VENV_DIR " ]] && [[ ! -x " $VENV_DIR /bin/python3" ]]; then
141- warning " 检测到损坏的虚拟环境,正在删除 ..."
141+ warning " Corrupted virtual environment detected, removing ..."
142142 rm -rf " $VENV_DIR "
143143 fi
144144
145- # 创建虚拟环境
145+ # Create venv if missing
146146 if [[ ! -d " $VENV_DIR " ]]; then
147- info " 创建新的虚拟环境 ..."
147+ info " Creating new virtual environment ..."
148148 python3 -m venv " $VENV_DIR "
149- success " 虚拟环境已创建 "
149+ success " Virtual environment created "
150150 else
151- info " 使用现有虚拟环境 "
151+ info " Using existing virtual environment "
152152 fi
153153}
154154
155- # 安装依赖
155+ # Install dependencies
156156install_deps () {
157- info " 安装 Python 依赖 ..."
157+ info " Installing Python dependencies ..."
158158
159159 # 激活虚拟环境
160160 source " $VENV_DIR /bin/activate"
161161
162- # 升级 pip(静默)
162+ # Upgrade pip (quiet)
163163 python -m pip install -q --upgrade pip -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
164164
165- # 安装依赖
165+ # Install requirements
166166 pip install -q -r " $REQUIREMENTS_FILE " -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
167167
168- success " 依赖安装完成 "
168+ success " Dependencies installed "
169169}
170170
171- # 验证安装
171+ # Verify installation
172172verify_installation () {
173- info " 验证安装 ..."
173+ info " Verifying installation ..."
174174
175175 # 测试 task.py
176176 if source " $VENV_DIR /bin/activate" && python3 ./scripts/task.py --help > /dev/null 2>&1 ; then
177- success " task.py 运行正常 "
177+ success " task.py runs correctly "
178178 else
179- error " task.py 运行失败 "
179+ error " task.py execution failed "
180180 exit 1
181181 fi
182182}
183183
184- # 写入完成标记
184+ # Write completion marker
185185write_marker () {
186186 local dep_hash
187187 dep_hash=$( compute_dep_hash)
@@ -192,21 +192,21 @@ timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)
192192python_version: $( python3 --version)
193193EOF
194194
195- success " 引导完成标记已写入 (hash: ${dep_hash: 0: 8} ...)"
195+ success " Bootstrap marker written (hash: ${dep_hash: 0: 8} ...)"
196196}
197197
198- # 主要执行流程
198+ # Main execution flow
199199main () {
200200 check_system_deps
201201 setup_venv
202202 install_deps
203203 verify_installation
204204 write_marker
205205
206- success " 虚拟环境设置完成! "
207- info " 使用 ' source venv/bin/activate' 激活环境 "
208- info " 使用 'make help' 查看可用命令 "
206+ success " Virtual environment setup complete! "
207+ info " Activate with: source venv/bin/activate"
208+ info " Use 'make help' to see available commands "
209209}
210210
211- # 执行主函数
211+ # Execute main function
212212main " $@ "
0 commit comments