Skip to content

Commit

Permalink
fix: Retrieve metadata correctly from importlib_metadata (#1115)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
effigies committed Jun 26, 2024
1 parent 6fbf880 commit f213ede
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/1115.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resolve DeprecationWarnings when extracting ``twine`` metadata.
11 changes: 8 additions & 3 deletions twine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@

__copyright__ = "Copyright 2019 Donald Stufft and individual contributors"

import email

import importlib_metadata

metadata = importlib_metadata.metadata("twine")


__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

0 comments on commit f213ede

Please sign in to comment.