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-2/

Python Version Resolver

Build a command-line tool that resolves and reports Python executable paths for different Python versions using pyenv.

Requirements

Your tool should accept a Python version identifier (e.g., python3.9, python2.7, pypy3) as a command-line argument and output the full path to the corresponding Python executable as managed by pyenv.

Core Functionality

The tool must:

  1. Accept a single command-line argument specifying a Python version identifier
  2. Query pyenv to locate the executable for the specified Python version
  3. Print the full path to the Python executable to stdout
  4. Exit with code 0 on success

Error Handling

The tool must handle errors appropriately:

  1. If pyenv is not installed or not found in the system, print an error message to stderr and exit with code 1
  2. If pyenv cannot find the requested Python version, print an error message to stderr and exit with code 2
  3. If no command-line argument is provided, print a usage message to stderr and exit with code 1

Test Cases

  • Given the argument python3.9 when pyenv has Python 3.9 installed, the tool outputs the path /home/user/.pyenv/versions/3.9.0/bin/python3.9 and exits with code 0 @test
  • Given the argument python2.7 when pyenv does not have Python 2.7 installed, the tool prints an error to stderr and exits with code 2 @test
  • Given no arguments, the tool prints a usage message to stderr and exits with code 1 @test
  • When pyenv is not available in PATH, the tool prints an error message to stderr and exits with code 1 @test

Implementation

@generates

API

#!/usr/bin/env python
"""
Python Version Resolver - Resolves Python executable paths via pyenv
"""

def find_pyenv_binary():
    """
    Locate the pyenv binary in the system PATH.

    Returns:
        str: Path to the pyenv binary

    Raises:
        FileNotFoundError: If pyenv is not found in PATH
    """
    pass

def resolve_python_executable(version_identifier):
    """
    Resolve the full path to a Python executable for a given version identifier.

    Args:
        version_identifier (str): Python version identifier (e.g., 'python3.9', 'pypy3')

    Returns:
        str: Full path to the Python executable

    Raises:
        FileNotFoundError: If pyenv is not available
        RuntimeError: If pyenv cannot find the specified Python version
    """
    pass

def main():
    """
    Main entry point for the command-line tool.

    Parses command-line arguments, resolves the Python executable,
    and prints the result or error messages.

    Exits with appropriate status codes:
        0: Success
        1: Invalid usage or pyenv not found
        2: Python version not found by pyenv
    """
    pass

if __name__ == '__main__':
    main()

Dependencies { .dependencies }

tox-pyenv { .dependency }

Provides reference implementation for pyenv integration patterns

Install with Tessl CLI

npx tessl i tessl/pypi-tox-pyenv

tile.json