Skip to content

Commit

Permalink
Fix compatibility with importlib-metadata 8 and Python 3.13
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Jan 1, 2025
1 parent fe6926a commit ad95dcb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions src/rez_pip/rez.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,47 +141,47 @@ def _convertMetadata(
del originalMetadata["version"]

# https://packaging.python.org/en/latest/specifications/core-metadata/#summary
if dist.metadata["Summary"]:
if "Summary" in dist.metadata:
metadata["summary"] = dist.metadata["Summary"]
del originalMetadata["summary"]

# https://packaging.python.org/en/latest/specifications/core-metadata/#description
if dist.metadata["Description"]:
if "Description" in dist.metadata:
metadata["description"] = dist.metadata["Description"]
del originalMetadata["description"]

authors = []

# https://packaging.python.org/en/latest/specifications/core-metadata/#author
author = dist.metadata["Author"]
if author:
authors.append(author)
if "Author" in dist.metadata:
authors.append(dist.metadata["Author"])
del originalMetadata["author"]

# https://packaging.python.org/en/latest/specifications/core-metadata/#author-email
authorEmail = dist.metadata["Author-email"]
if authorEmail:
authors.extend([email.strip() for email in authorEmail.split(",")])
if "Author-email" in dist.metadata:
authors.extend(
[email.strip() for email in dist.metadata["Author-email"].split(",")]
)
del originalMetadata["author_email"]

# https://packaging.python.org/en/latest/specifications/core-metadata/#maintainer
maintainer = dist.metadata["Maintainer"]
if maintainer:
authors.append(maintainer)
if "Maintainer" in dist.metadata:
authors.append(dist.metadata["Maintainer"])
del originalMetadata["maintainer"]

# https://packaging.python.org/en/latest/specifications/core-metadata/#maintainer-email
maintainerEmail = dist.metadata["Maintainer-email"]
if maintainerEmail:
authors.extend([email.strip() for email in maintainerEmail.split(",")])
if "Maintainer-email" in dist.metadata:
authors.extend(
[email.strip() for email in dist.metadata["Maintainer-email"].split(",")]
)
del originalMetadata["maintainer_email"]

if authors:
metadata["authors"] = authors

# https://packaging.python.org/en/latest/specifications/core-metadata/#license
# Prefer the License field and fallback to classifiers if one is present.
if dist.metadata["License"]:
if "License" in dist.metadata:
metadata["license"] = dist.metadata["License"]
del originalMetadata["license"]
else:
Expand All @@ -199,12 +199,12 @@ def _convertMetadata(
helpLinks = []

# https://packaging.python.org/en/latest/specifications/core-metadata/#home-page
if dist.metadata["Home-page"]:
if "Home-page" in dist.metadata:
helpLinks.append(["Home-page", dist.metadata["Home-page"]])
del originalMetadata["home_page"]

# https://packaging.python.org/en/latest/specifications/core-metadata/#project-url-multiple-use
if dist.metadata["Project-URL"]:
if "Project-URL" in dist.metadata:
urls = [
url.strip()
for value in dist.metadata.get_all("Project-URL", failobj=[])
Expand All @@ -214,7 +214,7 @@ def _convertMetadata(
del originalMetadata["project_url"]

# https://packaging.python.org/en/latest/specifications/core-metadata/#download-url
if dist.metadata["Download-URL"]:
if "Download-URL" in dist.metadata:
helpLinks.append(["Download-URL", dist.metadata["Download-URL"]])
del originalMetadata["download_url"]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_rez.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_convertMetadata(
expectedRemaining,
monkeypatch: pytest.MonkeyPatch,
):
dist = importlib_metadata.Distribution()
dist = importlib_metadata.PathDistribution("asd")
monkeypatch.setattr(
dist,
"read_text",
Expand Down

0 comments on commit ad95dcb

Please sign in to comment.