Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[patch]: Update sys info information #16297

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions libs/core/langchain_core/sys_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@

def print_sys_info(*, additional_pkgs: Sequence[str] = tuple()) -> None:
"""Print information about the environment for debugging purposes."""
import pkgutil
import platform
import sys
from importlib import metadata, util

packages = [
"langchain_core",
"langchain",
"langchain_community",
# Packages that do not start with "langchain" prefix.
other_langchain_packages = [
"langserve",
] + list(additional_pkgs)
"langgraph",
]

langchain_pkgs = [
name for _, name, _ in pkgutil.iter_modules() if name.startswith("langchain")
]

all_packages = sorted(
set(langchain_pkgs + other_langchain_packages + list(additional_pkgs))
)

# Always surface these packages to the top
order_by = ["langchain_core", "langchain", "langchain_community"]

for pkg in reversed(order_by):
if pkg in all_packages:
all_packages.remove(pkg)
all_packages = [pkg] + list(all_packages)

system_info = {
"OS": platform.system(),
Expand All @@ -32,13 +48,15 @@ def print_sys_info(*, additional_pkgs: Sequence[str] = tuple()) -> None:
print("Package Information")
print("-------------------")

for pkg in packages:
not_installed = []

for pkg in all_packages:
try:
found_package = util.find_spec(pkg)
except Exception:
found_package = None
if found_package is None:
print(f"> {pkg}: Not Found")
not_installed.append(pkg)
continue

# Package version
Expand All @@ -51,7 +69,16 @@ def print_sys_info(*, additional_pkgs: Sequence[str] = tuple()) -> None:
if package_version is not None:
print(f"> {pkg}: {package_version}")
else:
print(f"> {pkg}: Found")
print(f"> {pkg}: Installed. No version info available.")

if not_installed:
print()
print("Packages not installed (Not Necessarily a Problem)")
print("--------------------------------------------------")
print("The following packages were not found:")
print()
for pkg in not_installed:
print(f"> {pkg}")


if __name__ == "__main__":
Expand Down
Loading