Use Conda for backend & sync-microservice setup on Windows#1076
Use Conda for backend & sync-microservice setup on Windows#1076rahul-vyas-dev wants to merge 8 commits intoAOSSIE-Org:mainfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe Windows setup script ( Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant SetupPS as "scripts/setup.ps1"
participant Miniconda
participant Conda
participant BackendEnv as backend_env
participant SyncEnv as sync_env
User->>SetupPS: run setup.ps1
SetupPS->>Conda: check for conda in PATH / conda info
alt conda not found
SetupPS->>Miniconda: download and silently install Miniconda
Miniconda-->>SetupPS: install finished
SetupPS->>Conda: initialize conda for PowerShell (conda init / conda-hook)
end
SetupPS->>Conda: conda create -n backend_env python=3.12 --yes
Conda-->>BackendEnv: backend_env created
SetupPS->>Conda: conda run -n backend_env pip install -r backend/requirements.txt
SetupPS->>Conda: conda create -n sync_env python=3.12 --yes
Conda-->>SyncEnv: sync_env created
SetupPS->>Conda: conda run -n sync_env pip install -r sync-microservice/requirements.txt
SetupPS->>User: continue with frontend steps / finish
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@scripts/setup.ps1`:
- Around line 169-176: The conda commands may fail silently in a non-interactive
PowerShell script; after running "conda create -n backend_env python=3.12 -y"
and "conda activate backend_env" check $LASTEXITCODE and abort with a clear
error if non-zero, or avoid activation entirely by replacing the two "python -m
pip install..." calls with "conda run -n backend_env python -m pip install
--upgrade pip" and "conda run -n backend_env python -m pip install -r
requirements.txt"; ensure you perform this change around the existing conda
create/activate and pip install invocations so installs target the intended
"backend_env" environment.
- Around line 192-199: The current block runs "conda create -n sync_env
python=3.12 -y" and "conda activate sync_env" without checking errors; change it
to either use "conda run -n sync_env -- python -m pip install ..." for
idempotent, error-safe execution or add explicit error checks after "conda
create -n sync_env ..." and "conda activate sync_env" (capture and test the exit
code) and log/exit on failure; update the sequence around "conda create -n
sync_env python=3.12 -y", "conda activate sync_env", and the pip install
commands so failures are detected and handled consistently with the backend
setup.
🧹 Nitpick comments (3)
scripts/setup.ps1 (3)
121-136: Add error handling for Miniconda installation.The installation block lacks error handling. If the download or installation fails, subsequent Conda commands will fail with confusing errors. Consider wrapping this in a try-catch and verifying the installation succeeded.
Proposed improvement
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 + try { + $installer = "$env:TEMP\miniconda.exe" + Invoke-WebRequest ` + -Uri "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" ` + -OutFile $installer -ErrorAction Stop + + Start-Process -Wait -FilePath $installer -ArgumentList ` + "/InstallationType=JustMe", + "/AddToPath=0", + "/RegisterPython=0", + "/S", + "/D=$condaRoot" + + Remove-Item $installer -ErrorAction SilentlyContinue + + if (-not (Test-Path $condaExe)) { + Write-Host "Miniconda installation failed." -ForegroundColor Red + exit 1 + } + Write-Host "Miniconda installed successfully." -ForegroundColor Green + } catch { + Write-Host "Error installing Miniconda: $_" -ForegroundColor Red + exit 1 + } +} else { + Write-Host "Miniconda is already installed." -ForegroundColor Green }
143-144: Add error handling for Conda initialization.If
conda info --basefails orconda-hook.ps1doesn't exist, subsequentconda activatecommands will fail silently or produce confusing errors.Proposed improvement
-$condaBase = & $condaExe info --base -& "$condaBase\shell\condabin\conda-hook.ps1" +$condaBase = & $condaExe info --base 2>&1 +if (-not $condaBase -or -not (Test-Path $condaBase)) { + Write-Host "Failed to determine Conda base path." -ForegroundColor Red + exit 1 +} + +$condaHook = "$condaBase\shell\condabin\conda-hook.ps1" +if (Test-Path $condaHook) { + & $condaHook + Write-Host "Conda initialized successfully." -ForegroundColor Green +} else { + Write-Host "Conda hook script not found at: $condaHook" -ForegroundColor Red + exit 1 +}
84-102: Consider whether system Python 3.12 installation is still needed.With Conda environments now managing their own Python (
python=3.12), the Chocolatey Python 3.12 installation may be redundant. If it's only used for the backend and sync-microservice, you could remove this block to simplify the setup.However, if other parts of the setup or workflow rely on a system Python, keep it.
… handle errors and improve clarity
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@scripts/setup.ps1`:
- Around line 128-136: Start capturing the Miniconda installer process and check
its exit code after Start-Process by using the -PassThru option (e.g., assign
Start-Process -Wait -PassThru -FilePath $installer ... to a variable), then if
the returned object's ExitCode is non-zero, write an error/verbose message and
stop the script (exit 1) instead of continuing; only call Remove-Item $installer
after confirming a successful (zero) ExitCode so failures are detected early.
🧹 Nitpick comments (2)
scripts/setup.ps1 (2)
143-144: Consider adding validation for Conda initialization.If
conda info --basefails orconda-hook.ps1doesn't exist, the script continues without proper Conda shell integration, which could cause subtle failures later.Proposed validation
$condaBase = & $condaExe info --base +if ($LASTEXITCODE -ne 0 -or -not $condaBase) { + throw "Failed to determine Conda base path" +} + +$condaHook = "$condaBase\shell\condabin\conda-hook.ps1" +if (-not (Test-Path $condaHook)) { + throw "Conda hook script not found at: $condaHook" +} -& "$condaBase\shell\condabin\conda-hook.ps1" +& $condaHook
84-102: Consider whether standalone Python installation is still needed.With the switch to Conda environments (which include their own Python 3.12), the Chocolatey Python 3.12 installation may be redundant. If no other part of the setup requires a system-wide Python, this block could be removed to simplify the script and reduce installation time.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@scripts/setup.ps1`:
- Around line 128-130: The error check incorrectly references an undefined
variable $installerPath; update the conditional to use the defined $installer
variable instead so the Test-Path and exit-code check operate on the actual
downloaded file (i.e., replace usages of $installerPath with $installer in the
if condition that checks $LASTEXITCODE and Test-Path).
♻️ Duplicate comments (1)
scripts/setup.ps1 (1)
132-141:$LASTEXITCODEis not set byStart-Process; exit code check is ineffective.
Start-Processdoes not populate$LASTEXITCODE. The check on line 139 will always see the exit code from the previous native command (likelyInvoke-WebRequest), not the installer. Use-PassThruto capture the process object and inspect itsExitCodeproperty.Proposed fix
- Start-Process -Wait -FilePath $installer -ArgumentList ` + $process = Start-Process -Wait -PassThru -FilePath $installer -ArgumentList ` "/InstallationType=JustMe", "/AddToPath=0", "/RegisterPython=0", "/S", "/D=$condaRoot" - if ($LASTEXITCODE -ne 0) { - throw "Miniconda installer exited with an error" + if ($process.ExitCode -ne 0) { + throw "Miniconda installer exited with error code $($process.ExitCode)" }
🧹 Nitpick comments (1)
scripts/setup.ps1 (1)
161-162: Consider adding error handling for Conda initialization.If
conda info --basefails or returns an unexpected value, the subsequent hook script invocation will fail with a confusing error. Adding a check would improve debuggability.Suggested improvement
$condaBase = & $condaExe info --base +if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($condaBase)) { + throw "Failed to retrieve Conda base path" +} & "$condaBase\shell\condabin\conda-hook.ps1" +if ($LASTEXITCODE -ne 0) { + throw "Failed to initialize Conda shell hook" +}
rahulharpal1603
left a comment
There was a problem hiding this comment.
After making the changes suggested. Test this script on your friend's machine, which doesn't already have PictoPy set up.
scripts/setup.ps1
Outdated
| } | ||
|
|
||
| # Create fresh environment | ||
| conda create -n backend_env python=3.12 -y |
There was a problem hiding this comment.
Command should match the manual setup guide
The environment names and flags should be the same.
scripts/setup.ps1
Outdated
| } | ||
|
|
||
| # Upgrade pip inside the environment | ||
| conda run -n sync_env python -m pip install --upgrade pip |
There was a problem hiding this comment.
Activate conda and then directly use pip install. Again, these commands should match the manual setup guide.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@scripts/setup.ps1`:
- Around line 128-130: The conditional checking $LASTEXITCODE is incorrect
because Invoke-WebRequest throws on failure rather than setting $LASTEXITCODE;
update the download failure handling in the block that references
Invoke-WebRequest, $installer and the throw "Failed to download Miniconda
installer" to either (a) remove the `$LASTEXITCODE -ne 0` check and rely solely
on `Test-Path $installer` before throwing, or (b) wrap the Invoke-WebRequest
call in a try/catch that catches the exception and throws a new error including
the caught exception message so the throw includes real failure details.
- Around line 132-136: The current invocation uses a single string in
$installerArgs and calls & $installer $installerArgs which passes the entire
string as one argument; replace this with Start-Process to pass the argument
string correctly and capture the true exit code: call Start-Process -FilePath
$installer -ArgumentList $installerArgs -Wait -NoNewWindow -PassThru and then
check the returned process object's ExitCode (e.g., $proc = Start-Process ...
-PassThru; if ($proc.ExitCode -ne 0) { throw ... }) instead of relying on
$LASTEXITCODE; alternatively, build an argument array and invoke the installer
with the splat operator (& $installer `@args`) to pass discrete switches.
- Around line 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.
🧹 Nitpick comments (1)
scripts/setup.ps1 (1)
184-191:.envas a Conda environment directory may conflict with dotenv files.
.envis the conventional name for dotenv/environment-variable files in many projects. Using it as a Conda prefix directory could confuse contributors or collide with an existing.envfile. Consider a more distinctive name like.conda-envorbackend.conda.
| if ($LASTEXITCODE -ne 0 -or !(Test-Path $installer)) { | ||
| throw "Failed to download Miniconda installer" | ||
| } |
There was a problem hiding this comment.
$LASTEXITCODE is not set by Invoke-WebRequest; this check is misleading.
Invoke-WebRequest is a PowerShell cmdlet — it throws on failure rather than setting $LASTEXITCODE. The exit-code half of this condition is inert and could mask failures if a prior native command left $LASTEXITCODE non-zero. Rely on Test-Path alone, or wrap the download in its own try/catch.
Proposed fix
- if ($LASTEXITCODE -ne 0 -or !(Test-Path $installer)) {
+ if (!(Test-Path $installer)) {
throw "Failed to download Miniconda installer"
}🤖 Prompt for AI Agents
In `@scripts/setup.ps1` around lines 128 - 130, The conditional checking
$LASTEXITCODE is incorrect because Invoke-WebRequest throws on failure rather
than setting $LASTEXITCODE; update the download failure handling in the block
that references Invoke-WebRequest, $installer and the throw "Failed to download
Miniconda installer" to either (a) remove the `$LASTEXITCODE -ne 0` check and
rely solely on `Test-Path $installer` before throwing, or (b) wrap the
Invoke-WebRequest call in a try/catch that catches the exception and throws a
new error including the caught exception message so the throw includes real
failure details.
| $installerArgs = "/InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /S /D=$condaRoot" | ||
| & $installer $installerArgs | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Miniconda installer failed with exit code $LASTEXITCODE" | ||
| } |
There was a problem hiding this comment.
Installer arguments passed as a single string — silent install will likely fail.
$installerArgs is a single string, so & $installer $installerArgs passes it as one argument to the NSIS installer. The individual switches (/S, /D=…, etc.) won't be parsed. Use Start-Process with -ArgumentList (which accepts a single string and passes it correctly to the process command line) or invoke the executable with discrete arguments.
Proposed fix using Start-Process
- $installerArgs = "/InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /S /D=$condaRoot"
- & $installer $installerArgs
- if ($LASTEXITCODE -ne 0) {
- throw "Miniconda installer failed with exit code $LASTEXITCODE"
- }
+ $process = Start-Process -Wait -PassThru -FilePath $installer -ArgumentList `
+ "/InstallationType=JustMe", "/AddToPath=0", "/RegisterPython=0", "/S", "/D=$condaRoot"
+ if ($process.ExitCode -ne 0) {
+ throw "Miniconda installer failed with exit code $($process.ExitCode)"
+ }🤖 Prompt for AI Agents
In `@scripts/setup.ps1` around lines 132 - 136, The current invocation uses a
single string in $installerArgs and calls & $installer $installerArgs which
passes the entire string as one argument; replace this with Start-Process to
pass the argument string correctly and capture the true exit code: call
Start-Process -FilePath $installer -ArgumentList $installerArgs -Wait
-NoNewWindow -PassThru and then check the returned process object's ExitCode
(e.g., $proc = Start-Process ... -PassThru; if ($proc.ExitCode -ne 0) { throw
... }) instead of relying on $LASTEXITCODE; alternatively, build an argument
array and invoke the installer with the splat operator (& $installer `@args`) to
pass discrete switches.
| # Create fresh environment | ||
| conda create -p .sync-env python=3.12 | ||
| 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 | ||
| python -m pip install -r requirements.txt | ||
| deactivate | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Failed to upgrade pip in sync_env" | ||
| } | ||
|
|
||
| # Install dependencies inside the environment | ||
| conda install -r requirements.txt | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Failed to install sync-microservice dependencies" | ||
| } |
There was a problem hiding this comment.
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.
|
@rahulharpal1603 please review now and i will update you with any visual guide soon. If you are agreeing, then I can test it on my local setup from starting |
The changes are good enough. Is it possible to test it? Share me a screen recording of running this script and then starting both servers and frontend. |
ok, testing on VM on my machine |
|
https://1drv.ms/v/c/2b55451e453f4443/IQC1sL0COsfKR5az_ixt38i9Afnhz3u2en7XSINyLAp5Idg?e=iPlbq2 https://1drv.ms/v/c/2b55451e453f4443/IQA-ldMCX6XiTKJSnSQibFPhAXq0R-K5HoXhQROFBwgMr1c?e=a6qU6M These are the videos that you can watch to make sure that this script is working. |
|
sir @rahulharpal1603, now you can review and merge this |
fixes: #1072
This PR standardizes the Windows environment setup by using Conda instead of python venv for both the backend and sync-microservice.
The goal is to make the setup reliable, reproducible, and consistent across manual and script-based workflows.
Problem
The current manual setup documentation recommends Conda
The PowerShell setup scripts create and activate python venv
This mismatch leads to:
package resolution issues on Windows
broken pip / CLI tools inside venv
confusion for contributors following docs
inconsistent environments between services
In practice, this caused failures even after successful venv activation.
What this PR changes
Replaces python venv usage with Conda environments in PowerShell scripts
Uses the same Conda-based flow for:
backend
sync-microservice
Properly initializes Conda in PowerShell using:
conda info --base
conda-hook.ps1
Ensures the Conda environment is correctly activated before running any commands
Keeps the rest of the setup logic unchanged for minimal disruption
Why Conda
Better dependency resolution on Windows
Avoids broken pip / missing module issues
Matches the manual setup instructions
More predictable for contributors and CI
Impact
No runtime behavior changes
Only affects local development setup on Windows
Improves onboarding and reduces environment-related bugs
Testing
Ran the updated PowerShell scripts on Windows
Verified Conda environment activation
Confirmed backend and sync-microservice start correctly inside the Conda env
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.