@@ -67,7 +67,12 @@ class PyenvMissing(ToxPyenvException, RuntimeError):
67
67
"""The pyenv program is not installed."""
68
68
69
69
70
- class PyenvWhichFailed (ToxPyenvException ):
70
+ class PyenvFailed (ToxPyenvException ):
71
+
72
+ """Calling `pyenv` failed."""
73
+
74
+
75
+ class PyenvWhichFailed (PyenvFailed ):
71
76
72
77
"""Calling `pyenv which` failed."""
73
78
@@ -173,6 +178,39 @@ def _enable_and_call(_available_version):
173
178
return _enable_and_call (match )
174
179
175
180
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
+
176
214
@tox_hookimpl
177
215
def tox_get_python_executable (envconfig ):
178
216
"""Hook into tox plugins to use pyenv to find executables."""
0 commit comments