Skip to content

Fix setup.bat PY_MINOR detection and run-all.bat START command quoting#11

Open
chainchopper with Copilot wants to merge 2 commits into
mainfrom
copilot/update-file-modifications
Open

Fix setup.bat PY_MINOR detection and run-all.bat START command quoting#11
chainchopper with Copilot wants to merge 2 commits into
mainfrom
copilot/update-file-modifications

Conversation

Copilot AI commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Two Windows batch script bugs caused setup.bat to crash during the optional llama-cpp-python install and run-all.bat to fail launching services with 'Frontend:' is not recognized.

setup.bat — PY_MINOR detection

The for /f "tokens=2" form with platform.python_version_tuple()[1] had two defects: the ) in the expression terminated the for /f clause early (batch parser truncation), and tokens=2 always yielded empty since the output is a single token. Replaced with usebackq backtick form using sys.version_info[1]:

- for /f "tokens=2" %%i in ('"%PYTHON%" -c "import platform; print(platform.python_version_tuple()[1])"') do set PY_MINOR=%%i
+ for /f "usebackq delims=" %%i in (`"%PYTHON%" -c "import sys; print(sys.version_info[1])"`) do set "PY_MINOR=%%i"

run-all.bat — START command quoting

cmd /k ^ line continuation with unescaped inner path quotes caused CMD to treat path components like Frontend: as commands. Collapsed to a single line with ""path"" doubled-quote escaping:

- start "NPU-STACK Backend" cmd /k ^
- "call "!ROOT!\.venv\Scripts\activate.bat" & cd /d "!ROOT!\backend" & python main.py"
+ start "NPU-STACK Backend" cmd /k "call ""!ROOT!\.venv\Scripts\activate.bat"" & cd /d ""!ROOT!\backend"" & python main.py"

Same fix applied to setup.bat's generator section so freshly-created run-all.bat files are also correct.

Original prompt

User is asking for confirmation whether file modifications are being made directly in chainchopper/NPU-STACK and expects direct repository edits for reported setup/run script issues. Please proceed by creating/continuing a PR with concrete file changes in the repository so the user can git pull fixes.

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: chainchopper <36168576+chainchopper@users.noreply.github.com>
Copilot AI changed the title [WIP] Update setup and run scripts in chainchopper/NPU-STACK Fix setup.bat PY_MINOR detection and run-all.bat START command quoting Mar 3, 2026
@chainchopper chainchopper marked this pull request as ready for review March 3, 2026 10:59
Copilot AI review requested due to automatic review settings March 3, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Windows batch-script quoting/parsing issues that were breaking optional llama-cpp-python install in setup.bat and service launching in run-all.bat.

Changes:

  • Update setup.bat to detect Python minor version via sys.version_info[1] using for /f usebackq to avoid batch parser truncation.
  • Fix START cmd /k quoting in run-all.bat so paths with spaces don’t get mis-parsed as commands.
  • Apply the same START quoting fix to the run-all.bat generator section inside setup.bat.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
setup.bat Fixes PY_MINOR detection and corrects quoting when generating run-all.bat entries.
run-all.bat Fixes start ... cmd /k command-line quoting so backend/frontend windows launch reliably.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread setup.bat
@@ -184,7 +184,7 @@ if %errorlevel% neq 0 (
echo Installing llama-cpp-python (optional - GGUF inference)...
"%PIP%" uninstall llama-cpp-python -y >nul 2>&1
set "LLAMA_CPP_OK=1"

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PY_MINOR is derived via a for /f command substitution, but it's never cleared or validated. If the Python invocation fails (e.g., transient venv/python issue), PY_MINOR could retain a pre-existing environment value and select the wrong wheel branch. Consider set "PY_MINOR=" before the loop and adding a guard that falls back to the generic pip install llama-cpp-python --only-binary :all: path when PY_MINOR is not set.

Suggested change
set "LLAMA_CPP_OK=1"
set "LLAMA_CPP_OK=1"
set "PY_MINOR="

Copilot uses AI. Check for mistakes.
Copilot AI added a commit that referenced this pull request Mar 3, 2026
…ation

- run-all.bat: Replace broken nested-quote START commands with clean
  delegation to run-backend.bat / run-frontend.bat helper scripts
- setup.bat: Fix generated run-all.bat lines to use ^!ROOT^!\run-backend.bat
  and ^!ROOT^!\run-frontend.bat with proper caret-escaped vars
- backend/Dockerfile: Add cmake, migrate llama.cpp build from make to CMake,
  update COPY paths to build/bin/ to match CMake output layout

Supersedes conflicting PRs #8, #9, #10, #11, #12

Co-authored-by: chainchopper <36168576+chainchopper@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants