Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.16.0 regression - KeyError: 'Requires-Python' crash when running pdm add in github actions on python 3.8 #2974

Closed
1 task done
DetachHead opened this issue Jun 26, 2024 · 7 comments · Fixed by #2975
Closed
1 task done
Labels
🐛 bug Something isn't working

Comments

@DetachHead
Copy link
Contributor

DetachHead commented Jun 26, 2024

  • I have searched the issue tracker and believe that this is not a duplicate.

when running the pdm add command on python 3.8 in github actions, it crashes with the following error:

KeyError: 'Requires-Python'

i can't reproduce this locally, but it happens in github actions (windows-latest, ubuntu-latest and macos-latest) on python 3.8 but not 3.12. this bug seems to have been introduced in pdm 2.16.0

Make sure you run commands with -v flag before pasting the output.

Steps to reproduce

  1. clone https://github.com/DetachHead/test/tree/0b2d5a592e30f2bfc76d8fddedf73b0ef17d6a4b
  2. run the following commands in github actions on python 3.8:
    ./pw pdm install -v
    ./pw pdm add pytest==3.8 -v
    

Actual behavior

see github actions for the full output: https://github.com/DetachHead/test/actions/runs/9671949594/job/26683445102

 Traceback (most recent call last):
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/bin/pdm", line 8, in <module>
    sys.exit(main())
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/core.py", line 363, in main
    return core.main(args or sys.argv[1:])
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/core.py", line 281, in main
    raise cast(Exception, err).with_traceback(traceback) from None
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/core.py", line 276, in main
    self.handle(project, options)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/core.py", line 212, in handle
    command.handle(project, options)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/cli/commands/add.py", line 69, in handle
    self.do_add(
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/cli/commands/add.py", line 162, in do_add
    resolved = do_lock(
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/cli/actions.py", line 101, in do_lock
    mapping, dependencies = resolve(
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/resolver/core.py", line 39, in resolve
    result = resolver.resolve(requirements, max_rounds)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/resolvelib/resolvers.py", line 546, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/resolvelib/resolvers.py", line 426, in resolve
    name = min(unsatisfied_names, key=self._get_preference)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/resolvelib/resolvers.py", line 203, in _get_preference
    return self._p.get_preference(
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/resolver/providers.py", line 135, in get_preference
    deps = self.get_dependencies(candidate)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/resolver/providers.py", line 272, in get_dependencies
    deps, requires_python, _ = self.repository.get_dependencies(candidate)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/models/repositories.py", line 90, in get_dependencies
    requirements, requires_python, summary = getter(candidate)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/models/repositories.py", line 48, in wrapper
    result = func(self, candidate)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/models/repositories.py", line 270, in _get_dependencies_from_metadata
    deps = prepared.get_dependencies_from_metadata()
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/models/candidates.py", line 625, in get_dependencies_from_metadata
    return filter_requirements_with_extras(self.metadata.requires or [], extras)
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/pdm/models/candidates.py", line 618, in metadata
    self.candidate.requires_python = cast(str, result.metadata["Requires-Python"] or "")
  File "/home/runner/work/test/test/.pyprojectx/venvs/pdm-2ad7fbee887cffa1265ac100532e45d2-py3.8/lib/python3.8/site-packages/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'Requires-Python'

Expected behavior

no error

Environment Information

{
  "implementation_name": "cpython",
  "implementation_version": "3.8.18",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "6.5.0-1022-azure",
  "platform_system": "Linux",
  "platform_version": "#23~22.04.1-Ubuntu SMP Thu May  9 17:59:24 UTC 2024",
  "python_full_version": "3.8.18",
  "platform_python_implementation": "CPython",
  "python_version": "3.8",
  "sys_platform": "linux"
}
@DetachHead DetachHead added the 🐛 bug Something isn't working label Jun 26, 2024
@JelleZijlstra
Copy link
Contributor

This is related to the release of importlib-metadata 8.0 today: https://importlib-metadata.readthedocs.io/en/latest/history.html#deprecations-and-removals

Message.__getitem__ now raises a KeyError on missing keys

pdm's code should presumably be rewritten to catch the KeyError.

@frostming
Copy link
Collaborator

@JelleZijlstra I also noticed today in one of my CI workflows. Thanks for finding the root cause.

@JelleZijlstra
Copy link
Contributor

I am working on a fix (well, mostly working on getting pdm's test suite running).

@sydney-runkle
Copy link

@frostming
Copy link
Collaborator

As a workaround, you can limit importlib-metadata to <8.0

@ajmedeio
Copy link

ajmedeio commented Aug 29, 2024

@frostming What version of pdm is this fixed with? I'm on version 2.12.2 and I'm receiving the error reported originally.

@frostming
Copy link
Collaborator

@ajmedeio please just report errors if there are any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants