Source code for langchain_core.sys_info

"""**sys_info** prints information about the system and langchain packages
for debugging purposes.
"""

from collections.abc import Sequence


def _get_sub_deps(packages: Sequence[str]) -> list[str]:
    """Get any specified sub-dependencies."""
    from importlib import metadata

    sub_deps = set()
    _underscored_packages = {pkg.replace("-", "_") for pkg in packages}

    for pkg in packages:
        try:
            required = metadata.requires(pkg)
        except metadata.PackageNotFoundError:
            continue

        if not required:
            continue

        for req in required:
            try:
                cleaned_req = req.split(" ")[0]
            except Exception:  # In case parsing of requirement spec fails
                continue

            if cleaned_req.replace("-", "_") not in _underscored_packages:
                sub_deps.add(cleaned_req)

    return sorted(sub_deps, key=lambda x: x.lower())






if __name__ == "__main__":
    print_sys_info()