CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pip

The PyPA recommended tool for installing Python packages.

91

1.07x
Overview
Eval results
Files

task.mdevals/scenario-4/

Package Cache Manager

Build a command-line tool that helps users manage their Python package manager's cache.

Overview

Python package managers maintain a cache to speed up installations. Your tool should provide a simple interface to query and manage this cache, helping users understand cache usage and free up disk space when needed.

Requirements

Cache Information Display

The tool must provide functionality to:

  • Display the location of the cache directory
  • Show cache statistics including the total number of cached items and total disk space used

Cache Content Listing

The tool must support:

  • Listing all cached wheel files with their package names and file sizes
  • Filtering cached items by a pattern (e.g., show only items matching "requests*")
  • Sorting output by package name

Cache Item Removal

The tool must allow:

  • Removing specific cached items matching a given pattern
  • Confirmation before deletion with details about items to be removed
  • Reporting how many items were removed and disk space freed

Complete Cache Purge

The tool must support:

  • Clearing all cached items with a single operation
  • Confirmation prompt before purging (with ability to skip confirmation via flag)
  • Summary of total items removed and space reclaimed

Command-Line Interface

Your tool should support the following commands:

# Show cache directory location
python cache_manager.py info --directory

# Show cache statistics
python cache_manager.py info --stats

# List all cached items
python cache_manager.py list

# List items matching a pattern
python cache_manager.py list --pattern "numpy*"

# Remove items matching a pattern
python cache_manager.py remove --pattern "old-package*"

# Remove items with confirmation skip
python cache_manager.py remove --pattern "temp*" --yes

# Purge all cache
python cache_manager.py purge

# Purge without confirmation
python cache_manager.py purge --yes

Implementation

@generates

API

"""
Package cache management utility.
"""

import argparse
from typing import Optional, List, Dict

class CacheManager:
    """Manages package cache operations."""

    def get_cache_directory(self) -> str:
        """
        Returns the path to the package cache directory.

        Returns:
            str: Absolute path to the cache directory
        """
        pass

    def get_cache_stats(self) -> Dict[str, any]:
        """
        Returns cache statistics.

        Returns:
            Dict with keys:
                - 'item_count': Number of cached items
                - 'total_size': Total size in bytes
        """
        pass

    def list_cached_items(self, pattern: Optional[str] = None) -> List[Dict[str, any]]:
        """
        Lists cached wheel files, optionally filtered by pattern.

        Args:
            pattern: Optional glob pattern to filter items (e.g., "numpy*")

        Returns:
            List of dicts with keys:
                - 'name': Package name
                - 'filename': Full filename
                - 'size': Size in bytes
        """
        pass

    def remove_cached_items(self, pattern: str, confirm: bool = True) -> Dict[str, any]:
        """
        Removes cached items matching the pattern.

        Args:
            pattern: Glob pattern to match items for removal
            confirm: If True, prompts for confirmation before removal

        Returns:
            Dict with keys:
                - 'removed_count': Number of items removed
                - 'space_freed': Bytes freed
        """
        pass

    def purge_cache(self, confirm: bool = True) -> Dict[str, any]:
        """
        Removes all cached items.

        Args:
            confirm: If True, prompts for confirmation before purging

        Returns:
            Dict with keys:
                - 'removed_count': Number of items removed
                - 'space_freed': Bytes freed
        """
        pass

def main():
    """Main entry point for the CLI."""
    pass

if __name__ == "__main__":
    main()

Test Cases

  • The tool correctly reports the cache directory location @test
  • The tool accurately calculates and displays cache statistics (count and size) @test
  • The tool lists all cached wheel files with correct names and sizes @test
  • The tool filters cached items by pattern correctly (e.g., "requests*" matches "requests-2.28.0.whl") @test
  • The tool removes cached items matching a pattern and reports accurate counts @test
  • The tool purges all cache items and correctly reports the number removed @test
  • The tool prompts for confirmation before removal operations when confirm=True @test

Dependencies { .dependencies }

pip { .dependency }

Provides Python package management and caching functionality.

Install with Tessl CLI

npx tessl i tessl/pypi-pip

tile.json