astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.82k stars 467 forks source link

twine issue due to recent release of importlib-metadata #1180

Closed geodab closed 4 months ago

geodab commented 4 months ago

Steps to Reproduce

It seems that a recent major release of importlib_metadata 8.0.0 removed deprecated support that twine 4.0.2 relies upon, which causes twine (and rye publish) to fail to run.

The simplest way to reproduce is to run ~/.rye/self/bin/twine --version.

The error can be fixed by either downgrading importlib_metadata to 7.2.1 or upgrading twine to 5.1.1, e.g., by running either ~/.rye/self/bin/pip install importlib_metadata==7.2.1 or ~/.rye/self/bin/pip install twine==5.1.1.

Additional details and explanation can be found at https://github.com/pypa/twine/issues/1125 and https://github.com/abichinger/semantic-release-pypi/pull/39.

Expected Result

Either:

$ ~/.rye/self/bin/twine --version
twine version 4.0.2 (importlib-metadata: 7.2.1, keyring: 25.2.1, pkginfo: 1.11.1, requests: 2.31.0, requests-toolbelt: 1.0.0,
urllib3: 2.0.7)

Or:

$ ~/.rye/self/bin/twine --version
twine version 5.1.1 (importlib-metadata: 8.0.0, keyring: 25.2.1, pkginfo: 1.10.0, requests: 2.31.0, requests-toolbelt: 1.0.0,
urllib3: 2.0.7)

Actual Result

$ ~/.rye/self/bin/twine --version
Traceback (most recent call last):
  File "/home/user/.rye/self/bin/twine", line 5, in <module>
    from twine.__main__ import main
  File "/home/user/.rye/self/lib/python3.12/site-packages/twine/__init__.py", line 43, in <module>
    __license__ = metadata["license"]
                  ~~~~~~~~^^^^^^^^^^^
  File "/home/user/.rye/self/lib/python3.12/site-packages/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'license

Version Info

$ rye --version
rye 0.35.0
commit: 0.35.0 (a1dbc56d4 2024-06-24)
platform: linux (x86_64)
self-python: cpython@3.12.2
symlink support: true
uv enabled: true

Stacktrace

No response

zanieb commented 4 months ago

Thanks for the clear report! Sounds like https://github.com/astral-sh/rye/blob/03d535d29a4f26ed68f446268fb90484b6024e90/rye/src/bootstrap.rs#L51 should be bumped?

avigailmo commented 4 months ago

Thanks for the clear report! Sounds like

https://github.com/astral-sh/rye/blob/03d535d29a4f26ed68f446268fb90484b6024e90/rye/src/bootstrap.rs#L51

should be bumped?

what the way to bump twine version in rye project?

golgor commented 4 months ago

I can confirm that the fix from @geodab works. My Github actions failed due this bug, but I was able to publish my package locally from my machine.

golgor commented 4 months ago

If anyone are having issues in their Github actions when publishing packages using Rye, I added an additional step that patches Rye with the update Twine and it works fine for me. Consider this is temporary patch though. It uses the environmental variable from setup-rye.

      - name: Set up Rye
        uses: eifinger/setup-rye@v3

      - name: Patch Rye
        run: |
          echo "Patching Rye with Twine 5.1.1"
          $RYE_HOME/self/bin/pip install twine==5.1.1