Python packaging quality assessment tool that evaluates how well Python projects comply with best practices of the Python packaging ecosystem.
—
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.
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:
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
"""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:
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:
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')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