CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-wheel

Command line tool for manipulating wheel files

Overview
Eval results
Files

cli-commands.mddocs/

Command-Line Interface

Complete command-line interface for wheel manipulation operations. Provides subcommands for unpacking, repacking, converting, and modifying wheel files.

Capabilities

Main CLI Entry Point

Primary entry point for the wheel command-line tool with subcommand dispatching. Installed as console script wheel = "wheel._commands:main".

def main() -> int:
    """
    Main CLI entry point.
    
    Returns:
    Exit code (0 for success, 1 for error)
    """

def parser() -> argparse.ArgumentParser:
    """
    Create argument parser for CLI commands.
    
    Returns:
    Configured ArgumentParser with all subcommands
    """

Unpack Command

Extract wheel contents to a directory for inspection or modification.

def unpack(path: str, dest: str = ".") -> None:
    """
    Unpack a wheel file to a directory.
    
    Parameters:
    - path: Path to wheel file
    - dest: Destination directory (default: current directory)
    
    Creates directory: {dest}/{name}-{version}/
    Preserves file permissions from wheel archive
    """

CLI Usage

# Unpack wheel to current directory
wheel unpack package-1.0-py3-none-any.whl

# Unpack to specific directory
wheel unpack package-1.0-py3-none-any.whl --dest /tmp/wheels/

# Short form
wheel unpack package-1.0-py3-none-any.whl -d /tmp/wheels/

Pack Command

Repack a previously unpacked wheel directory into a new wheel file.

def pack(directory: str, dest_dir: str, build_number: str | None) -> None:
    """
    Repack wheel from unpacked directory.
    
    Parameters:
    - directory: Path to unpacked wheel directory
    - dest_dir: Destination directory for new wheel
    - build_number: Optional build tag to set/modify
    
    Raises:
    - WheelError: If no .dist-info directory found or multiple found
    - WheelError: If WHEEL file has no tags
    """

def compute_tagline(tags: list[str]) -> str:
    """
    Compute tagline from list of wheel tags.
    
    Parameters:
    - tags: List of tag strings (format: python-abi-platform)
    
    Returns:
    Combined tagline (format: python.abi.platform)
    """

CLI Usage

# Repack wheel directory
wheel pack package-1.0/ --dest-dir dist/

# Set build number
wheel pack package-1.0/ --dest-dir dist/ --build-number 20231201

# Short form
wheel pack package-1.0/ -d dist/

Convert Command

Convert legacy package formats (.egg files and Windows installers) to wheel format.

def convert(files: list[str], dest_dir: str, verbose: bool) -> None:
    """
    Convert .egg files and Windows installers to wheels.
    
    Parameters:
    - files: List of file patterns to convert
    - dest_dir: Output directory for converted wheels
    - verbose: Print conversion progress
    
    Supports:
    - .egg files (zipped and directory)
    - .exe Windows installers (bdist_wininst)
    """

CLI Usage

# Convert all .egg files in current directory
wheel convert *.egg --dest-dir wheels/

# Convert specific files with verbose output
wheel convert package-1.0-py2.7.egg --dest-dir wheels/ --verbose

# Short form
wheel convert *.egg -d wheels/ -v

Tags Command

Modify wheel tags (Python version, ABI, platform) without rebuilding the package.

def tags(
    wheel: str,
    python_tags: str | None = None,
    abi_tags: str | None = None,
    platform_tags: str | None = None,
    build_tag: str | None = None,
    remove: bool = False,
) -> str:
    """
    Modify wheel tags and create new wheel file.
    
    Parameters:
    - wheel: Path to wheel file
    - python_tags: Python version tags (e.g., "py38.py39")
    - abi_tags: ABI tags (e.g., "cp38.cp39")
    - platform_tags: Platform tags (e.g., "linux_x86_64.macosx_10_9_x86_64")
    - build_tag: Build tag (must start with digit)
    - remove: Delete original wheel file
    
    Returns:
    New wheel filename
    
    Tag modification rules:
    - Tags starting with '+' are appended
    - Tags starting with '-' are removed
    - Other tags replace existing tags
    - Tags can be dot-separated for multiple values
    """

CLI Usage

# Add Python versions
wheel tags --python-tag +py311 package-1.0-py3-none-any.whl

# Replace platform tags
wheel tags --platform-tag linux_x86_64.macosx_10_9_x86_64 package.whl

# Remove specific tags
wheel tags --python-tag -py37 package.whl

# Multiple modifications with build tag
wheel tags --python-tag py39.py310 --build 20231201 package.whl

# Remove original file
wheel tags --python-tag py311 --remove package.whl

Version Command

Display wheel package version information.

def version_f(args: argparse.Namespace) -> None:
    """
    Print wheel version and exit.
    """

CLI Usage

wheel version
# Output: wheel 0.46.1

Help Command

Display command help information.

CLI Usage

wheel help
# Displays full help information for all commands

Utility Functions

Helper functions for CLI argument parsing and validation.

def parse_build_tag(build_tag: str) -> str:
    """
    Validate and parse build tag string.
    
    Parameters:
    - build_tag: Build tag string
    
    Returns:
    Validated build tag
    
    Raises:
    - ArgumentTypeError: If tag doesn't start with digit or contains '-'
    """

Command Handler Functions

Internal functions that bridge CLI arguments to implementation functions.

def unpack_f(args: argparse.Namespace) -> None:
    """Handler for unpack command."""

def pack_f(args: argparse.Namespace) -> None:
    """Handler for pack command."""

def convert_f(args: argparse.Namespace) -> None:
    """Handler for convert command."""

def tags_f(args: argparse.Namespace) -> None:
    """Handler for tags command."""

def version_f(args: argparse.Namespace) -> None:
    """Handler for version command."""

def help_f(args: argparse.Namespace) -> None:
    """Handler for help command."""

Usage Examples

Programmatic CLI Access

from wheel._commands import main, parser
import sys

# Run CLI programmatically
sys.argv = ['wheel', 'unpack', 'package-1.0-py3-none-any.whl']
exit_code = main()

# Parse arguments without executing
p = parser()
args = p.parse_args(['pack', 'unpacked-wheel/', '-d', 'dist/'])
print(f"Command: {args.func.__name__}")
print(f"Directory: {args.directory}")

Error Handling

from wheel._commands import main
from wheel.wheelfile import WheelError
import sys

try:
    sys.argv = ['wheel', 'unpack', 'invalid-wheel.whl']
    exit_code = main()
except WheelError as e:
    print(f"Wheel error: {e}")
    sys.exit(1)

Types

import argparse
from typing import Literal

class ArgumentTypeError(Exception):
    """Exception raised for invalid command-line arguments."""
    pass

# CLI Help Text
TAGS_HELP: str
"""
Help text for the tags command explaining tag modification syntax.
"""

Install with Tessl CLI

npx tessl i tessl/pypi-wheel

docs

cli-commands.md

index.md

package-conversion.md

tag-management.md

wheelfile-ops.md

tile.json