Skip to content

Commit a2ec40d

Browse files
authored
Merge pull request #13473 from notatallshaw/use-flit-to-build
Use `flit-core` to build pip distributions
2 parents c46141c + d652eb9 commit a2ec40d

File tree

9 files changed

+68
-95
lines changed

9 files changed

+68
-95
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
- run: pip install nox
8383
- run: nox -s prepare-release -- 99.9
8484
- run: nox -s build-release -- 99.9
85-
- run: pipx run check-manifest
85+
- run: pipx run check-sdist
8686

8787
vendoring:
8888
name: vendoring

MANIFEST.in

Lines changed: 0 additions & 34 deletions
This file was deleted.

build-project/build-requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
build
2-
setuptools
2+
flit-core

build-project/build-requirements.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ build==1.3.0 \
88
--hash=sha256:698edd0ea270bde950f53aed21f3a0135672206f3911e0176261a31e0e07b397 \
99
--hash=sha256:7145f0b5061ba90a1500d60bd1b13ca0a8a4cebdd0cc16ed8adf1c0e739f43b4
1010
# via -r build-requirements.in
11-
packaging==24.2 \
12-
--hash=sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759 \
13-
--hash=sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f
11+
flit-core==3.12.0 \
12+
--hash=sha256:18f63100d6f94385c6ed57a72073443e1a71a4acb4339491615d0f16d6ff01b2 \
13+
--hash=sha256:e7a0304069ea895172e3c7bb703292e992c5d1555dd1233ab7b5621b5b69e62c
14+
# via -r build-requirements.in
15+
packaging==25.0 \
16+
--hash=sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484 \
17+
--hash=sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f
1418
# via build
1519
pyproject-hooks==1.2.0 \
1620
--hash=sha256:1e859bd5c40fae9448642dd871adf459e5e2084186e8d2c2a79a824c970da1f8 \
1721
--hash=sha256:9e5c6bfa8dcc30091c74b0cf803c81fdd29d94f01992a7707bc97babb1141913
1822
# via build
19-
20-
# The following packages are considered to be unsafe in a requirements file:
21-
setuptools==80.9.0 \
22-
--hash=sha256:062d34222ad13e0cc312a4c02d73f059e86a4acbfbdea8f8f76b28c99f306922 \
23-
--hash=sha256:f36b47402ecde768dbfafc46e8e4207b4360c654f1f3bb84475f0a28628fb19c
24-
# via -r build-requirements.in

docs/html/development/architecture/anatomy.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ The ``README``, license, ``pyproject.toml``, and so on are in the top level.
1818

1919
* ``AUTHORS.txt``
2020
* ``LICENSE.txt``
21-
* ``MANIFEST.in``
2221
* ``NEWS.rst``
2322
* ``pyproject.toml``
2423
* ``README.rst``

news/13743.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Building pip itself from source now uses flit-core instead of setuptools.
2+
This does not affect how pip installs or builds packages you use.

pyproject.toml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[project]
22
dynamic = ["version"]
3-
43
name = "pip"
54
description = "The PyPA recommended tool for installing Python packages."
65
readme = "README.rst"
@@ -46,12 +45,13 @@ Source = "https://github.com/pypa/pip"
4645
Changelog = "https://pip.pypa.io/en/stable/news/"
4746

4847
[build-system]
49-
requires = ["setuptools>=77"]
50-
build-backend = "setuptools.build_meta"
48+
requires = ["flit-core >=3.11,<4"]
49+
build-backend = "flit_core.buildapi"
5150

