witty-crayon-22786
03/03/2021, 12:06 AMdef get_pyenv_root():
try:
return subprocess.check_output(["pyenv", "root"]).decode().strip()
except (OSError, subprocess.CalledProcessError):
return None
hundreds-father-404
03/03/2021, 12:10 AMwitty-crayon-22786
03/03/2021, 12:10 AMsrc/python/pants/python/python_setup.py
enough-analyst-54434
03/03/2021, 12:30 AM$ echo $PYENV_ROOT
$ pyenv root
/home/jsirois/.pyenv
witty-crayon-22786
03/04/2021, 9:24 PMdef get_pyenv_root(pants_env: PantsEnvironment) -> str:
"""See <https://github.com/pyenv/pyenv#environment-variables>."""
from_env = pants_env.env.get("PYENV_ROOT")
if from_env:
return from_env
home_from_env = pants_env.env.get("HOME")
if home_from_env:
return os.path.join(home_from_env, ".cache")
raise ValueError(
f"The environment {pants_env} does not contain enough information to locate pyenv."
)
… and that seems fine.PATH
based?interpreter_search_path: [<PYENV>]
via ~/.pantsrc
… and that’s triggering under unit tests (which is a bug that i need to look into independently)..pantsrc
usage, the next question is: how do we want to ensure that we’re able to find pythons in Pants’ tests?enough-analyst-54434
03/04/2021, 9:37 PMpyenv root
. Clearly we can run that later in a rule if PYENV_ROOT is not in the env but pyenv is on the PATH - right?witty-crayon-22786
03/04/2021, 9:38 PMpyenv root
correctly, we’d need to pass through both of these env vars anywaysubprocess
(afaict)enough-analyst-54434
03/04/2021, 9:39 PMwitty-crayon-22786
03/04/2021, 9:40 PMenough-analyst-54434
03/04/2021, 9:42 PMwitty-crayon-22786
03/04/2021, 9:43 PM.pantsrc
aspect. this is relevant to me because
$ cat ~/.pants.rc
[python-setup]
# Avoid system python.
interpreter_search_paths = ["<PYENV>"]
enough-analyst-54434
03/04/2021, 9:44 PMpyenv root
would still be used if I had <PYENV> but no PYENV_ROOT exported.witty-crayon-22786
03/04/2021, 9:44 PMenough-analyst-54434
03/04/2021, 9:45 PMpyenv root
call not be moved off to a rule as a fallback?witty-crayon-22786
03/04/2021, 9:46 PMpyenv root
requires PYENV_ROOT or HOMEif you run it without those, you will get the wrong answer (or it will fail.)it appears that the result is: “wrong answer”:
$ env -i /usr/local/bin/pyenv root
/.pyenv
enough-analyst-54434
03/04/2021, 9:51 PMwitty-crayon-22786
03/04/2021, 11:29 PM--interpreter-search-paths
is ["<PYENV>", "<PATH>"]