Skip to content

Commit

Permalink
core.magics.packaging: improve re usage
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMino committed Oct 11, 2020
1 parent bdbecf8 commit 3af8cfa
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions IPython/core/magics/packaging.py
Expand Up @@ -32,12 +32,14 @@ def _get_conda_executable():

# Otherwise, attempt to extract the executable from conda history.
# This applies in any conda environment.
R = re.compile(r"^#\s*cmd:\s*(?P<command>.*conda)\s[create|install]")
with open(Path(sys.prefix, "conda-meta", "history")) as f:
for line in f:
match = R.match(line)
if match:
return match.groupdict()['command']
history = Path(sys.prefix, "conda-meta", "history").read_text()
match = re.search(
r"^#\s*cmd:\s*(?P<command>.*conda)\s[create|install]",
history,
flags=re.MULTILINE,
)
if match:
return match.groupdict()["command"]

# Fallback: assume conda is available on the system path.
return "conda"
Expand Down

0 comments on commit 3af8cfa

Please sign in to comment.