1+ # MHKiT-MATLAB Step 1: Conda Detection
2+ # Generated from template - DO NOT EDIT DIRECTLY
3+ # Report issues: https://github.com/MHKiT-Software/MHKiT-MATLAB/issues/new
4+
5+ $ErrorActionPreference = " Stop" # Exit on any error
6+
7+ # Script configuration
8+ $CONDA_ENV_NAME = " mhkit-matlab-env"
9+ $PYTHON_VERSION = " 3.11"
10+ $MHKIT_VERSION = " 0.9"
11+ $GITHUB_ISSUES = " https://github.com/MHKiT-Software/MHKiT-MATLAB/issues/new"
12+
13+ # Logging functions
14+ function Write-Info {
15+ param ([string ]$Message )
16+ Write-Host " [INFO] $Message " - ForegroundColor Green
17+ }
18+
19+ function Write-Success {
20+ param ([string ]$Message )
21+ Write-Host " [SUCCESS] $Message " - ForegroundColor Cyan
22+ }
23+
24+ function Write-Warning {
25+ param ([string ]$Message )
26+ Write-Host " [WARNING] $Message " - ForegroundColor Yellow
27+ }
28+
29+ function Write-Error {
30+ param ([string ]$Message )
31+ Write-Host " [ERROR] $Message " - ForegroundColor Red
32+ Write-Host " [ERROR] Please report this issue: $GITHUB_ISSUES " - ForegroundColor Red
33+ }
34+
35+ # Function to test if a conda installation works
36+ function Test-Conda {
37+ param ([string ]$CondaPath )
38+
39+ Write-Info " Testing conda at: $CondaPath "
40+
41+ # Test if the conda executable exists
42+ if (Test-Path $CondaPath ) {
43+ try {
44+ # Test if conda info works (this is the most reliable test)
45+ $null = & " $CondaPath " info 2> $null
46+ $condaVersion = & " $CondaPath " -- version 2> $null
47+ $condaLocation = & " $CondaPath " info -- base 2> $null
48+ Write-Success " Working conda found!"
49+ Write-Info " Version: $condaVersion "
50+ Write-Info " Location: $condaLocation "
51+ return $true
52+ } catch {
53+ Write-Warning " Conda executable found but 'conda info' failed"
54+ return $false
55+ }
56+ } else {
57+ return $false
58+ }
59+ }
60+
61+ # OS and Architecture Detection
62+ $OSType = " Windows"
63+ $ArchType = $env: PROCESSOR_ARCHITECTURE
64+ # Function to check if conda is available
65+ function Find-Conda {
66+ Write-Info " Starting comprehensive conda detection..."
67+
68+ # Step 1: Check if conda is already in PATH and working
69+ try {
70+ $condaCmd = Get-Command conda - ErrorAction SilentlyContinue
71+ if ($condaCmd ) {
72+ Write-Info " Found conda in PATH"
73+ if (Test-Conda $condaCmd.Source ) {
74+ Write-Output " CONDA_DETECTED=true"
75+ Write-Output " CONDA_PATH=$ ( $condaCmd.Source ) "
76+ return
77+ } else {
78+ Write-Warning " Conda in PATH is not working properly"
79+ }
80+ }
81+ } catch {
82+ # Continue to other detection methods
83+ }
84+
85+ # Step 2: Check environment variables
86+ $envValue = [Environment ]::GetEnvironmentVariable(" CONDA_EXE" )
87+ if ($envValue ) {
88+ Write-Info " Checking environment variable CONDA_EXE: $envValue "
89+ $condaFromEnv = " "
90+ if (" CONDA_EXE" -eq " CONDA_EXE" ) {
91+ $condaFromEnv = $envValue
92+ } elseif (" CONDA_EXE" -eq " CONDA_PREFIX" ) {
93+ $condaFromEnv = Join-Path $envValue " Scripts\conda.exe"
94+ }
95+
96+ if ($condaFromEnv -and (Test-Conda $condaFromEnv )) {
97+ Write-Output " CONDA_DETECTED=true"
98+ Write-Output " CONDA_PATH=$condaFromEnv "
99+ return
100+ }
101+ }
102+ $envValue = [Environment ]::GetEnvironmentVariable(" CONDA_PREFIX" )
103+ if ($envValue ) {
104+ Write-Info " Checking environment variable CONDA_PREFIX: $envValue "
105+ $condaFromEnv = " "
106+ if (" CONDA_PREFIX" -eq " CONDA_EXE" ) {
107+ $condaFromEnv = $envValue
108+ } elseif (" CONDA_PREFIX" -eq " CONDA_PREFIX" ) {
109+ $condaFromEnv = Join-Path $envValue " Scripts\conda.exe"
110+ }
111+
112+ if ($condaFromEnv -and (Test-Conda $condaFromEnv )) {
113+ Write-Output " CONDA_DETECTED=true"
114+ Write-Output " CONDA_PATH=$condaFromEnv "
115+ return
116+ }
117+ }
118+
119+ # Step 3: Check all common installation paths systematically
120+ Write-Info " Checking common conda installation paths..."
121+ $pathsToCheck = @ (
122+ [Environment ]::ExpandEnvironmentVariables(" %USERPROFILE%\miniconda3\Scripts\conda.exe" ),
123+ [Environment ]::ExpandEnvironmentVariables(" %USERPROFILE%\miniconda3\condabin\conda.bat" ),
124+ [Environment ]::ExpandEnvironmentVariables(" %USERPROFILE%\Miniconda3\Scripts\conda.exe" ),
125+ [Environment ]::ExpandEnvironmentVariables(" %USERPROFILE%\Anaconda3\Scripts\conda.exe" ),
126+ [Environment ]::ExpandEnvironmentVariables(" %USERPROFILE%\anaconda3\Scripts\conda.exe" ),
127+ [Environment ]::ExpandEnvironmentVariables(" C:\ProgramData\Miniconda3\Scripts\conda.exe" ),
128+ [Environment ]::ExpandEnvironmentVariables(" C:\ProgramData\Anaconda3\Scripts\conda.exe" ),
129+ [Environment ]::ExpandEnvironmentVariables(" C:\tools\miniconda3\Scripts\conda.exe" ),
130+ [Environment ]::ExpandEnvironmentVariables(" C:\tools\Miniconda3\Scripts\conda.exe" ),
131+ [Environment ]::ExpandEnvironmentVariables(" %LOCALAPPDATA%\Continuum\miniconda3\Scripts\conda.exe" ),
132+ [Environment ]::ExpandEnvironmentVariables(" %LOCALAPPDATA%\Continuum\anaconda3\Scripts\conda.exe" )
133+ )
134+
135+ foreach ($path in $pathsToCheck ) {
136+ if (Test-Conda $path ) {
137+ Write-Output " CONDA_DETECTED=true"
138+ Write-Output " CONDA_PATH=$path "
139+ return
140+ }
141+ }
142+
143+ Write-Info " No working conda installation found"
144+ Write-Output " CONDA_DETECTED=false"
145+ }
146+
147+ # Main execution
148+ function Main {
149+ Write-Info " Step 1: Detecting conda installation..."
150+ Find-Conda
151+ }
152+
153+ # Run main function
154+ Main
0 commit comments