Skip to content

Commit df8e158

Browse files
authored
feat: clippy warning as error, log to english (#265)
* feat: clippy warn as error * Refactor and translate Axvisor scripts for improved clarity and consistency
1 parent a01561e commit df8e158

File tree

12 files changed

+299
-298
lines changed

12 files changed

+299
-298
lines changed

axvisor.sh

Lines changed: 125 additions & 126 deletions
Large diffs are not rendered by default.

scripts/bootstrap.sh

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,51 @@
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
1010
RED='\033[0;31m'
1111
GREEN='\033[0;32m'
1212
YELLOW='\033[1;33m'
1313
BLUE='\033[0;34m'
1414
NC='\033[0m' # No Color
1515

16-
# 输出函数
16+
# Output helpers
1717
info() { echo -e "${BLUE}${NC} $1"; }
1818
success() { echo -e "${GREEN}${NC} $1"; }
1919
warning() { echo -e "${YELLOW}${NC} $1"; }
2020
error() { echo -e "${RED}${NC} $1"; }
2121

22-
# 获取项目根目录
22+
# Get project root directory
2323
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2424
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
2525
cd "$PROJECT_ROOT"
2626

27-
# 检查是否已经在虚拟环境中
27+
# If already inside a virtual environment, just update deps
2828
if [[ -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
4242
fi
4343

44-
# 虚拟环境和标记文件
44+
# Virtual environment and marker file
4545
VENV_DIR="venv"
4646
MARKER_FILE="$VENV_DIR/.bootstrapped"
4747
REQUIREMENTS_FILE="scripts/requirements.txt"
4848

49-
# 计算依赖哈希值
49+
# Compute dependency hash
5050
compute_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
6464
check_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
9494
if ! check_bootstrap_needed; then
95-
success "引导已完成且依赖未更改,跳过引导"
95+
success "Bootstrap already done and dependencies unchanged, skipping"
9696
exit 0
9797
fi
9898

99-
info "开始设置 Python 虚拟环境..."
99+
info "Starting Python virtual environment setup..."
100100

101-
# 检查系统依赖
101+
# Check system dependencies
102102
check_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
136136
setup_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
156156
install_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
172172
verify_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
185185
write_marker() {
186186
local dep_hash
187187
dep_hash=$(compute_dep_hash)
@@ -192,21 +192,21 @@ timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)
192192
python_version: $(python3 --version)
193193
EOF
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
199199
main() {
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
212212
main "$@"

scripts/build.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,52 @@
99

1010

1111
def main(args) -> int:
12-
"""构建项目"""
13-
print("执行 build 功能...")
12+
"""Build the project"""
13+
print("Running build task...")
1414

15-
# 获取配置文件路径
15+
# Get config file path
1616
config_file_path = getattr(args, "config", ".hvconfig.toml")
17-
18-
# 检查配置文件是否存在
17+
# Check if config file exists
1918
config_exists = os.path.exists(config_file_path)
2019

21-
# 首先设置 arceos 依赖
22-
print("设置 arceos 依赖...")
20+
# Setup arceos dependency first
21+
print("Setting up arceos dependency...")
2322
if not setup_arceos():
24-
print("设置 arceos 失败,无法继续构建")
23+
print("Failed to setup arceos, cannot build")
2524
return 1
2625

27-
# 创建配置对象
26+
# Create config object
2827
config: AxvisorConfig = create_config_from_args(args)
29-
30-
# 构建 make 命令
28+
# Build make command
3129
cmd = config.format_make_command("")
3230

33-
print(f"执行命令: {cmd}")
31+
print(f"Executing: {cmd}")
3432

3533
try:
36-
# 执行 make 命令
34+
# Run make command
3735
result = subprocess.run(
3836
cmd, shell=True, check=True, env=config.get_subprocess_env()
3937
)
40-
print("构建成功!")
38+
print("Build succeeded!")
4139

42-
# 如果配置文件不存在且有有意义的命令行参数,则创建配置文件
40+
# If config file missing and CLI args meaningful, create the config file
4341
if not config_exists:
44-
print(f"检测到 {config_file_path} 不存在,根据命令行参数创建配置文件...")
42+
print(
43+
f"Detected missing {config_file_path}, creating config file from arguments..."
44+
)
4545
if save_config_to_file(config, config_file_path):
4646
print(
47-
f"配置文件创建成功,下次可以直接运行 './task.py build -c {config_file_path}' 而无需指定参数"
47+
f"Config file created. Next time just run './task.py build -c {config_file_path}'"
4848
)
4949
else:
50-
print("配置文件创建失败,下次仍需手动指定参数")
50+
print(
51+
"Failed to create config file; you'll need to pass arguments again next run"
52+
)
5153

5254
return 0
5355
except subprocess.CalledProcessError as e:
54-
print(f"构建失败,退出码: {e.returncode}")
56+
print(f"Build failed, exit code: {e.returncode}")
5557
return e.returncode
5658
except Exception as e:
57-
print(f"构建过程中发生错误: {e}")
59+
print(f"Error during build: {e}")
5860
return 1

scripts/clean.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@
66

77

88
def main(args) -> int:
9-
"""清理构建产物"""
10-
print("执行 clean 功能...")
9+
"""Clean build artifacts"""
10+
print("Running clean task...")
1111

12-
# 首先设置 arceos 依赖
13-
print("设置 arceos 依赖...")
12+
# Setup arceos dependency first
13+
print("Setting up arceos dependency...")
1414
if not setup_arceos():
15-
print("设置 arceos 失败,无法继续执行 clean")
15+
print("Failed to setup arceos, cannot clean")
1616
return 1
1717

1818
cmd = format_make_command_base()
1919

2020
cmd.append("clean")
2121

22-
# 构建 make 命令
22+
# Build make command string
2323
cmd = " ".join(cmd)
2424

25-
print(f"执行命令: {cmd}")
25+
print(f"Executing: {cmd}")
2626

2727
try:
28-
# 执行 make 命令
28+
# Run make command
2929
subprocess.run(cmd, shell=True, check=True)
30-
print("清理完成!")
30+
print("Clean succeeded!")
3131
return 0
3232
except subprocess.CalledProcessError as e:
33-
print(f"清理失败,退出码: {e.returncode}")
33+
print(f"Clean failed, exit code: {e.returncode}")
3434
return e.returncode
3535
except Exception as e:
36-
print(f"清理过程中发生错误: {e}")
36+
print(f"Error during clean: {e}")
3737
return 1

0 commit comments

Comments
 (0)