重构启动方式,更新为使用uv自动管理python虚拟环境
This commit is contained in:
parent
925098944c
commit
39e86ee6df
4
apps/jingrow/frontend/package-lock.json
generated
4
apps/jingrow/frontend/package-lock.json
generated
@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "jingrowlocal-frontend",
|
||||
"name": "jingrow-frontend",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "jingrowlocal-frontend",
|
||||
"name": "jingrow-frontend",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@iconify/vue": "^5.0.0",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "jingrowlocal-frontend",
|
||||
"name": "jingrow-frontend",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
[project]
|
||||
name = "jingrow"
|
||||
version = "1.0.0"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
"fastapi==0.104.1",
|
||||
"uvicorn[standard]==0.24.0",
|
||||
@ -9,6 +10,9 @@ dependencies = [
|
||||
"pydantic-settings>=2.0.0",
|
||||
"qdrant-client==1.15.1",
|
||||
"requests==2.31.0",
|
||||
"pytz>=2023.3",
|
||||
"APScheduler>=3.10.4",
|
||||
"redis>=5.0.0",
|
||||
"dramatiq",
|
||||
"dramatiq[watch]",
|
||||
]
|
||||
|
||||
1467
apps/jingrow/uv.lock
generated
Normal file
1467
apps/jingrow/uv.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
60
dev.sh
60
dev.sh
@ -24,6 +24,30 @@ check_cmd() {
|
||||
fi
|
||||
}
|
||||
|
||||
# 安装 uv(官方安装脚本)
|
||||
install_uv() {
|
||||
info "尝试自动安装 uv..."
|
||||
# 使用仓库内脚本进行安装
|
||||
if [ -f ./install_uv.sh ]; then
|
||||
bash ./install_uv.sh || {
|
||||
warn "install_uv.sh 执行失败"
|
||||
return 1
|
||||
}
|
||||
else
|
||||
warn "install_uv.sh 不存在"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 尝试把本次会话的 PATH 补上
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
|
||||
if command -v uv &> /dev/null; then
|
||||
success "uv 安装完成"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# 清理进程
|
||||
cleanup() {
|
||||
info "清理现有进程..."
|
||||
@ -71,7 +95,13 @@ check_deps() {
|
||||
info "检查依赖..."
|
||||
|
||||
check_cmd node || exit 1
|
||||
check_cmd python3 || exit 1
|
||||
if ! command -v uv &> /dev/null; then
|
||||
warn "uv 未安装"
|
||||
install_uv || {
|
||||
error "自动安装 uv 失败,请手动安装: curl -fsSL https://astral.sh/uv/install.sh | sh"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
# 检查前端依赖
|
||||
if [ ! -d "apps/jingrow/frontend/node_modules" ]; then
|
||||
@ -80,11 +110,21 @@ check_deps() {
|
||||
cd apps/jingrow/frontend && npm install && cd ../..
|
||||
fi
|
||||
|
||||
# 检查后端依赖
|
||||
if ! python3 -c "import uvicorn" &> /dev/null; then
|
||||
warn "后端依赖未安装"
|
||||
info "安装后端依赖..."
|
||||
cd apps/jingrow && pip install -r requirements.txt && cd ../..
|
||||
# 检查后端依赖(优先使用 uv)
|
||||
info "同步后端依赖 (uv)..."
|
||||
if [ -f "apps/jingrow/pyproject.toml" ]; then
|
||||
(cd apps/jingrow && uv sync) || {
|
||||
error "uv 同步失败"
|
||||
exit 1
|
||||
}
|
||||
elif [ -f "apps/jingrow/requirements.txt" ]; then
|
||||
warn "未发现 pyproject.toml,使用 requirements.txt 安装"
|
||||
(cd apps/jingrow && uv pip install -r requirements.txt) || {
|
||||
error "uv pip 安装失败"
|
||||
exit 1
|
||||
}
|
||||
else
|
||||
warn "未发现依赖清单(pyproject.toml 或 requirements.txt)"
|
||||
fi
|
||||
|
||||
success "依赖检查完成"
|
||||
@ -127,8 +167,8 @@ start_all() {
|
||||
npx concurrently \
|
||||
--names "BACKEND,WORKER,FRONTEND" \
|
||||
--prefix-colors "blue,yellow,green" \
|
||||
"cd apps/jingrow && python3 -m jingrow.app" \
|
||||
"cd apps/jingrow && python3 -m jingrow.dramatiq" \
|
||||
"cd apps/jingrow && uv run python -m jingrow.app" \
|
||||
"cd apps/jingrow && uv run python -m jingrow.dramatiq" \
|
||||
"sleep 3 && cd apps/jingrow/frontend && npm run dev"
|
||||
}
|
||||
|
||||
@ -157,8 +197,8 @@ start_backend() {
|
||||
npx concurrently \
|
||||
--names "BACKEND,WORKER" \
|
||||
--prefix-colors "blue,yellow" \
|
||||
"cd apps/jingrow && python3 -m jingrow.app" \
|
||||
"cd apps/jingrow && python3 -m jingrow.dramatiq"
|
||||
"cd apps/jingrow && uv run python -m jingrow.app" \
|
||||
"cd apps/jingrow && uv run python -m jingrow.dramatiq"
|
||||
}
|
||||
|
||||
# 停止服务
|
||||
|
||||
2080
install_uv.sh
Normal file
2080
install_uv.sh
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,15 +10,15 @@
|
||||
"redis": "redis-server ./redis.conf || echo 'Redis already running or not installed'",
|
||||
"worker": "cd apps/jingrow && dramatiq jingrow.services.queue --processes 1 --threads 1",
|
||||
"frontend": "cd apps/jingrow/frontend && npm run dev",
|
||||
"backend": "cd apps/jingrow && uvicorn jingrow.main:app --host 0.0.0.0 --port 9001 --reload",
|
||||
"backend": "cd apps/jingrow && uv run uvicorn jingrow.main:app --host 0.0.0.0 --port 9001 --reload",
|
||||
"install": "npm run install:frontend && npm run install:backend",
|
||||
"install:frontend": "cd apps/jingrow/frontend && npm install",
|
||||
"install:backend": "cd apps/jingrow && pip install -r requirements.txt",
|
||||
"install:backend": "bash -lc 'cd apps/jingrow && if [ -f pyproject.toml ]; then uv sync; elif [ -f requirements.txt ]; then uv pip install -r requirements.txt; else echo \"No dependency manifest found\"; fi'",
|
||||
"build": "npm run build:frontend",
|
||||
"build:frontend": "cd apps/jingrow/frontend && npm run build",
|
||||
"start": "npm run start:frontend && npm run start:backend",
|
||||
"start:frontend": "cd apps/jingrow/frontend && npm run preview",
|
||||
"start:backend": "cd apps/jingrow && uvicorn jingrow.main:app --host 0.0.0.0 --port 9001",
|
||||
"start:backend": "cd apps/jingrow && uv run uvicorn jingrow.main:app --host 0.0.0.0 --port 9001",
|
||||
"clean": "npm run clean:frontend && npm run clean:backend",
|
||||
"clean:frontend": "cd apps/jingrow/frontend && rm -rf node_modules dist",
|
||||
"clean:backend": "cd apps/jingrow && find . -name '__pycache__' -type d -exec rm -rf {} +",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user