Skip to content

Commit

Permalink
Force build to provision its own pip in nox test session (#12848)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ichard26 authored Jul 15, 2024
1 parent e99327f commit 5e8b086
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Empty file.
6 changes: 5 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ def test(session: nox.Session) -> None:
if os.path.exists(sdist_dir):
shutil.rmtree(sdist_dir, ignore_errors=True)

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

0 comments on commit 5e8b086

Please sign in to comment.