Skip to content

Commit f213ede

Browse files
authored
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.
1 parent 6fbf880 commit f213ede

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

changelog/1115.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Resolve DeprecationWarnings when extracting ``twine`` metadata.

twine/__init__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,20 @@
3030

3131
__copyright__ = "Copyright 2019 Donald Stufft and individual contributors"
3232

33+
import email
34+
3335
import importlib_metadata
3436

3537
metadata = importlib_metadata.metadata("twine")
3638

3739

3840
__title__ = metadata["name"]
3941
__summary__ = metadata["summary"]
40-
__uri__ = metadata["home-page"]
42+
__uri__ = next(
43+
entry.split(", ")[1]
44+
for entry in metadata.get_all("Project-URL", ())
45+
if entry.startswith("Homepage")
46+
)
4147
__version__ = metadata["version"]
42-
__author__ = metadata["author"]
43-
__email__ = metadata["author-email"]
48+
__author__, __email__ = email.utils.parseaddr(metadata["author-email"])
4449
__license__ = None

0 commit comments

Comments
 (0)