diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index b4df2f7..9c6c5a1 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -226,3 +226,26 @@ function Test-DirHasFiles { return $false } } + +function Activate-RepoVenv { + $repoRoot = Get-RepoRoot + # If inside a .worktrees directory, use its root to detect a VIRTUAL_ENV + $venvBase = $repoRoot + if ($repoRoot -match ".worktrees") { + $venvBase = $repoRoot.Substring(0, $repoRoot.IndexOf(".worktrees")) + } + $venvPath = Join-Path $venvBase ".venv" + $activateScript = Join-Path $venvPath "Scripts/Activate.ps1" + if (-not $env:VIRTUAL_ENV) { + if (Test-Path $activateScript) { + Write-Output "Activating virtual environment at $venvPath" + $env:VIRTUAL_ENV = $venvPath + & $activateScript + } else { + Write-Warning ".venv not found at repo root: $venvPath" + } + } +} + +# auto-activate if not already in a venv +Activate-RepoVenv