| 323 | |
| 324 | |
| 325 | def identify_conda_exe(conda_exe: str | Path | None = None) -> tuple[StandaloneExe, str]: |
| 326 | if conda_exe is None: |
| 327 | conda_exe = normalize_path(join(sys.prefix, "standalone_conda", "conda.exe")) |
| 328 | if isinstance(conda_exe, Path): |
| 329 | conda_exe = str(conda_exe) |
| 330 | try: |
| 331 | output_version = check_output([conda_exe, "--version"], text=True) |
| 332 | output_version = output_version.strip() |
| 333 | fields = output_version.split() |
| 334 | if "conda" in fields: |
| 335 | return StandaloneExe.CONDA, fields[1] |
| 336 | # micromamba only returns the version number |
| 337 | output_help = check_output([conda_exe, "--help"], text=True) |
| 338 | if "mamba" in output_help: |
| 339 | return StandaloneExe.MAMBA, output_version |
| 340 | except (CalledProcessError, OSError) as exc: |
| 341 | logger.debug("Exception while identifying binary", exc_info=exc) |
| 342 | logger.warning("Could not identify standalone binary: %s", exc) |
| 343 | return None, None |
| 344 | |
| 345 | |
| 346 | def format_conda_exe_name(conda_exe: str | Path) -> str: |