NagaAgent icon indicating copy to clipboard operation
NagaAgent copied to clipboard

Something wrong with setup.ps1?

Open Gazerrr03 opened this issue 1 year ago • 5 comments

Issue description

I 'git clone’ this project to my local fold and I run the 'setup.ps1' according to the document However, it returns:

PS (my folder)\NagaAgent> & (my folder)\NagaAgent\setup.ps1'
所在位置 (my folder)\NagaAgent\setup.ps1:41 字符: 8
+ } else {
+        ~
语句块或类型定义中缺少右“}”。
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingEndCurlyBrace

How I try to solve

I send the feedback message to ChatGPT And the modified parts are as follows: 1.Clarified the virtual‑env comment

Original: # 创建并激活虚拟环境 Updated: # 创建虚拟环境(如果不存在) — just made the comment more precise; no logic change.

2.Moved elseif onto its own line

-} elseif (Test-Path "requirements.txt") {
+}
+elseif (Test-Path "requirements.txt") {

This ensures the closing } of the if block is clearly paired before the elseif, avoiding any parser confusion.

3.Added blank lines around each logical block — Improves visual separation, making it easy to spot unmatched { or } when you scroll.

4.Guaranteed every if, elseif, and else has its own matching braces Each branch now looks like:

if ( … ) {
    …
}
elseif ( … ) {
    …
}
else {
    …
}

5.Added a note about UTF‑8 (no BOM) encoding — Hidden BOM bytes can be misinterpreted as stray { or } in PowerShell, so saving without BOM prevents that.

That's it! I am a beginner programmer and may not be very good at explaining problems, but I hope I can be of help to you. Anyway, your project is very interesting! Keep up the good work!

Gazerrr03 avatar Jul 18 '25 15:07 Gazerrr03

thanks!

RTGS2017 avatar Jul 18 '25 15:07 RTGS2017

👍🏻👍🏻👍🏻

Gazerrr03 avatar Jul 18 '25 15:07 Gazerrr03

Or you can use this without using the "elif".

setup.txt

一键配置脚本 for NagaAgent 3.0 (极致码高尔夫)

版本号由config.py统一管理

$ErrorActionPreference = "Stop" # 设置错误时停止执行 $pythonMinVersion = "3.8" # Python最低版本要求 $venvPath = ".venv" # 虚拟环境路径

检查Python版本

$pythonVersion = (python --version 2>&1) -replace "Python " if ([version]$pythonVersion -lt [version]$pythonMinVersion) { Write-Error "需要Python $pythonMinVersion或更高版本,当前版本: $pythonVersion" exit 1 }

设置工作目录

$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path Set-Location $scriptPath

创建并激活虚拟环境

if (-not (Test-Path $venvPath)) { Write-Host "创建虚拟环境..." python -m venv $venvPath }

激活虚拟环境

. "$venvPath/Scripts/Activate.ps1"

安装依赖(用清华源加速)

Write-Host "安装依赖(使用清华镜像源加速)..."

检查并安装依赖

if (Test-Path "pyproject.toml") { Write-Host "使用 uv 安装依赖..." -ForegroundColor Green $uvCommand = Get-Command "uv" -ErrorAction SilentlyContinue if ($uvCommand) { uv sync } else { Write-Host "未找到 uv,使用 pip 安装..." -ForegroundColor Yellow pip install -e . } } else { if (Test-Path "requirements.txt") { Write-Host "使用 requirements.txt 安装依赖..." -ForegroundColor Green pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple } else { Write-Host "未找到依赖文件,请检查项目配置" -ForegroundColor Red exit 1 } }

兼容旧的 requirements 文件扫描(如果存在)

Get-ChildItem -Filter "requirements*.txt" -ErrorAction SilentlyContinue | ForEach-Object { pip install -r $_.FullName -i https://pypi.tuna.tsinghua.edu.cn/simple }

安装playwright浏览器驱动

Write-Host "安装playwright浏览器驱动..." python -m playwright install chromium

验证playwright安装

Write-Host "验证playwright安装..." $playwrightVersion = python -m playwright --version if ($LASTEXITCODE -ne 0) { Write-Error "Playwright安装验证失败" exit 1 } Write-Host "Playwright版本: $playwrightVersion"

Write-Host "环境设置完成!" Write-Host "如需安装其他浏览器驱动,请运行:" Write-Host "python -m playwright install firefox # 安装Firefox" Write-Host "python -m playwright install webkit # 安装WebKit"

Ludwig1827 avatar Jul 19 '25 05:07 Ludwig1827

已使用gemini修改,测试后能正常使用配置 以下是修改完毕的内容,全部复制粘贴到ps1文件保存运行即可

版本号由config.py统一管理

$ErrorActionPreference = "Stop" # 设置错误时停止执行 $pythonMinVersion = "3.8" # Python最低版本要求 $venvPath = ".venv" # 虚拟环境路径

检查Python版本

$pythonVersion = (python --version 2>&1) -replace "Python " if ([version]$pythonVersion -lt [version]$pythonMinVersion) { Write-Error "需要Python $pythonMinVersion或更高版本,当前版本: $pythonVersion" exit 1 }

设置工作目录

$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path Set-Location $scriptPath

创建并激活虚拟环境

if (-not (Test-Path $venvPath)) { Write-Host "创建虚拟环境..." python -m venv $venvPath }

激活虚拟环境

. "$venvPath/Scripts/Activate.ps1"

安装依赖(用清华源加速)

Write-Host "安装依赖(使用清华镜像源加速)..."

优先使用 pyproject.toml

if (Test-Path "pyproject.toml") { Write-Host "使用 uv 安装依赖..." -ForegroundColor Green if (Get-Command "uv" -ErrorAction SilentlyContinue) { uv sync } else { Write-Host "未找到 uv,使用 pip 安装..." -ForegroundColor Yellow pip install -e . } } elseif (Test-Path "requirements.txt") { Write-Host "使用 requirements.txt 安装依赖..." -ForegroundColor Green pip install -r requirements.txt } else { Write-Host "未找到依赖文件,请检查项目配置" -ForegroundColor Red exit 1 }

兼容旧的 requirements 文件扫描(如果存在)

Get-ChildItem -Filter "requirements*.txt" -ErrorAction SilentlyContinue | ForEach-Object { pip install -r $_.FullName -i https://pypi.tuna.tsinghua.edu.cn/simple }

安装playwright浏览器驱动

Write-Host "安装playwright浏览器驱动..." python -m playwright install chromium

验证playwright安装

Write-Host "验证playwright安装..." $playwrightVersion = python -m playwright --version if ($LASTEXITCODE -ne 0) { Write-Error "Playwright安装验证失败" exit 1 } Write-Host "Playwright版本: $playwrightVersion"

Write-Host "环境设置完成!" Write-Host "如需安装其他浏览器驱动,请运行:" Write-Host "python -m playwright install firefox # 安装Firefox" Write-Host "python -m playwright install webkit # 安装WebKit"

exynos967 avatar Jul 19 '25 06:07 exynos967

Open the file in vscode and save it as UTF-8 with BOM works fine with me

Cylopsis avatar Jul 20 '25 05:07 Cylopsis