tox plugin that makes tox use `pyenv which` to find python executables
npx @tessl/cli install tessl/pypi-tox-pyenv@1.1.0A tox plugin that integrates pyenv with tox for Python version management during testing. The plugin replaces tox's default Python executable discovery mechanism with pyenv's pyenv which command, ensuring tox uses specific Python versions managed by pyenv rather than falling back to system-wide installations.
pip install tox-pyenvimport tox_pyenvFor accessing specific components:
from tox_pyenv import ToxPyenvException, PyenvMissing, PyenvWhichFailedThe plugin automatically activates when installed alongside tox. No explicit import or initialization is required in user code - it operates through tox's plugin system.
# Example circle.yml configuration
dependencies:
override:
- pip install tox tox-pyenv
- pyenv local 2.7.9 3.4.3 3.5.0# Example tox.ini configuration
[tox]
envlist = py27,py34,py35
[testenv]
# Optional: disable fallback to tox's default behavior
tox_pyenv_fallback = False# Command line usage with no-fallback option
tox --tox-pyenv-no-fallbackFunctions that integrate with tox's plugin system to modify its behavior.
def tox_get_python_executable(envconfig):
"""
Return a python executable for the given python base name using pyenv which.
This hook function replaces tox's default python executable discovery.
Uses `pyenv which {basepython}` to locate the appropriate python executable.
Args:
envconfig: testenv configuration object containing .envname and .basepython settings
Returns:
str or None: Path to python executable, or None if fallback is needed
Raises:
PyenvWhichFailed: If pyenv which command fails and fallback is disabled
"""
def tox_addoption(parser):
"""
Add command line option to the argparse-style parser object.
Adds the --tox-pyenv-no-fallback command line option and corresponding
tox_pyenv_fallback configuration option.
Args:
parser: tox argument parser object
"""Custom exceptions for plugin-specific error handling.
class ToxPyenvException(Exception):
"""Base class for exceptions from this plugin."""
class PyenvMissing(ToxPyenvException, RuntimeError):
"""The pyenv program is not installed."""
class PyenvWhichFailed(ToxPyenvException):
"""Calling `pyenv which` failed."""--tox-pyenv-no-fallback / -F: Disable fallback to tox's built-in python executable discovery when pyenv failstox_pyenv_fallback (bool): If pyenv which {basepython} fails, allow fallback to tox's built-in default logic (default: True)Package information constants available for introspection.
__title__ = 'tox-pyenv'
__summary__ = 'tox plugin that makes tox use `pyenv which` to find python executables'
__url__ = 'https://github.com/samstav/tox-pyenv'
__version__ = '1.1.0'
__author__ = 'Sam Stavinoha'
__email__ = 'smlstvnh@gmail.com'
__keywords__ = ['tox', 'pyenv', 'python']
__license__ = 'Apache License, Version 2.0'The plugin is automatically registered with tox via setuptools entry points:
# In setup.py
ENTRY_POINTS = {
'tox': [
'pyenv = tox_pyenv',
]
}The plugin includes comprehensive error handling for common failure scenarios:
pyenv which command returns non-zero exit codeWhen fallback is enabled (default: True), the plugin logs warnings and allows tox to continue with its built-in executable discovery. When fallback is disabled, the plugin raises PyenvWhichFailed exceptions to halt execution.