Skip to content
111 changes: 89 additions & 22 deletions scripts/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,38 @@ if (-not (Test-Command cmake)) {
Write-Host "CMake is already installed. Version: $(cmake --version)" -ForegroundColor Green
}

# --------------------------------------------------
# Miniconda
# --------------------------------------------------
$condaRoot = "$env:USERPROFILE\miniconda3"
$condaExe = "$condaRoot\Scripts\conda.exe"

if (-not (Test-Path $condaExe)) {
Write-Host "Installing Miniconda..." -ForegroundColor Yellow
$installer = "$env:TEMP\miniconda.exe"
Invoke-WebRequest `
-Uri "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" `
-OutFile $installer

Start-Process -Wait -FilePath $installer -ArgumentList `
"/InstallationType=JustMe",
"/AddToPath=0",
"/RegisterPython=0",
"/S",
"/D=$condaRoot"

Remove-Item $installer
}

# --------------------------------------------------
# Initialize Conda (THIS WAS MISSING BEFORE)
# --------------------------------------------------
$env:Path = "$condaRoot;$condaRoot\Scripts;$condaRoot\condabin;$env:Path"

$condaBase = & $condaExe info --base
& "$condaBase\shell\condabin\conda-hook.ps1"


# ---- Set up the frontend ----
Write-Host "Setting up frontend..." -ForegroundColor Yellow
try {
Expand All @@ -131,19 +163,37 @@ try {
# ---- Set up the backend using Python 3.12 ----
Write-Host "Setting up backend..." -ForegroundColor Yellow
try {
Set-Location .\backend\

# Create virtual environment
python -m venv .env

# Activate virtual environment and install dependencies
.\.env\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
deactivate


Set-Location .\backend\

Write-Host "Setting up backend Conda environment..." -ForegroundColor Cyan

# Remove existing environment (ignore if it does not exist)
conda remove -n backend_env --all -y
if ($LASTEXITCODE -ne 0) {
Write-Host "Environment did not exist or could not be removed, continuing..." -ForegroundColor Yellow
}

# Create fresh environment
conda create -n backend_env python=3.12 -y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command should match the manual setup guide

The environment names and flags should be the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

if ($LASTEXITCODE -ne 0) {
throw "Failed to create Conda environment"
}

# Upgrade pip inside the environment
conda run -n backend_env python -m pip install --upgrade pip
if ($LASTEXITCODE -ne 0) {
throw "Failed to upgrade pip inside Conda environment"
}

# Install backend dependencies
conda run -n backend_env python -m pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
throw "Failed to install backend dependencies"
}

Set-Location ..

Write-Host "Backend setup completed successfully." -ForegroundColor Green
} catch {
Write-Host "Error setting up backend: $_" -ForegroundColor Red
Expand All @@ -155,17 +205,34 @@ Write-Host "Setting up sync-microservice..." -ForegroundColor Yellow
try {
Set-Location .\sync-microservice\

# Create virtual environment
python -m venv .sync-env

# Activate virtual environment and install dependencies
.\.sync-env\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
deactivate

Write-Host "Setting up sync-microservice Conda environment..." -ForegroundColor Cyan

# Remove existing environment (ignore if it does not exist)
conda remove -n sync_env --all -y
if ($LASTEXITCODE -ne 0) {
Write-Host "Environment did not exist or could not be removed, continuing..." -ForegroundColor Yellow
}

# Create fresh environment
conda create -n sync_env python=3.12 -y
if ($LASTEXITCODE -ne 0) {
throw "Failed to create Conda environment for sync-microservice"
}

# Upgrade pip inside the environment
conda run -n sync_env python -m pip install --upgrade pip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Activate conda and then directly use pip install. Again, these commands should match the manual setup guide.

if ($LASTEXITCODE -ne 0) {
throw "Failed to upgrade pip in sync_env"
}

# Install dependencies inside the environment
conda run -n sync_env python -m pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
throw "Failed to install sync-microservice dependencies"
}
Comment on lines 233 to 251
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

conda install -r requirements.txt is invalid — -r is pip syntax, not conda.

Line 248 uses conda install -r requirements.txt, but conda install does not support the -r flag for reading a requirements file. This will fail at runtime. It should be pip install -r requirements.txt, consistent with the backend block (line 205).

Also, the same -y and conda activate issues flagged in the backend block apply here (lines 234, 239).

Proposed fix (sync-microservice block)
-    conda create -p .sync-env python=3.12 
+    conda create -p .sync-env python=3.12 -y
     if ($LASTEXITCODE -ne 0) {
         throw "Failed to create Conda environment for sync-microservice"
     }
 
-    conda activate .\.sync-env
-
-    # Upgrade pip inside the environment
-    python -m pip install --upgrade pip
+    conda run -p .sync-env python -m pip install --upgrade pip
     if ($LASTEXITCODE -ne 0) {
         throw "Failed to upgrade pip in sync_env"
     }
 
-    # Install dependencies inside the environment
-    conda install -r requirements.txt
+    conda run -p .sync-env pip install -r requirements.txt
     if ($LASTEXITCODE -ne 0) {
         throw "Failed to install sync-microservice dependencies"
     }
-    # Deactivate environment after setup
-    conda deactivate
     Set-Location ..
🤖 Prompt for AI Agents
In `@scripts/setup.ps1` around lines 233 - 251, The script uses invalid conda
flags and unsafe activation: replace the failing "conda install -r
requirements.txt" with "pip install -r requirements.txt" (run inside the created
env after activating), add the non-interactive flag when creating the env (use
conda create with -y for "conda create -p .sync-env python=3.12 -y" or
equivalent), and avoid a plain "conda activate .\.sync-env" that may fail in
non-interactive shells—use the recommended env activation approach for scripts
(e.g., source/conda run or the conda hook) so subsequent commands like "python
-m pip install --upgrade pip" and "pip install -r requirements.txt" run
reliably; update the commands around conda create, conda activate, and the pip
install steps to follow this sequence.


Set-Location ..

Write-Host "Sync-microservice setup completed successfully." -ForegroundColor Green
} catch {
Write-Host "Error setting up sync-microservice: $_" -ForegroundColor Red
Expand Down