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

Support the metadata directory (as per PEP-517) for build_wheel #4647

Merged
merged 8 commits into from
Sep 26, 2024

Conversation

pelson
Copy link
Contributor

@pelson pelson commented Sep 13, 2024

Summary of changes

Allow dist-info-dir to be passed to bdist_wheel.
More importantly, fixes the build_wheel PEP-517 interface to treat the given metadata as per the spec.

With this change, I was able to verify that I could:

python setup.py dist_info
touch setuptools-74.1.2.post20240913.dist-info/FOO
python setup.py bdist_wheel --dist-info-dir setuptools-74.1.2.post20240913.dist-info/

And the resulting wheel contained my desired metadata file. My personal goal is to support this behaviour in PEP-517 build backends, and to write a setuptools build backend wrapper which injects such metadata (I need to do something like setuptools-ext does). Presently, the functionality does not exist, you end up having to post-process the built wheel (hence the complexity that exists in setuptools-ext).

Honestly, despite having written many Command subclasses over many years, I am very unfamiliar with the intricacies of distutils.Command and setuptools in general, and may have implemented a solution which is not quite right due to a lack of that knowledge.

Closes #1825. Follows a prototype I did in pypa/wheel#611.

Pull Request Checklist

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks sound to me.

I don't love the complexity this adds, but I also recognize that refactoring the behavior, such as to re-order operations or not generate egg-info might be dangerous.

Comment on lines +448 to +462
# Egg info is still generated, so remove it now to avoid it getting
# copied into the wheel.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know why egg info is still generated? Is it because other commands might have generated it? What happens if the line for rmtree is removed (will the tests fail)?

While I'm okay with this approach, I'm also somewhat apprehensive, as it is perpetuating and reinforcing the expectation that egg-info is generated, even when it's not needed, making it harder in the future to correct this suboptimal approach. For example, this project also has the goal to someday obviate egg-info altogether, and to generate dist-info directly, and adding this additional handling of egg-info will likely complicate that work (though maybe not too much).

I wonder - how much do other commands from bdist_wheel depend on the generation of egg-info and could those commands get by without generating it if bdist_wheel could pass through the instruction to re-use existing dist-info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know why egg info is still generated?

Looks like install calls install_egg_info (a registered sub-command, which is automatically run), which then calls egg_info. I wasn't brave enough to try to touch this.

What happens if the line for rmtree is removed (will the tests fail)?

I've added a specific test for this. Previously the test would have passed.

this project also has the goal to someday obviate egg-info altogether

Yes, I appreciate that. IMO, this change does add an additional place where you have to think about egg-info, but I believe it is already necessary to deal with bdist_wheel wrt egg-info, and the added code-path now explicitly rejects its use - I think that ultimately makes that easier to remove egg-info in the future.

@jaraco
Copy link
Member

jaraco commented Sep 15, 2024

Also, I just noticed you're a first-time contributor. Thanks for the contribution and nice work!

@pelson pelson force-pushed the feature/pep517-metadata-directory branch from d58825b to 94a3cf1 Compare September 16, 2024 04:42
@pelson pelson force-pushed the feature/pep517-metadata-directory branch from 94a3cf1 to 04f989b Compare September 25, 2024 05:56
@pelson
Copy link
Contributor Author

pelson commented Sep 25, 2024

I noticed that this PR needed a rebase, so have just done so. Please let me know if there is anything else you need from my side.

setuptools/command/bdist_wheel.py Outdated Show resolved Hide resolved
@pelson pelson force-pushed the feature/pep517-metadata-directory branch from 04f989b to bd615ee Compare September 25, 2024 11:50
Co-authored-by: Anderson Bravalheri <[email protected]>
@abravalheri abravalheri merged commit 89d3e94 into pypa:main Sep 26, 2024
24 checks passed
@abravalheri
Copy link
Contributor

Thank you very much!

@pelson pelson deleted the feature/pep517-metadata-directory branch September 26, 2024 15:39
@pelson
Copy link
Contributor Author

pelson commented Sep 26, 2024

Thanks for your review 👍 🎉

@tacaswell
Copy link

This seems to have broken building some projects. https://github.com/yaml/pyyaml I am seeing failures like:

Processing /home/tcaswell/source/p/yaml/pyyaml
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: PyYAML
  Building wheel for PyYAML (pyproject.toml): started
  Building wheel for PyYAML (pyproject.toml): finished with status 'error'
Failed to build PyYAML

  error: subprocess-exited-with-error

  × Building wheel for PyYAML (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      usage: _in_process.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
         or: _in_process.py --help [cmd1 cmd2 ...]
         or: _in_process.py --help-commands
         or: _in_process.py cmd --help

      error: option --dist-info-dir not recognized
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for PyYAML
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (PyYAML)

with the main branch of setuptools, but going back to the commit before this was merged (3106af0 which is v75.1.0) works again.

I have not had time to debug this further and it is not all packages nor do I know if this is the only one.

@pelson
Copy link
Contributor Author

pelson commented Oct 7, 2024

Looks like that project is importing bdist_wheel from wheel (https://github.com/yaml/pyyaml/blob/69c141adcf805c5ebdc9ba519927642ee5c7f639/setup.py#L97) and setting that as the bdist_wheel command.

To be honest, that implementation looks to be rather unnecessary - I'm not sure on the backwards compat policy of setuptools, but I think this one is best addressed in pyyaml otherwise it will never be possible to add and use new features to the bdist_wheel command in setuptools.

@pelson
Copy link
Contributor Author

pelson commented Oct 7, 2024

Looks like that project is importing bdist_wheel from wheel
To be honest, that implementation looks to be rather unnecessary

@henryiii already has a proposed fix in yaml/pyyaml#823 (a few weeks before I made this MR 😂).

tacaswell added a commit to tacaswell/pyerfa that referenced this pull request Oct 10, 2024
Due to upcoming changes to
setuptools (pypa/setuptools#4647) using
bdist_wheel from wheel will fail.
tacaswell added a commit to tacaswell/tornado that referenced this pull request Oct 10, 2024
Due to upcoming changes to
setuptools (pypa/setuptools#4647) using
bdist_wheel from wheel will fail.
hynek added a commit to hynek/argon2-cffi-bindings that referenced this pull request Oct 12, 2024
Co-authored-by: Thomas A Caswell
<[email protected]>
@abravalheri
Copy link
Contributor

abravalheri commented Oct 15, 2024

OK, I hit the PyYAML problem in the integration tests when trying to cut a release. I wonder if there is any workaround for this problem. Trying out #4684.

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

Successfully merging this pull request may close these issues.

build meta wheel does not respect metadata_directory per PEP-517
4 participants