import pkg_resources
from typing import Dict
from typing import Any


def get_distribution_metadata(
        distribution: pkg_resources.Distribution
) -> Dict[str, Any]:
    """
    Get metadata of a given distribution and all its dependencies.

    :param distribution: A distribution object
    :return: A metadata dictionary
    """
    requirements = map(pkg_resources.get_distribution, distribution.requires())
    return {
        'name':         distribution.project_name,
        'version':      distribution.version,
        'py_version':   distribution.py_version,
        'requirements': {
            requirement.project_name: get_distribution_metadata(requirement)
            for requirement in requirements
        },
    }