5251
[dependency-groups]
5352
test = [
5453
"cryptography",
54+
"flit-core >= 3.11, < 4",
5555
"freezegun",
5656
"installer",
5757
# pytest-subket requires 7.0+
@@ -73,6 +73,7 @@ test = [
7373
]
7474

7575
test-common-wheels = [
76+
"flit-core >= 3.11, < 4",
7677
# We pin setuptools<80 because our test suite currently
7778
# depends on setup.py develop to generate egg-link files.
7879
"setuptools >= 40.8.0, != 60.6.0, <80",
@@ -82,28 +83,24 @@ test-common-wheels = [
8283
"pytest-subket >= 0.8.1",
8384
]
8485

85-
[tool.setuptools]
86-
package-dir = {"" = "src"}
87-
include-package-data = false
88-
89-
[tool.setuptools.dynamic]
90-
version = {attr = "pip.__version__"}
91-
92-
[tool.setuptools.packages.find]
93-
where = ["src"]
94-
exclude = ["contrib", "docs", "tests*", "tasks"]
95-
96-
[tool.setuptools.package-data]
97-
"pip" = ["py.typed"]
98-
"pip._vendor" = ["vendor.txt"]
99-
"pip._vendor.certifi" = ["*.pem"]
100-
"pip._vendor.distlib" = [
101-
"t32.exe",
102-
"t64.exe",
103-
"t64-arm.exe",
104-
"w32.exe",
105-
"w64.exe",
106-
"w64-arm.exe",
86+
[tool.flit.sdist]
87+
include = [
88+
"NEWS.rst",
89+
"SECURITY.md",
90+
"build-project/.python-version",
91+
"build-project/build-project.py",
92+
"build-project/build-requirements.in",
93+
"build-project/build-requirements.txt",
94+
"docs/requirements.txt",
95+
"docs/**/*.css",
96+
"docs/**/*.dot",
97+
"docs/**/*.md",
98+
"docs/**/*.png",
99+
"docs/**/*.py",
100+
"docs/**/*.rst",
101+
]
102+
exclude = [
103+
"src/pip/_vendor/**/*.pyi",
107104
]
108105

109106
######################################################################################
@@ -362,3 +359,15 @@ exclude_also = [
362359
# This excludes typing-specific code, which will be validated by mypy anyway.
363360
"if TYPE_CHECKING",
364361
]
362+
363+
[tool.check-sdist]
364+
git-only = [
365+
"tests/**",
366+
"tools/**",
367+
"news/.gitignore",
368+
".gitattributes",
369+
".gitignore",
370+
".git-blame-ignore-revs",
371+
".mailmap",
372+
".readthedocs-custom-redirects.yml"
373+
]

tests/functional/test_freeze.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,38 +99,33 @@ def test_freeze_with_pip(script: PipTestEnvironment) -> None:
9999

100100
def test_freeze_with_setuptools(script: PipTestEnvironment) -> None:
101101
"""
102-
Test that pip shows setuptools only when --all is used
103-
or _should_suppress_build_backends() returns false
102+
Test that pip shows setuptools only when --all is used on Python < 3.12,
103+
otherwise it should be shown in default freeze output.
104104
"""
105105

106106
result = script.pip("freeze", "--all")
107107
assert "setuptools==" in result.stdout
108108

109-
(script.site_packages_path / "mock.pth").write_text("import mock\n")
110-
111-
(script.site_packages_path / "mock.py").write_text(
112-
textwrap.dedent(
113-
"""\
114-
import pip._internal.commands.freeze as freeze
115-
freeze._should_suppress_build_backends = lambda: False
116-
"""
117-
)
118-
)
119-
109+
# Test the default behavior (without --all)
120110
result = script.pip("freeze")
121-
assert "setuptools==" in result.stdout
122111

123-
(script.site_packages_path / "mock.py").write_text(
124-
textwrap.dedent(
125-
"""\
126-
import pip._internal.commands.freeze as freeze
127-
freeze._should_suppress_build_backends = lambda: True
128-
"""
112+
should_suppress = sys.version_info < (3, 12)
113+
if should_suppress:
114+
# setuptools should be hidden in default freeze output
115+
assert "setuptools==" not in result.stdout, (
116+
f"setuptools should be suppressed in Python {sys.version_info[:2]} "
117+
f"but was found in freeze output: {result.stdout}"
118+
)
119+
else:
120+
# setuptools should be shown in default freeze output
121+
assert "setuptools==" in result.stdout, (
122+
f"setuptools should be shown in Python {sys.version_info[:2]} "
123+
f"but was not found in freeze output: {result.stdout}"
129124
)
130-
)
131125

132-
result = script.pip("freeze")
133-
assert "setuptools==" not in result.stdout
126+
# --all should always show setuptools regardless of version
127+
result_all = script.pip("freeze", "--all")
128+
assert "setuptools==" in result_all.stdout
134129

135130

136131
def test_exclude_and_normalization(script: PipTestEnvironment, tmpdir: Path) -> None:

tests/functional/test_self_update.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Check that pip can update itself correctly
22

3+
from pathlib import Path
34
from typing import Any
45

56

6-
def test_self_update_editable(script: Any, pip_src: Any) -> None:
7+
def test_self_update_editable(script: Any, pip_src: Any, common_wheels: Path) -> None:
78
# Test that if we have an environment with pip installed in non-editable
89
# mode, that pip can safely update itself to an editable install.
910
# See https://github.com/pypa/pip/issues/12666 for details.
1011

12+
# Install flit-core (build backend) since we use --no-build-isolation
13+
script.pip("install", "--no-index", "-f", common_wheels, "flit-core")
14+
1115
# Step 1. Install pip as non-editable. This is expected to succeed as
1216
# the existing pip in the environment is installed in editable mode, so
1317
# it only places a .pth file in the environment.

0 commit comments

Comments
 (0)