Skip to content

Commit

Permalink
fix(sdk): improve package name detection for metadata (#2607)
Browse files Browse the repository at this point in the history
  • Loading branch information
doronkopit5 authored Feb 5, 2025
1 parent 2741061 commit 8c9ef5a
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 8c9ef5a

Please sign in to comment.