Setup proactively installs conda if conda is not available. Returns the path to the conda binary and error if installation fails.
()
| 192 | // Setup proactively installs conda if conda is not available. |
| 193 | // Returns the path to the conda binary and error if installation fails. |
| 194 | func (c *CondaPython) Setup() error { |
| 195 | // Determine the expected conda binary path |
| 196 | condaInstallDir := filepath.Join(dirs.WorkspaceDir, "downloads", "tools", "conda-"+c.condaVersion) |
| 197 | condaBinDir := filepath.Join(condaInstallDir, expr.If(runtime.GOOS == "windows", "Scripts", "bin")) |
| 198 | condaBinary := filepath.Join(condaBinDir, expr.If(runtime.GOOS == "windows", "conda.exe", "conda")) |
| 199 | |
| 200 | // Check if conda is already installed at the expected location. |
| 201 | if fileio.PathExists(condaBinary) { |
| 202 | if err := exec.Command(condaBinary, "--version").Run(); err == nil { |
| 203 | c.condaBinary = condaBinary |
| 204 | return nil |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // Need to install conda - get the conda installer |
| 209 | condaInstallerPath, condaInstallDir, err := c.getCondaInstallerPaths() |
| 210 | if err != nil { |
| 211 | return fmt.Errorf("failed to locate conda installer: %w", err) |
| 212 | } |
| 213 | |
| 214 | // Execute the conda installation script. |
| 215 | if err := c.installConda(condaInstallerPath, condaInstallDir); err != nil { |
| 216 | return fmt.Errorf("failed to execute conda installation: %w", err) |
| 217 | } |
| 218 | |
| 219 | // Update PATH to include conda's bin directory. |
| 220 | condaBinDir = filepath.Join(condaInstallDir, expr.If(runtime.GOOS == "windows", "Scripts", "bin")) |
| 221 | if fileio.PathExists(condaBinDir) { |
| 222 | os.Setenv("PATH", env.JoinPaths("PATH", condaBinDir)) |
| 223 | } |
| 224 | |
| 225 | // Verify conda binary exists after installation. |
| 226 | if !fileio.PathExists(condaBinary) { |
| 227 | return fmt.Errorf("conda binary not found at %s after installation", condaBinary) |
| 228 | } |
| 229 | |
| 230 | // Configure conda to use conda-forge channel as default. |
| 231 | // This enables conda-forge packages by default. |
| 232 | tosCmd := exec.Command(condaBinary, "config", "--add", "channels", "conda-forge") |
| 233 | if err := tosCmd.Run(); err != nil { |
| 234 | return fmt.Errorf("Note: Could not configure conda-forge channel: %v", err) |
| 235 | } |
| 236 | |
| 237 | // Note: Python version installation is handled by getPythonExecutable via conda create |
| 238 | // This avoids conflicts in the base environment (e.g., conda-anaconda-tos package conflicts) |
| 239 | // Each Python version is created in a dedicated conda environment (e.g., py311) |
| 240 | c.condaBinary = condaBinary |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | // getCondaInstallerPaths determines the paths to the conda installer and installation directory. |
| 245 | // Returns installer path and installation directory |
nothing calls this directly
no test coverage detected