Skip to content
Snippets Groups Projects
Commit 58e740b5 authored by Nicolas Dandrimont's avatar Nicolas Dandrimont
Browse files

opam: retrieve opam from $PATH with shutil.which

The default behavior of subprocess is to pull executables from a
hardcoded list, which doesn't work when opam is installed manually in
the user's home directory.
parent 95fbf8a2
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
import io
import os
import shutil
from subprocess import PIPE, Popen, call
from typing import Any, Iterator, List, Optional, Tuple
......@@ -33,6 +34,19 @@ class OpamPackageInfo(BasePackageInfo):
committer = attr.ib(type=Person)
def opam() -> str:
"""Get the path to the opam executable.
Raises:
EnvironmentError if no opam executable is found
"""
ret = shutil.which("opam")
if not ret:
raise EnvironmentError("No opam executable found in path {os.environ['PATH']}")
return ret
def opam_read(
cmd: List[str], init_error_msg_if_any: Optional[str] = None
) -> Optional[str]:
......@@ -162,7 +176,7 @@ class OpamLoader(PackageLoader[OpamPackageInfo]):
# folder
call(
[
"opam",
opam(),
"init",
"--reinit",
"--bare",
......@@ -190,7 +204,7 @@ class OpamLoader(PackageLoader[OpamPackageInfo]):
package_file = self.get_package_file(version)
return [
"opam",
opam(),
"show",
"--color",
"never",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment