From f213ede904ec8553c82e75d6125efd1972fe8b00 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Wed, 26 Jun 2024 10:36:47 -0400 Subject: [PATCH] fix: Retrieve metadata correctly from importlib_metadata (#1115) * fixes #977: Retrieve metadata correctly from importlib_metadata Running twine with `PYTHONWARNINGS=error`, DeprecationWarnings about missing keys indicate that `twine.__uri__` is being set to `None`. `author` is also missing from package metadata. This change iterates over Project-URLs looking for "Homepage", and parses the author and email from Author-Email. The email stdlib module is used for correctness; it is already imported by importlib_metadata, so this does not add to import time. --- changelog/1115.bugfix.rst | 1 + twine/__init__.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 changelog/1115.bugfix.rst diff --git a/changelog/1115.bugfix.rst b/changelog/1115.bugfix.rst new file mode 100644 index 00000000..1026c3a4 --- /dev/null +++ b/changelog/1115.bugfix.rst @@ -0,0 +1 @@ +Resolve DeprecationWarnings when extracting ``twine`` metadata. diff --git a/twine/__init__.py b/twine/__init__.py index 99a68612..0952da38 100644 --- a/twine/__init__.py +++ b/twine/__init__.py @@ -30,6 +30,8 @@ __copyright__ = "Copyright 2019 Donald Stufft and individual contributors" +import email + import importlib_metadata metadata = importlib_metadata.metadata("twine") @@ -37,8 +39,11 @@ __title__ = metadata["name"] __summary__ = metadata["summary"] -__uri__ = metadata["home-page"] +__uri__ = next( + entry.split(", ")[1] + for entry in metadata.get_all("Project-URL", ()) + if entry.startswith("Homepage") +) __version__ = metadata["version"] -__author__ = metadata["author"] -__email__ = metadata["author-email"] +__author__, __email__ = email.utils.parseaddr(metadata["author-email"]) __license__ = None