Show More
@@ -8,33 +8,32 b'' | |||||
8 | # The full license is in the file COPYING.txt, distributed with this software. |
|
8 | # The full license is in the file COPYING.txt, distributed with this software. | |
9 | #----------------------------------------------------------------------------- |
|
9 | #----------------------------------------------------------------------------- | |
10 |
|
10 | |||
11 | import os |
|
|||
12 | import re |
|
11 | import re | |
13 | import shlex |
|
12 | import shlex | |
14 | import sys |
|
13 | import sys | |
15 |
|
14 | |||
|
15 | from pathlib import Path | |||
16 | from IPython.core.magic import Magics, magics_class, line_magic |
|
16 | from IPython.core.magic import Magics, magics_class, line_magic | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | def _is_conda_environment(): |
|
19 | def _is_conda_environment(): | |
20 | """Return True if the current Python executable is in a conda env""" |
|
20 | """Return True if the current Python executable is in a conda env""" | |
21 | # TODO: does this need to change on windows? |
|
21 | # TODO: does this need to change on windows? | |
22 |
|
|
22 | return Path(sys.prefix, 'conda-meta', 'history').exists() | |
23 | return os.path.exists(conda_history) |
|
|||
24 |
|
23 | |||
25 |
|
24 | |||
26 | def _get_conda_executable(): |
|
25 | def _get_conda_executable(): | |
27 | """Find the path to the conda executable""" |
|
26 | """Find the path to the conda executable""" | |
28 | # Check if there is a conda executable in the same directory as the Python executable. |
|
27 | # Check if there is a conda executable in the same directory as the Python executable. | |
29 | # This is the case within conda's root environment. |
|
28 | # This is the case within conda's root environment. | |
30 |
conda = |
|
29 | conda = Path(sys.executable).parent / 'conda' | |
31 |
if |
|
30 | if conda.isfile(): | |
32 | return conda |
|
31 | return str(conda) | |
33 |
|
32 | |||
34 | # Otherwise, attempt to extract the executable from conda history. |
|
33 | # Otherwise, attempt to extract the executable from conda history. | |
35 | # This applies in any conda environment. |
|
34 | # This applies in any conda environment. | |
36 | R = re.compile(r"^#\s*cmd:\s*(?P<command>.*conda)\s[create|install]") |
|
35 | R = re.compile(r"^#\s*cmd:\s*(?P<command>.*conda)\s[create|install]") | |
37 |
with open( |
|
36 | with open(Path(sys.prefix, 'conda-meta', 'history')) as f: | |
38 | for line in f: |
|
37 | for line in f: | |
39 | match = R.match(line) |
|
38 | match = R.match(line) | |
40 | if match: |
|
39 | if match: |
General Comments 0
You need to be logged in to leave comments.
Login now