(pythonVersion string, ignoreErrors bool)
| 280 | } |
| 281 | |
| 282 | func resolvePythonExecPath(pythonVersion string, ignoreErrors bool) (string, error) { |
| 283 | // Since the install location can be set by the user on Windows we use relative import |
| 284 | if runtime.GOOS == "windows" { |
| 285 | _here, err := executable.Folder() |
| 286 | if err != nil { |
| 287 | log.Warnf("Error getting executable folder: %v", err) |
| 288 | log.Warnf("Trying again allowing symlink resolution to fail") |
| 289 | _here, err = executable.FolderAllowSymlinkFailure() |
| 290 | if err != nil { |
| 291 | log.Warnf("Error getting executable folder w/o symlinks: %v", err) |
| 292 | } |
| 293 | } |
| 294 | log.Debugf("Executable folder is %v", _here) |
| 295 | |
| 296 | embeddedPythonHome2 := filepath.Join(_here, "..", "embedded2") |
| 297 | embeddedPythonHome3 := filepath.Join(_here, "..", "embedded3") |
| 298 | |
| 299 | // We want to use the path-relative embedded2/3 directories above by default. |
| 300 | // They will be correct for normal installation on Windows. However, if they |
| 301 | // are not present for cases like running unit tests, fall back to the compile |
| 302 | // time values. |
| 303 | if _, err := os.Stat(embeddedPythonHome2); os.IsNotExist(err) { |
| 304 | log.Warnf("Relative embedded directory not found for Python 2. Using default: %s", pythonHome2) |
| 305 | } else { |
| 306 | pythonHome2 = embeddedPythonHome2 |
| 307 | } |
| 308 | if _, err := os.Stat(embeddedPythonHome3); os.IsNotExist(err) { |
| 309 | log.Warnf("Relative embedded directory not found for Python 3. Using default: %s", pythonHome3) |
| 310 | } else { |
| 311 | pythonHome3 = embeddedPythonHome3 |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | if pythonVersion == "2" { |
| 316 | PythonHome = pythonHome2 |
| 317 | } else if pythonVersion == "3" { |
| 318 | PythonHome = pythonHome3 |
| 319 | } |
| 320 | |
| 321 | log.Infof("Using '%s' as Python home", PythonHome) |
| 322 | |
| 323 | // For Windows, the binary should be in our path already and have a |
| 324 | // consistent name |
| 325 | if runtime.GOOS == "windows" { |
| 326 | // If we are in a development environment, PythonHome will not be set so we |
| 327 | // use the absolute path to the python.exe in our path. |
| 328 | if PythonHome == "" { |
| 329 | log.Warnf("Python home is empty. Inferring interpreter path from binary in path.") |
| 330 | return pathToBinary(PythonWinExeBasename, ignoreErrors) |
| 331 | } |
| 332 | |
| 333 | return filepath.Join(PythonHome, PythonWinExeBasename), nil |
| 334 | } |
| 335 | |
| 336 | // On *nix both Python versions are installed in the same embedded directory. We |
| 337 | // don't want to use the default version (aka "python") but rather "python2" or |
| 338 | // "python3" based on the configuration. Also on some Python3 platforms there |
| 339 | // are no "python" aliases either. |
no test coverage detected
searching dependent graphs…