Skip to content

Use flit-core to build pip distributions #13473

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

notatallshaw
Copy link
Member

@notatallshaw notatallshaw commented Jul 9, 2025

Fixes #13472

This is a very quick attempt to make a PR to switch to flit-core as pip's build back end, and if there is any missing features pip requires.

There is no plan to merge, at least until, or if, there is agreement among the maintainers.

@notatallshaw notatallshaw changed the title [PoC] Use flit to build pip distributions [PoC] Use flit-core to build pip distributions Jul 9, 2025
@notatallshaw
Copy link
Member Author

test_freeze.py::test_freeze_with_setuptool fails on Python 3.9 only, otherwise everything appears to be passing.

@pfmoore
Copy link
Member

pfmoore commented Jul 9, 2025

+1 from me

@pfmoore
Copy link
Member

pfmoore commented Jul 9, 2025

A couple of minor points here.

  1. Flit includes license files in the wheel. This isn't a bad thing, of course, and we should be doing it even with setuptools via Switch license metadata to the PEP 639 format #13335 and Why licenses of vendored libraries are not distributed in wheels? #8330. My tests seem to not have the licenses under setuptools, but I'm not going to bother digging to work out why, as it's not relevant.
  2. Flit includes everything under the src directory, regardless of what .gitignore says. That means it's important to have a clean checkout - I was getting weird .pyd files in my build, and it took me a long time to work out why they were there1. It doesn't include __pycache__, though. Unless I've missed something, flit's docs on what gets included in the wheel aren't that great - I've created Document exactly what goes into a wheel flit#747 to see if that can be fixed.

Footnotes

  1. Mostly because I didn't spot the .py[cod] pattern in .gitignore 🙁

@ichard26
Copy link
Member

ichard26 commented Jul 9, 2025

+1 assuming that downstream is OK with it.

This also reduces the time it takes to build pip from source (1.6s to 1s, locally with flit/setuptools cached via --find-links) which is a nice developer UX improvement.

Co-authored-by: Richard Si <[email protected]>
@pradyunsg
Copy link
Member

That means it's important to have a clean checkout

FWIW, the next session for building release artifacts does so in a clean temporary working checkout:

pip/noxfile.py

Line 345 in 4bb2bcb

with release.isolated_temporary_checkout(session, version) as build_dir:

@notatallshaw notatallshaw changed the title [PoC] Use flit-core to build pip distributions Use flit-core to build pip distributions Jul 10, 2025
@notatallshaw notatallshaw marked this pull request as ready for review July 10, 2025 04:17
@notatallshaw
Copy link
Member Author

Somehow I've got all tests passing without too much difficulty and there is general positive feedback, so I am removing PoC and draft status from PR.

I do think this PR should be open for at least a couple of weeks to get maintainer feedback or anyone else watching pip closely.

@sbidoul
Copy link
Member

sbidoul commented Jul 10, 2025

I compared 1 the generated wheel in this PR and main, and the difference that stands out is the various LICENCE files that are added in pip/_vendor and subdirectories. There is also pip/_vendor/README.rst that probably should not be in the wheel.

Otherwise this looks good and I'm ok with the change to flit-core.

Footnotes

  1. uvx pip-wheel-diff git+https://github.com/pypa/pip@main git+https://github.com/pypa/pip@refs/pull/13473/head

@SpecLad
Copy link
Contributor

SpecLad commented Jul 10, 2025

I compared the generated wheel in this PR and main, and the difference that stands out is the various LICENCE files that are added in pip/_vendor and subdirectories.

That's actually a flit bug (in my opinion, anyway...); I noticed it myself yesterday: pypa/flit#749.

@notatallshaw
Copy link
Member Author

I should mention that updating test_freeze.py::test_freeze_with_setuptool required taking a different approach to run the test. I don't have a strong understanding of the mechanics of editable installs but I think that the test imported pip via a .pth file, this was throwing an import error as I think flit installs editables via the PEP 660 mechanism?

So if someone is dependent on importing pip in .pth based editable installs it may no longer work?

Copy link
Member

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

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

So if someone is dependent on importing pip in .pth based editable installs it may no longer work?

It seems like flit-core uses an .pth file for its build_editable implementation anyway, but honestly, I'm not worried about breaking users that are depending specifically on how our build backend implements editable installs. I'm not entirely sure why the freeze test needed to be updated, but I'm going to guess that the order in which the .pth files are executed changed, causing the mock file to execute before the pip source got added to sys.path.

It's mildly annoying that flit decided that the duplicate license files are not a bug (pypa/flit#749), but I'm not going to block this change on it.

I asked the flit team whether they had any objections to us switching over to their backend. No real issues: pypa/flit#751.

Anyway, with my RM hat on, I'm only going to consider merging this if every other maintainer is on board. And even then, I feel that would be possibly premature. We have ~2.5 weeks before pip 25.2 which is not a lot of time.

@notatallshaw
Copy link
Member Author

Anyway, with my RM hat on, I'm only going to consider merging this if every other maintainer is on board. And even then, I feel that would be possibly premature. We have ~2.5 weeks before pip 25.2 which is not a lot of time.

I also think that if this is merged it would be better at the beginning of a release cycle, not at the end.

@pfmoore
Copy link
Member

pfmoore commented Jul 14, 2025

+1 from me on merging, but I agree let’s do it at the start of a release cycle.

@ichard26 ichard26 added this to the 25.3 milestone Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch from setuptools to flit-core for pip's build backend
6 participants