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

Commit dbd734a

Browse files
committed
preemptive conflict avoidance
1 parent 524795b commit dbd734a

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tox_pyenv.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ class PyenvMissing(ToxPyenvException, RuntimeError):
6767
"""The pyenv program is not installed."""
6868

6969

70-
class PyenvWhichFailed(ToxPyenvException):
70+
class PyenvFailed(ToxPyenvException):
71+
72+
"""Calling `pyenv` failed."""
73+
74+
75+
class PyenvWhichFailed(PyenvFailed):
7176

7277
"""Calling `pyenv which` failed."""
7378

@@ -173,6 +178,39 @@ def _enable_and_call(_available_version):
173178
return _enable_and_call(match)
174179

175180

181+
@tox_hookimpl
182+
def tox_get_python_executable(envconfig):
183+
try:
184+
pyenv = (getattr(py.path.local.sysfind('pyenv'), 'strpath', 'pyenv')
185+
or 'pyenv')
186+
cmd = [pyenv, 'which', envconfig.basepython]
187+
pipe = subprocess.Popen(
188+
cmd,
189+
stdout=subprocess.PIPE,
190+
stderr=subprocess.PIPE,
191+
universal_newlines=True
192+
)
193+
out, err = pipe.communicate()
194+
except OSError:
195+
err = '\'pyenv\': command not found'
196+
LOG.warning(
197+
"pyenv doesn't seem to be installed, you probably "
198+
"don't want this plugin installed either."
199+
)
200+
else:
201+
if pipe.poll() == 0:
202+
return out.strip()
203+
else:
204+
if not envconfig.tox_pyenv_fallback:
205+
raise PyenvFailed(err)
206+
LOG.debug("`%s` failed thru tox-pyenv plugin, falling back. "
207+
"STDERR: \"%s\" | To disable this behavior, set "
208+
"tox_pyenv_fallback=False in your tox.ini or use "
209+
" --tox-pyenv-no-fallback on the command line.",
210+
' '.join([str(x) for x in cmd]), err)
211+
212+
213+
176214
@tox_hookimpl
177215
def tox_get_python_executable(envconfig):
178216
"""Hook into tox plugins to use pyenv to find executables."""

0 commit comments

Comments
 (0)