Skip to content

Commit 5e8b086

Browse files
authored
Force build to provision its own pip in nox test session (#12848)
Modern versions of build use the pip from the environment it's installed in, taking advantage of --python to avoid needing to provision pip in the temporary build environment. This is a neat optimization, but it breaks when a broken pip is installed from a previous test run. When this happens, you have to clear out the old Nox session environment to get build functioning again. This is annoying and clearly works against the goal of run_with_protected_pip() which is meant to prevent such issues. We can force build to provision its own pip by simply uninstalling pip before invoking the sdist build.
1 parent e99327f commit 5e8b086

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

news/72167f18-bd68-41e1-8404-4d23e6b2652f.trivial.rst

Whitespace-only changes.

noxfile.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ def test(session: nox.Session) -> None:
8888
if os.path.exists(sdist_dir):
8989
shutil.rmtree(sdist_dir, ignore_errors=True)
9090

91+
run_with_protected_pip(session, "install", "build")
92+
# build uses the pip present in the outer environment (aka the nox environment)
93+
# as an optimization. This will crash if the last test run installed a broken
94+
# pip, so uninstall pip to force build to provision a known good version of pip.
95+
run_with_protected_pip(session, "uninstall", "pip", "-y")
9196
# fmt: off
92-
session.install("build")
9397
session.run(
9498
"python", "-I", "-m", "build", "--sdist", "--outdir", sdist_dir,
9599
silent=True,

0 commit comments

Comments
 (0)