Skip to content

[BUG] upgraded vendor copy of importlib_metadata breaks packages #4489

@novas0x2a

Description

@novas0x2a

setuptools version

setuptools==71.0.0 setuptools==71.0.1 setuptools==71.0.2

Python version

3.9

OS

ubuntu 22.04 (linux)

Additional environment information

No response

Description

We have sdists that are not yet fully converted to pep517; however, they would build correctly with pip wheel --use-pep517. Unfortunately, importlib_metadata 8.0.0 landed this change (python/importlib_metadata#371) which converts a None return into a KeyError.

Expected behavior

I expected an existing package to keep working.

How to Reproduce

This is with a specific internal package with code I can't share, but I can answer questions about it.

Output

(.venv-3.9) $ pip freeze --all
pip==24.1.2
setuptools==71.0.2
(.venv-3.9) $ pip wheel .
Processing $HOME/$PACKAGENAME-4.0.51
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [38 lines of output]
      running egg_info
      Traceback (most recent call last):
        File "$HOME/$PACKAGENAME-4.0.51/.venv-3.9/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "$HOME/$PACKAGENAME-4.0.51/.venv-3.9/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "$HOME/$PACKAGENAME-4.0.51/.venv-3.9/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 327, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 297, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 497, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 313, in run_setup
          exec(code, locals())
        File "<string>", line 45, in <module>
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 106, in setup
          return distutils.core.setup(**attrs)
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 184, in setup
          return run_commands(dist)
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 200, in run_commands
          dist.run_commands()
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 970, in run_commands
          self.run_command(cmd)
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 974, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.ensure_finalized()
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 111, in ensure_finalized
          self.finalize_options()
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 258, in finalize_options
          key = getattr(pd, "key", None) or getattr(pd, "name", None)
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 460, in name
          return self.metadata['Name']
        File "/tmp/pip-build-env-95l81nvf/overlay/lib/python3.9/site-packages/setuptools/_vendor/importlib_metadata/_adapters.py", line 54, in __getitem__
          raise KeyError(item)
      KeyError: 'Name'
      [end of output]

It looks like the egg_info command had a workaround for the scenario this package is triggering (

key = getattr(pd, "key", None) or getattr(pd, "name", None)
) and no longer does. If I add a try/except for KeyError around this code, the wheel builds as before.

I assume this is at least partially related to this internal package, but I don't actually know what I'd need to change to fix it. I'm also not sure if this scenario is supposed to fail now, maybe there's some problem that we didn't notice with the old way?

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions