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

add egg_info command patch to fix pip building with setuptools==75.2.0 #26

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

thrau
Copy link
Member

@thrau thrau commented Oct 21, 2024

Motivation

This PR addresses an issue that surfaced with setuptools 75.2.0, most likely this PR: pypa/setuptools#4647

When you pip install <some-source-distribution>, the following things happen (among others):

  • pip extracts the source distribution .tar.gz into some temporary folder, say /tmp/pip-req-build-bwekzpi_, this directory will contain the .egg-info that was packaged with the source distribution
  • pip creates a new temporary directory where the "modern metadata" will land (i.e., .dist-info directory)
  • pip calls prepare_metadata_for_build_wheel on the build backend (an interface from PEP 517)
  • setuptools prepare_metadata_for_build_wheel is just a wrapper around the dist_info command, which again first calls the egg_info command
  • setuptools populates the .dist-info directory from the newly created .egg-info directory (which are both in pip's temporary build context)

Here's a an example where I run pip install /path/to/test-library/dist/test_library-0.1.0.tar.gz:
pip-build-context

The issue is that this temporary .egg-info directory is completely built from scratch from the python configuration files (pyproject.toml or setup.cfg). no previously generated metadata files from the original source distribution are copied.

This PR adds a patch to egg_info to address this issue. when plux is part of the setup procedure, it detects a local pip build context and copies the plux.json file from the extracted source distribution into the temporary build context. the remaining egg_info command proceeds normally and will then create the entry_points.txt correctly through the plux.json egg-info writer plugin.

Changes

  • plux copies the plux.json file from the original source distribution into the temporary build context when building with pip

@thrau thrau marked this pull request as ready for review October 21, 2024 20:55
@thrau thrau requested a review from alexrashed October 21, 2024 20:56
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

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

Wow! What a deep dive! setuptools achievement unlocked! 🥇
Really great description, really great comments on the code, super weird stuff that's happening there, and I'm glad the solution is actually clean and somewhat simple! 🦸🏽
Btw, the solution works perfectly fine for me. I used the reproducer described in #25, and I can verify that the issue is fixed with this PR.

Comment on lines +298 to +299
# this code path is for building wheels from source distributions via pip
i = sys.argv.index("--output-dir")
Copy link
Member

Choose a reason for hiding this comment

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

🤯

Copy link
Member Author

Choose a reason for hiding this comment

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

it's not great we're depending on assumptions how pip calls setuptools, but 🤷

LOG.debug("Locating plux.json from local build context %s", meta_dir)
plux_json = os.path.join(meta_dir, "plux.json")
if os.path.exists(plux_json):
self.mkpath(self.egg_info) # this is what egg_info.run()
Copy link
Member

Choose a reason for hiding this comment

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

nit: It seems like this comment didn't get to the end: "# this is what egg_info.run()"
I think you are referring to this line in setuptools, right?
https://github.com/pypa/setuptools/blob/e5f16a2a990ff18cdef27a22b742f97444867186/setuptools/command/egg_info.py#L297

@thrau thrau merged commit d1bfa2e into main Oct 22, 2024
5 checks passed
@alexrashed alexrashed deleted the fix-setuptools branch October 22, 2024 12:57
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.

2 participants