pypa / twine

Utilities for interacting with PyPI
https://twine.readthedocs.io/
Apache License 2.0
1.61k stars 308 forks source link

KeyError: 'home-page' with importlib_metadata 8.0.0 #1125

Closed FeodorFitsner closed 4 months ago

FeodorFitsner commented 4 months ago

Is there an existing issue for this?

What keywords did you use to search existing issues?

No response

What operating system are you using?

Linux

If you selected 'Other', describe your Operating System here

No response

What version of Python are you running?

Python 3.10.13

How did you install twine? Did you use your operating system's package manager or pip or something else?

pip install twine

What version of twine do you have installed (include the complete output)

5.1.0

Which package repository are you using?

pypi.org

Please describe the issue that you are experiencing

importlib_metadata has just released 8.0.0 and CI jobs calling twine upload started failing with the following error:

Traceback (most recent call last):
  File "/home/appveyor/venv3.10.13/bin/twine", line 5, in <module>
    from twine.__main__ import main
  File "/home/appveyor/venv3.10.13/lib/python3.10/site-packages/twine/__init__.py", line 40, in <module>
    __uri__ = metadata["home-page"]
  File "/home/appveyor/venv3.10.13/lib/python3.10/site-packages/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'home-page'

Please list the steps required to reproduce this behaviour

pip install --upgrade setuptools wheel twine poetry tomlkit virtualenv

Anything else you'd like to mention?

No response

gesslerpd commented 4 months ago

See #1124

jykr commented 4 months ago

Would be helpful to have twine 5.1.0 yanked from pypi to prevent CI's relying on twine being broken, until bug gets fixed

henryiii commented 4 months ago

Why does 5.0 work? Was the bug added to 5.1 just before importlib-metadata 8 was released? I was about to reply that it didn't have anything to do with 5.1 but checked it and it seems 5.0 works with importlib-metadata 8 (I assume).

I don't see the __init__.py file even being touched: https://github.com/pypa/twine/compare/5.0.0...5.1.0. But the environment clearly does have importlib-metadata 8.0 and it works for me.

henryiii commented 4 months ago

