CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-tox-pyenv

tox plugin that makes tox use `pyenv which` to find python executables

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-8/

Python Environment Fallback Handler

A tox plugin that implements a fallback mechanism for Python executable discovery, attempting to use a primary version manager before falling back to the system's default Python discovery.

Capabilities

Primary version manager discovery

  • When given basepython "python3.8" and the primary manager successfully returns "/usr/local/bin/python3.8", the function returns that path @test
  • When given basepython "python2.7" and the primary manager successfully returns "/opt/python/2.7/bin/python2.7", the function returns that path @test

Fallback to default discovery

  • When the primary manager command fails with exit code 1, the function returns None to allow tox's default discovery @test
  • When the primary manager raises an OSError (command not found), the function returns None to allow tox's default discovery @test

Error handling

  • When the primary manager returns an empty string, the function returns None to trigger fallback @test

Implementation

@generates

API

import subprocess
from typing import Optional

def get_python_executable(basepython: str, primary_command: str) -> Optional[str]:
    """
    Attempts to discover Python executable using a primary command, falling back to None.

    Args:
        basepython: The target Python version identifier (e.g., "python3.8", "python2.7")
        primary_command: The command to use for primary discovery (e.g., "pyenv")

    Returns:
        The full path to the Python executable if found via primary command,
        or None to signal that tox should use its default discovery mechanism.

    The function executes: `<primary_command> which <basepython>`
    """
    pass

Install with Tessl CLI

npx tessl i tessl/pypi-tox-pyenv

tile.json