Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
preemptive conflict avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
stavxyz committed Jan 24, 2018
1 parent 524795b commit dbd734a
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tox_pyenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ class PyenvMissing(ToxPyenvException, RuntimeError):
"""The pyenv program is not installed."""


class PyenvWhichFailed(ToxPyenvException):
class PyenvFailed(ToxPyenvException):

"""Calling `pyenv` failed."""


class PyenvWhichFailed(PyenvFailed):

"""Calling `pyenv which` failed."""

Expand Down Expand Up @@ -173,6 +178,39 @@ def _enable_and_call(_available_version):
return _enable_and_call(match)


@tox_hookimpl
def tox_get_python_executable(envconfig):
try:
pyenv = (getattr(py.path.local.sysfind('pyenv'), 'strpath', 'pyenv')
or 'pyenv')
cmd = [pyenv, 'which', envconfig.basepython]
pipe = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
out, err = pipe.communicate()
except OSError:
err = '\'pyenv\': command not found'
LOG.warning(
"pyenv doesn't seem to be installed, you probably "
"don't want this plugin installed either."
)
else:
if pipe.poll() == 0:
return out.strip()
else:
if not envconfig.tox_pyenv_fallback:
raise PyenvFailed(err)
LOG.debug("`%s` failed thru tox-pyenv plugin, falling back. "
"STDERR: \"%s\" | To disable this behavior, set "
"tox_pyenv_fallback=False in your tox.ini or use "
" --tox-pyenv-no-fallback on the command line.",
' '.join([str(x) for x in cmd]), err)



@tox_hookimpl
def tox_get_python_executable(envconfig):
"""Hook into tox plugins to use pyenv to find executables."""
Expand Down

0 comments on commit dbd734a

Please sign in to comment.