fix(setup): reuse existing uv-created venv instead of failing on rerun#433
Open
Turkzilla wants to merge 1 commit intoBeehiveInnovations:mainfrom
Open
fix(setup): reuse existing uv-created venv instead of failing on rerun#433Turkzilla wants to merge 1 commit intoBeehiveInnovations:mainfrom
Turkzilla wants to merge 1 commit intoBeehiveInnovations:mainfrom
Conversation
`uv venv` refuses to write into an existing directory unless `--clear`
is passed. The current setup_environment() preserves uv-created venvs
(by skipping the removal block when the `uv_created` marker exists),
then unconditionally calls `uv venv ...` against that same directory.
That call fails on every run after the first with:
error: Failed to create virtual environment
Caused by: A virtual environment already exists at `.pal_venv`.
Use `--clear` to replace it
The script then logs "uv environment creation failed" and falls back
to system Python detection, defeating the uv-first design and
reinstalling all dependencies through pip on every run.
Add a fast-path that detects an existing healthy uv-created venv and
reuses it (echoing the venv's python, matching the function contract).
If the marker is present but the Python is missing or non-executable,
the venv is removed and recreated cleanly.
No behavior change for first-time setup or for non-uv venvs.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates run-server.sh to allow the reuse of existing uv-created virtual environments, which prevents unnecessary recreations and ensures the uv-first design is maintained. A review comment identifies a potential issue where the Python executable path should be double-quoted to safely handle paths containing spaces.
Comment on lines
+596
to
+597
| print_success "Reusing existing uv environment ($($existing_python --version 2>&1))" | ||
| if ! $existing_python -m pip --version &>/dev/null 2>&1; then |
Contributor
There was a problem hiding this comment.
The variable $existing_python should be double-quoted when used as a command to prevent word splitting and globbing. This is particularly important if the path to the virtual environment contains spaces, which is common on some operating systems (e.g., macOS or Windows).
Suggested change
| print_success "Reusing existing uv environment ($($existing_python --version 2>&1))" | |
| if ! $existing_python -m pip --version &>/dev/null 2>&1; then | |
| print_success "Reusing existing uv environment ($("$existing_python" --version 2>&1))" | |
| if ! "$existing_python" -m pip --version &>/dev/null 2>&1; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
uv venvrefuses to write into an existing directory unless--clearis passed. The currentsetup_environment()inrun-server.shpreserves uv-created venvs (by skipping the removal block when theuv_createdmarker exists), then unconditionally callsuv venv ...against that same directory.That call fails on every run after the first with:
The script then logs
uv environment creation failedand falls back to system Python detection, defeating the uv-first design and reinstalling all dependencies through pip on every run.Fix
Add a fast-path that detects an existing healthy uv-created venv and reuses it (echoing the venv's python, matching the function contract).
If the
uv_createdmarker is present but the Python interpreter is missing or non-executable, the venv is removed and recreated cleanly.No behavior change for first-time setup or for non-uv venvs.
Test plan
uv venvcalluv venv --python 3.12.pal_venv/bin/pythonmissing → venv recreated cleanlybash -n run-server.shsyntax check passesRepro of the bug (before this fix)