##// END OF EJS Templates
core.magics.packaging: improve re usage
Blazej Michalik -
Show More
@@ -32,12 +32,14 b' def _get_conda_executable():'
32
32
33 # Otherwise, attempt to extract the executable from conda history.
33 # Otherwise, attempt to extract the executable from conda history.
34 # This applies in any conda environment.
34 # This applies in any conda environment.
35 R = re.compile(r"^#\s*cmd:\s*(?P<command>.*conda)\s[create|install]")
35 history = Path(sys.prefix, "conda-meta", "history").read_text()
36 with open(Path(sys.prefix, "conda-meta", "history")) as f:
36 match = re.search(
37 for line in f:
37 r"^#\s*cmd:\s*(?P<command>.*conda)\s[create|install]",
38 match = R.match(line)
38 history,
39 if match:
39 flags=re.MULTILINE,
40 return match.groupdict()['command']
40 )
41 if match:
42 return match.groupdict()["command"]
41
43
42 # Fallback: assume conda is available on the system path.
44 # Fallback: assume conda is available on the system path.
43 return "conda"
45 return "conda"
General Comments 0
You need to be logged in to leave comments. Login now