Ahh, I see it; it's due to the modernization of the build system, and the new build system doesn't set home-page (it's triggering on twine itself!), but it happened to pass due to importlib-metadata returning None here instead of erroring before 8.0.

So yes, yanking 5.1 while waiting for 5.1.1 would be a temporary fix. You can also set !=5.1.0 in your CI's, like pipx run 'twine!=5.1.0'.

jaraco commented 4 months ago

This issue isn't due to a release of twine but due to a release of importlib-metadata 8. See #977 where the deprecation warning was detected and reported.

arcivanov commented 4 months ago

Just bumped into this as well!

Clivern commented 4 months ago

Same here!

arcivanov commented 4 months ago

Please yank the offending version - this is breaking all sorts of builds due to twine check crashing.

teej commented 4 months ago

Just ran into this. For those looking for a quick fix, I changed my twine dependency to twine!=5.1.0, rebuilt my dev venv, and that worked for me.

Thanks @henryiii

tipabu commented 4 months ago

This issue isn't due to a release of twine but due to a release of importlib-metadata 8.

I have to push back on this -- from a fresh py312 venv:

$ pip install 'twine<5.1'
Collecting twine<5.1
  Using cached twine-5.0.0-py3-none-any.whl.metadata (3.3 kB)
...
Successfully installed Pygments-2.18.0 SecretStorage-3.3.3 certifi-2024.6.2 cffi-1.16.0 charset-normalizer-3.3.2 cryptography-42.0.8 docutils-0.21.2 idna-3.7 importlib-metadata-8.0.0 jaraco.classes-3.4.0 jaraco.context-5.3.0 jaraco.functools-4.0.1 jeepney-0.8.0 keyring-25.2.1 markdown-it-py-3.0.0 mdurl-0.1.2 more-itertools-10.3.0 nh3-0.2.17 pkginfo-1.11.1 pycparser-2.22 readme-renderer-43.0 requests-2.32.3 requests-toolbelt-1.0.0 rfc3986-2.0.0 rich-13.7.1 twine-5.0.0 urllib3-2.2.2 zipp-3.19.2
$ twine -h
usage: twine [-h] [--version] [--no-color] {check,upload,register}
...

i.e. even with importlib-metadata-8.0.0, twine would still work, because the 5.0.0 package included the home-page metadata twine itself is looking for. But if I upgrade it:

$ pip install -U 'twine'
Requirement already satisfied: twine in ./venv/lib/python3.12/site-packages (5.0.0)
Collecting twine
  Using cached twine-5.1.0-py3-none-any.whl.metadata (3.4 kB)
Requirement already satisfied: pkginfo>=1.8.1 in ./venv/lib/python3.12/site-packages (from twine) (1.11.1)
Requirement already satisfied: readme-renderer>=35.0 in ./venv/lib/python3.12/site-packages (from twine) (43.0)
Requirement already satisfied: requests>=2.20 in ./venv/lib/python3.12/site-packages (from twine) (2.32.3)
Requirement already satisfied: requests-toolbelt!=0.9.0,>=0.8.0 in ./venv/lib/python3.12/site-packages (from twine) (1.0.0)
Requirement already satisfied: urllib3>=1.26.0 in ./venv/lib/python3.12/site-packages (from twine) (2.2.2)
Requirement already satisfied: importlib-metadata>=3.6 in ./venv/lib/python3.12/site-packages (from twine) (8.0.0)
Requirement already satisfied: keyring>=15.1 in ./venv/lib/python3.12/site-packages (from twine) (25.2.1)
Requirement already satisfied: rfc3986>=1.4.0 in ./venv/lib/python3.12/site-packages (from twine) (2.0.0)
Requirement already satisfied: rich>=12.0.0 in ./venv/lib/python3.12/site-packages (from twine) (13.7.1)
Requirement already satisfied: zipp>=0.5 in ./venv/lib/python3.12/site-packages (from importlib-metadata>=3.6->twine) (3.19.2)
Requirement already satisfied: jaraco.classes in ./venv/lib/python3.12/site-packages (from keyring>=15.1->twine) (3.4.0)
Requirement already satisfied: jaraco.functools in ./venv/lib/python3.12/site-packages (from keyring>=15.1->twine) (4.0.1)
Requirement already satisfied: jaraco.context in ./venv/lib/python3.12/site-packages (from keyring>=15.1->twine) (5.3.0)
Requirement already satisfied: SecretStorage>=3.2 in ./venv/lib/python3.12/site-packages (from keyring>=15.1->twine) (3.3.3)
Requirement already satisfied: jeepney>=0.4.2 in ./venv/lib/python3.12/site-packages (from keyring>=15.1->twine) (0.8.0)
Requirement already satisfied: nh3>=0.2.14 in ./venv/lib/python3.12/site-packages (from readme-renderer>=35.0->twine) (0.2.17)
Requirement already satisfied: docutils>=0.13.1 in ./venv/lib/python3.12/site-packages (from readme-renderer>=35.0->twine) (0.21.2)
Requirement already satisfied: Pygments>=2.5.1 in ./venv/lib/python3.12/site-packages (from readme-renderer>=35.0->twine) (2.18.0)
Requirement already satisfied: charset-normalizer<4,>=2 in ./venv/lib/python3.12/site-packages (from requests>=2.20->twine) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in ./venv/lib/python3.12/site-packages (from requests>=2.20->twine) (3.7)
Requirement already satisfied: certifi>=2017.4.17 in ./venv/lib/python3.12/site-packages (from requests>=2.20->twine) (2024.6.2)
Requirement already satisfied: markdown-it-py>=2.2.0 in ./venv/lib/python3.12/site-packages (from rich>=12.0.0->twine) (3.0.0)
Requirement already satisfied: mdurl~=0.1 in ./venv/lib/python3.12/site-packages (from markdown-it-py>=2.2.0->rich>=12.0.0->twine) (0.1.2)
Requirement already satisfied: cryptography>=2.0 in ./venv/lib/python3.12/site-packages (from SecretStorage>=3.2->keyring>=15.1->twine) (42.0.8)
Requirement already satisfied: more-itertools in ./venv/lib/python3.12/site-packages (from jaraco.classes->keyring>=15.1->twine) (10.3.0)
Requirement already satisfied: cffi>=1.12 in ./venv/lib/python3.12/site-packages (from cryptography>=2.0->SecretStorage>=3.2->keyring>=15.1->twine) (1.16.0)
Requirement already satisfied: pycparser in ./venv/lib/python3.12/site-packages (from cffi>=1.12->cryptography>=2.0->SecretStorage>=3.2->keyring>=15.1->twine) (2.22)
Using cached twine-5.1.0-py3-none-any.whl (38 kB)
Installing collected packages: twine
  Attempting uninstall: twine
    Found existing installation: twine 5.0.0
    Uninstalling twine-5.0.0:
      Successfully uninstalled twine-5.0.0
Successfully installed twine-5.1.0
$ twine -h
Traceback (most recent call last):
  File ".../venv/bin/twine", line 5, in <module>
    from twine.__main__ import main
  File ".../venv/lib/python3.12/site-packages/twine/__init__.py", line 40, in <module>
    __uri__ = metadata["home-page"]
              ~~~~~~~~^^^^^^^^^^^^^
  File ".../venv/lib/python3.12/site-packages/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'home-page'
henryiii commented 4 months ago

5.1.0 stated relying on the fact that metadata["home-page"] was returning None and producing a (hidden) deprecation warning. That's why installing 5.0.0 fixes it or installing importlib-metadata 7 fixes it.

jaraco commented 4 months ago

Oh, that's good to know that only one version of twine is implicated. I've yanked it. That should stop the bleeding until the issue can be fixed.

arcivanov commented 4 months ago

Thank you, yanking solved it.

puittenbroek commented 4 months ago
Sorry, this is with `twin==4.0.2` and `importlib_metadata==8.0.0`
marcinmilewski1 commented 4 months ago

I can confirm this issue is with twine==4.0.2 too. It can be fixed by forcing importlib-metadata==7.2.1 installation.

jaraco commented 4 months ago

Twine 5.1.1 was just released. I'm assuming this issue is addressed, but please don't hesitate to report if the issues aren't addressed.