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 <andersonbravalheri+github@gmail.com>
Co-authored-by: Anderson Bravalheri <andersonbravalheri+github@gmail.com>
@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 👍 🎉

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
3 participants