Show More
@@ -9,6 +9,7 | |||||
9 | #----------------------------------------------------------------------------- |
|
9 | #----------------------------------------------------------------------------- | |
10 |
|
10 | |||
11 | import functools |
|
11 | import functools | |
|
12 | import os | |||
12 | import re |
|
13 | import re | |
13 | import shlex |
|
14 | import shlex | |
14 | import sys |
|
15 | import sys | |
@@ -41,6 +42,16 def _get_conda_like_executable(command): | |||||
41 | executable: string |
|
42 | executable: string | |
42 | Value should be: conda, mamba or micromamba |
|
43 | Value should be: conda, mamba or micromamba | |
43 | """ |
|
44 | """ | |
|
45 | # Check for a environment variable bound to the base executable, both conda and mamba | |||
|
46 | # set these when activating an environment. | |||
|
47 | base_executable = "CONDA_EXE" | |||
|
48 | if "mamba" in command.lower(): | |||
|
49 | base_executable = "MAMBA_EXE" | |||
|
50 | if base_executable in os.environ: | |||
|
51 | executable = Path(os.environ[base_executable]) | |||
|
52 | if executable.is_file(): | |||
|
53 | return str(executable.resolve()) | |||
|
54 | ||||
44 | # Check if there is a conda executable in the same directory as the Python executable. |
|
55 | # Check if there is a conda executable in the same directory as the Python executable. | |
45 | # This is the case within conda's root environment. |
|
56 | # This is the case within conda's root environment. | |
46 | executable = Path(sys.executable).parent / command |
|
57 | executable = Path(sys.executable).parent / command | |
@@ -48,10 +59,12 def _get_conda_like_executable(command): | |||||
48 | return str(executable) |
|
59 | return str(executable) | |
49 |
|
60 | |||
50 | # Otherwise, attempt to extract the executable from conda history. |
|
61 | # Otherwise, attempt to extract the executable from conda history. | |
51 | # This applies in any conda environment. |
|
62 | # This applies in any conda environment. Parsing this way is error prone because | |
|
63 | # different versions of conda and mamba include differing cmd values such as | |||
|
64 | # `conda`, `conda-script.py`, or `path/to/conda`, here use the raw command provided. | |||
52 | history = Path(sys.prefix, "conda-meta", "history").read_text(encoding="utf-8") |
|
65 | history = Path(sys.prefix, "conda-meta", "history").read_text(encoding="utf-8") | |
53 | match = re.search( |
|
66 | match = re.search( | |
54 |
rf"^#\s*cmd:\s*(?P<command>.*{ |
|
67 | rf"^#\s*cmd:\s*(?P<command>.*{command})\s[create|install]", | |
55 | history, |
|
68 | history, | |
56 | flags=re.MULTILINE, |
|
69 | flags=re.MULTILINE, | |
57 | ) |
|
70 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now