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

fix(sdk): improve package name detection for metadata #2607

Merged
merged 4 commits into from
Feb 5, 2025
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
16 changes: 15 additions & 1 deletion packages/traceloop-sdk/traceloop/sdk/utils/package_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
from importlib.metadata import distributions

installed_packages = {dist.metadata["Name"].lower() for dist in distributions()}

def _get_package_name(dist):
# Try both 'Name' and 'name' keys to handle different metadata formats
if hasattr(dist, 'metadata') and dist.metadata is not None:
for key in ('Name', 'name'):
try:
return dist.metadata[key].lower()
except (KeyError, AttributeError):
continue

# If metadata is missing or neither key exists, use the distribution name directly
return dist.name.lower()


installed_packages = {_get_package_name(dist) for dist in distributions()}


def is_package_installed(package_name: str) -> bool:
Expand Down