fix(cli): pass --clear to uv venv in rebuild_venv to avoid Windows brick - #39044
fix(cli): pass --clear to uv venv in rebuild_venv to avoid Windows brick#39044teknium1 wants to merge 1 commit into
Conversation
On Windows, `hermes update` can leave a half-deleted venv that bricks the install. `rebuild_venv` calls `shutil.rmtree(venv_dir, ignore_errors=True)` on the venv that hosts the currently running interpreter — `python.exe` is locked by Windows, so `Scripts/python.exe` survives while `pyvenv.cfg` is deleted. `uv venv` is then called without `--clear` and aborts with "A directory already exists", leaving the venv unusable (no `pyvenv.cfg`) and every subsequent `uv pip install -e .` failing with "No virtual environment found". The CLI itself dies with `ModuleNotFoundError: hermes_cli`. Add `--clear` to the `uv venv` invocation so uv replaces the leftover directory itself. `shutil.rmtree(ignore_errors=True)` is retained as a defense-in-depth fast path for POSIX systems where it succeeds outright. Fixes #37881
🔎 Lint report:
|
|
Closing as already fixed on The Windows venv brick (#37881) was fixed in c136eb4 ("fix(update): harden venv rebuild + verify core deps after install"), which uses the same Thanks for the clean fix and the precise root-cause writeup — you correctly diagnosed the locked- |
hermes updateno longer bricks the install on Windows when it rebuilds the venv.When the running interpreter lives inside the venv being rebuilt, Windows locks
python.exe, soshutil.rmtree(..., ignore_errors=True)silently leaves a half-deleted directory (pyvenv.cfg gone, Scripts/python.exe still present). The subsequentuv venvthen aborts withA directory already exists, leaving a broken venv →ModuleNotFoundError: hermes_cli.Changes
hermes_cli/managed_uv.py: pass--cleartouv venvinrebuild_venv()so uv replaces any leftover directory rmtree couldn't fully remove.tests/hermes_cli/test_managed_uv.py: 2 regression tests (--clearis passed; rebuild succeeds when rmtree leaves residue).Validation
uv venvover leftover residueerror: A directory already exists(brick)Verified live with a real
uvbinary: no---clearreturns exit 2 with the exact "A directory already exists" error;--clearreturns 0 and produces a working venv. 17/17test_managed_uv.pypass.Fixes #37881.
Salvaged from #37895 by @jackjin1997 (clean implementation against current
managed_uv.py); also supersedes @kyssta-exe's #37965 / #38051, which fixed the same bug from a stale fork base. Credit to both contributors.Infographic