Skip to content

Commit 2d087a3

Browse files
Copilotpamelafox
andcommitted
Improve OS detection and reduce code duplication in start.ps1
Co-authored-by: pamelafox <297042+pamelafox@users.noreply.github.com>
1 parent 9f7ebbb commit 2d087a3

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

app/start.ps1

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
Set-Location ../
22

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+
313
Write-Host 'Creating python virtual environment ".venv"'
414
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
515
if (-not $pythonCmd) {
@@ -12,11 +22,7 @@ Write-Host ""
1222
Write-Host "Restoring backend python packages"
1323
Write-Host ""
1424

15-
$venvPythonPath = "./.venv/Scripts/python.exe"
16-
if (Test-Path -Path "/usr") {
17-
# fallback to Linux venv path
18-
$venvPythonPath = "./.venv/bin/python"
19-
}
25+
$venvPythonPath = Get-VenvPythonPath "./.venv"
2026

2127
Start-Process -FilePath $venvPythonPath -ArgumentList "-m pip install -r app/backend/requirements.txt" -Wait -NoNewWindow
2228
if ($LASTEXITCODE -ne 0) {
@@ -49,11 +55,7 @@ Write-Host ""
4955
Set-Location ../backend
5056

5157
# Update venv path for backend directory
52-
$venvPythonPath = "../../.venv/Scripts/python.exe"
53-
if (Test-Path -Path "/usr") {
54-
# fallback to Linux venv path
55-
$venvPythonPath = "../../.venv/bin/python"
56-
}
58+
$venvPythonPath = Get-VenvPythonPath "../../.venv"
5759

5860
$port = 50505
5961
$hostname = "localhost"

0 commit comments

Comments
 (0)