From 99e18747e652cb9ebbeff840dc03250ce88be545 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Tue, 28 May 2024 09:48:33 -0400 Subject: [PATCH 1/2] fix: 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. --- twine/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 From 884b6b25241f435ce9bebb59e488063064fce1e3 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Tue, 28 May 2024 10:00:57 -0400 Subject: [PATCH 2/2] doc: Add changelog entry --- changelog/1115.bugfix.rst | 1 + 1 file changed, 1 insertion(+) 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.