CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyroma

Python packaging quality assessment tool that evaluates how well Python projects comply with best practices of the Python packaging ecosystem.

Pending
Overview
Eval results
Files

data-extraction.mddocs/

Data Extraction

Functions for extracting package metadata from different sources including project directories, distribution files, and PyPI packages. These modules handle the complexities of parsing various packaging formats, build systems, and configuration files.

Capabilities

Project Directory Analysis

pyroma.projectdata Module

Functions for extracting metadata from local project directories using modern Python build systems.

METADATA_MAP

METADATA_MAP: dict
"""Mapping of metadata field names between different packaging systems.

Maps standard setuptools/wheel metadata field names to their pyroma equivalents.
Used internally to normalize metadata from different sources like setup.cfg, 
pyproject.toml, and wheel metadata.

Example mappings:
- 'summary' -> 'description'
- 'classifier' -> 'classifiers'  
- 'home_page' -> 'url'
- 'requires_python' -> 'python_requires'
"""

get_data(path)

def get_data(path):
    """Extract package metadata from a project directory.
    
    Args:
        path: Absolute path to project directory
        
    Returns:
        dict: Package metadata including name, version, description,
              classifiers, dependencies, and build system information
              
    Raises:
        build.BuildException: If project cannot be built or analyzed
    """

Primary function for project analysis that:

  • Uses Python build system to extract metadata
  • Supports pyproject.toml, setup.cfg, and setup.py configurations
  • Handles both isolated and non-isolated build environments
  • Automatically falls back through different extraction methods
  • Adds internal flags for missing configuration files

build_metadata(path, isolated=None)

def build_metadata(path, isolated=None):
    """Build wheel metadata using the project's build system.
    
    Args:
        path: Project directory path
        isolated: Whether to use build isolation (None for auto-detection)
        
    Returns:
        Metadata object containing package information
        
    Raises:
        build.BuildBackendException: If build system fails
    """

map_metadata_keys(metadata)

def map_metadata_keys(metadata) -> dict:
    """Convert metadata object to standardized dictionary format.
    
    Args:
        metadata: Metadata object from build system
        
    Returns:
        dict: Normalized metadata with standardized key names
    """

get_build_data(path, isolated=None)

def get_build_data(path, isolated=None):
    """Extract package data using modern build system.
    
    Args:
        path: Project directory path  
        isolated: Whether to use build isolation
        
    Returns:
        dict: Package metadata with build system information
    """

get_setupcfg_data(path)

def get_setupcfg_data(path):
    """Extract metadata from setup.cfg configuration file.
    
    Args:
        path: Project directory path
        
    Returns:
        dict: Metadata from setup.cfg file
        
    Raises:
        Exception: If setup.cfg cannot be parsed
    """

get_setuppy_data(path)

def get_setuppy_data(path):
    """Extract metadata by executing setup.py (fallback method).
    
    Args:
        path: Absolute path to project directory
        
    Returns:
        dict: Package metadata from setup.py execution
        
    Note:
        This is a fallback method for legacy projects and
        adds '_stoneage_setuppy' flag to indicate usage
    """

Distribution File Analysis

pyroma.distributiondata Module

Functions for analyzing packaged distribution files (tar.gz, zip, wheel, egg).

get_data(path)

def get_data(path):
    """Extract metadata from a distribution file.
    
    Args:
        path: Path to distribution file (.tar.gz, .zip, .egg, etc.)
        
    Returns:
        dict: Package metadata extracted from distribution
        
    Raises:
        ValueError: If file type is not supported
        tarfile.TarError: If tar file is corrupted
        zipfile.BadZipFile: If zip file is corrupted
    """

Analyzes distribution files by:

  • Safely extracting archives to temporary directories
  • Using project data extraction on extracted contents
  • Supporting multiple archive formats (tar.gz, tar.bz2, zip, egg)
  • Protecting against path traversal attacks (CVE-2007-4559)
  • Cleaning up temporary files automatically

PyPI Package Analysis

pyroma.pypidata Module

Functions for analyzing packages published on PyPI using the PyPI API and XML-RPC interface.

get_data(project)

def get_data(project):
    """Extract metadata from a PyPI package.
    
    Args:
        project: PyPI package name
        
    Returns:
        dict: Complete package metadata including PyPI-specific information
        
    Raises:
        ValueError: If package not found on PyPI or HTTP error occurs
        requests.RequestException: If network request fails
    """

Comprehensive PyPI analysis that:

  • Downloads package metadata from PyPI JSON API
  • Retrieves ownership information via XML-RPC
  • Downloads and analyzes source distributions when available
  • Combines PyPI metadata with distribution analysis
  • Adds PyPI-specific flags (_owners, _has_sdist, _pypi_downloads)

Usage examples:

# Analyze local project
from pyroma.projectdata import get_data
data = get_data('/path/to/project')

# Analyze distribution file  
from pyroma.distributiondata import get_data
data = get_data('package-1.0.tar.gz')

# Analyze PyPI package
from pyroma.pypidata import get_data  
data = get_data('requests')

Helper Classes

FakeContext

class FakeContext:
    """Context manager for temporarily changing working directory and sys.path.
    
    Used internally for safe execution of setup.py files without
    affecting the global Python environment.
    """
    
    def __init__(self, path): ...
    def __enter__(self): ...
    def __exit__(self, exc_type, exc_val, exc_tb): ...

SetupMonkey

class SetupMonkey:
    """Context manager that monkey-patches setup() calls to capture metadata.
    
    Intercepts calls to distutils.core.setup() and setuptools.setup()
    to extract package metadata without executing setup commands.
    """
    
    def __enter__(self): ...
    def __exit__(self, exc_type, exc_val, exc_tb): ...
    def get_data(self): ...

Install with Tessl CLI

npx tessl i tessl/pypi-pyroma

docs

core-analysis.md

data-extraction.md

index.md

rating-system.md

tile.json