Skip to content

Commit

Permalink
Fix deprecation warning in provenance, fixes #2592
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jul 19, 2024
1 parent 24201c2 commit fcfef31
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ctapipe/core/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,17 @@ def provenance(self):


def _get_python_packages():
def _sortkey(dist):
"""Sort packages by name, case insensitive"""
# get is needed to avoid errors / deprecation warning
# in case packages with broken metadata are in the system
# see e.g. https://github.com/pypa/setuptools/issues/4482
return dist.metadata.get("Name", "").lower()

return [
{"name": p.name, "version": p.version}
for p in sorted(distributions(), key=lambda d: (d.name or "").lower())
{"name": p.name, "version": p.metadata.get("Version", "<unknown>")}
for p in sorted(distributions(), key=_sortkey)
if p.metadata.get("Name") is not None
]


Expand Down

0 comments on commit fcfef31

Please sign in to comment.