Skip to content

Commit eaf2c69

Browse files
authored
Merge pull request #55 from Azure-Samples/copilot/fix-powershell-script-venv
Fix start.ps1 to use correct virtual environment paths
2 parents 7b82d61 + 2d087a3 commit eaf2c69

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

app/start.ps1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
Write-Host 'Creating python virtual environment "backend/backend_env"'
1+
Set-Location ../
2+
3+
# Function to get the venv python path based on OS and relative path
4+
function Get-VenvPythonPath {
5+
param([string]$relativePath)
6+
if ($IsLinux -or $IsMacOS) {
7+
return "$relativePath/bin/python"
8+
} else {
9+
return "$relativePath/Scripts/python.exe"
10+
}
11+
}
12+
13+
Write-Host 'Creating python virtual environment ".venv"'
214
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
315
if (-not $pythonCmd) {
416
# fallback to python3 if python not found
517
$pythonCmd = Get-Command python3 -ErrorAction SilentlyContinue
618
}
7-
Start-Process -FilePath ($pythonCmd).Source -ArgumentList "-m venv ./backend/backend_env" -Wait -NoNewWindow
19+
Start-Process -FilePath ($pythonCmd).Source -ArgumentList "-m venv .venv" -Wait -NoNewWindow
820

921
Write-Host ""
1022
Write-Host "Restoring backend python packages"
1123
Write-Host ""
1224

13-
$venvPythonPath = "./venv/scripts/python.exe"
14-
if (Test-Path -Path "/usr") {
15-
# fallback to Linux venv path
16-
$venvPythonPath = "./venv/bin/python"
17-
}
25+
$venvPythonPath = Get-VenvPythonPath "./.venv"
1826

1927
Start-Process -FilePath $venvPythonPath -ArgumentList "-m pip install -r app/backend/requirements.txt" -Wait -NoNewWindow
2028
if ($LASTEXITCODE -ne 0) {
@@ -25,7 +33,7 @@ if ($LASTEXITCODE -ne 0) {
2533
Write-Host ""
2634
Write-Host "Restoring frontend npm packages"
2735
Write-Host ""
28-
Set-Location ../frontend
36+
Set-Location app/frontend
2937
npm install
3038
if ($LASTEXITCODE -ne 0) {
3139
Write-Host "Failed to restore frontend npm packages"
@@ -46,6 +54,9 @@ Write-Host "Starting backend"
4654
Write-Host ""
4755
Set-Location ../backend
4856

57+
# Update venv path for backend directory
58+
$venvPythonPath = Get-VenvPythonPath "../../.venv"
59+
4960
$port = 50505
5061
$hostname = "localhost"
5162
Start-Process -FilePath $venvPythonPath -ArgumentList "-m quart --app main:app run --port $port --host $hostname --reload" -Wait -NoNewWindow

0 commit comments

Comments
 (0)