or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/tox-pyenv@1.1.x
tile.json

tessl/pypi-tox-pyenv

tessl install tessl/pypi-tox-pyenv@1.1.0

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

Agent Success

Agent success rate when using this tile

98%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.03x

Baseline

Agent success rate without this tile

95%

task.mdevals/scenario-10/

Tool Version Validator

Build a Python utility that validates whether a command-line tool is installed with a specific version. The utility executes the tool's version command as a subprocess and verifies the output matches the expected version.

Behavior

The utility should:

  • Execute a command <tool_name> --version to retrieve version information
  • Capture both standard output and standard error from the subprocess
  • Parse the version number from the output (expecting format like "toolname 1.2.3")
  • Compare the parsed version with the expected version string
  • Raise appropriate exceptions for different error conditions

Error Handling

The utility must handle three distinct error scenarios:

  1. Tool not found: When the command doesn't exist in the system PATH, catch OSError and raise ToolNotFoundError
  2. Command failure: When the subprocess exits with a non-zero status code, raise CommandFailedError with the stderr output
  3. Version mismatch: When the tool is found but the version doesn't match expectations, raise VersionMismatchError

All custom exceptions should inherit from a base VersionCheckError exception.

Test Cases

  • It successfully validates when the correct version is found @test
  • It raises an error when the tool is not found in PATH @test
  • It raises an error when the command exits with non-zero status @test
  • It raises an error when the version doesn't match @test

Implementation

@generates

API

class VersionCheckError(Exception):
    """Base exception for version checking errors."""
    pass

class ToolNotFoundError(VersionCheckError):
    """Raised when the tool is not found in the system PATH."""
    pass

class CommandFailedError(VersionCheckError):
    """Raised when the command execution fails with non-zero exit code."""
    pass

class VersionMismatchError(VersionCheckError):
    """Raised when the actual version doesn't match the expected version."""
    pass

def check_version(tool_name: str, expected_version: str) -> bool:
    """
    Check if a tool's version matches the expected version.

    Args:
        tool_name: Name of the command-line tool to check
        expected_version: Expected version string (e.g., "1.2.3")

    Returns:
        True if the version matches

    Raises:
        ToolNotFoundError: If the tool is not found in PATH
        CommandFailedError: If the command exits with non-zero status
        VersionMismatchError: If the version doesn't match
    """
    pass

Dependencies { .dependencies }

subprocess { .dependency }

Provides subprocess execution and management capabilities for running external commands.