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

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

Closed
novas0x2a opened this issue Jul 18, 2024 · 2 comments · Fixed by #4493
Closed

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

novas0x2a opened this issue Jul 18, 2024 · 2 comments · Fixed by #4493
Assignees
Labels

Comments

@novas0x2a
Copy link

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?

@novas0x2a novas0x2a added bug Needs Triage Issues that need to be evaluated for severity and status. labels Jul 18, 2024
@jaraco
Copy link
Member

jaraco commented Jul 18, 2024

Thanks for the report. Yes, as part of the simplified vendoring process in Setuptools 71, the vendored packages were also updated, including the backward-incompatible behavior of importlib_metadata 8. It wasn't anticipated this change would have an effect on users, but it seems to have caught an issue unique to your environment where the relevant package does not have a Name metadata field.

I have a decent understanding of what's going on and I'll take a look in earnest tomorrow.

@jaraco jaraco self-assigned this Jul 18, 2024
@jaraco jaraco removed the Needs Triage Issues that need to be evaluated for severity and status. label Jul 18, 2024
@jaraco
Copy link
Member

jaraco commented Jul 19, 2024

It looks like maybe abravalheri added that change in #3823. If I revert that change, the tests still pass, and I'm not very confident in what that code is aiming to accomplish.

It looks like pd is a importlib.metadata.PackageMetadata | None and here is the only place it's set. Since PackageMetadata doesn't have a .key property, I'm thinking that check should be for just pd.metadata.get('Name', None).

But wait! pd is never used and it's immediately cleared after altering its properties. I'm now beginning to think that anything having to do with distribution._patched_dist should just be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants