Skip to content

Commit db99b5b

Browse files
authored
Merge pull request #12545 from chrysle/fix-tests
Use `build` to create `pip` sdist for testing
2 parents ae5fff3 + 34e233e commit db99b5b

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

news/12545.trivial.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This change will use ``build`` to create the ``pip`` sdist for testing.
2+
3+
It will also remove a direct ``setup.py`` invocation to install ``pip`` in
4+
editable mode to run from tests.

noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ def test(session: nox.Session) -> None:
8989
shutil.rmtree(sdist_dir, ignore_errors=True)
9090

9191
# fmt: off
92-
session.install("setuptools")
92+
session.install("build")
9393
session.run(
94-
"python", "setup.py", "sdist", "--formats=zip", "--dist-dir", sdist_dir,
94+
"python", "-I", "-m", "build", "--sdist", "--outdir", sdist_dir,
9595
silent=True,
9696
)
9797
# fmt: on

tests/conftest.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,36 @@ def not_code_files_and_folders(path: str, names: List[str]) -> Iterable[str]:
376376
return pip_src
377377

378378

379+
@pytest.fixture(scope="session")
380+
def pip_editable_parts(
381+
pip_src: Path, tmpdir_factory: pytest.TempPathFactory
382+
) -> Tuple[Path, ...]:
383+
pip_editable = tmpdir_factory.mktemp("pip") / "pip"
384+
shutil.copytree(pip_src, pip_editable, symlinks=True)
385+
# noxfile.py is Python 3 only
386+
assert compileall.compile_dir(
387+
pip_editable,
388+
quiet=1,
389+
rx=re.compile("noxfile.py$"),
390+
)
391+
pip_self_install_path = tmpdir_factory.mktemp("pip_self_install")
392+
subprocess.check_call(
393+
[
394+
sys.executable,
395+
"-m",
396+
"pip",
397+
"install",
398+
"--target",
399+
pip_self_install_path,
400+
"-e",
401+
pip_editable,
402+
]
403+
)
404+
pth = next(pip_self_install_path.glob("*pip*.pth"))
405+
dist_info = next(pip_self_install_path.glob("*.dist-info"))
406+
return (pth, dist_info)
407+
408+
379409
def _common_wheel_editable_install(
380410
tmpdir_factory: pytest.TempPathFactory, common_wheels: Path, package: str
381411
) -> Path:
@@ -439,6 +469,7 @@ def virtualenv_template(
439469
request: pytest.FixtureRequest,
440470
tmpdir_factory: pytest.TempPathFactory,
441471
pip_src: Path,
472+
pip_editable_parts: Tuple[Path, ...],
442473
setuptools_install: Path,
443474
wheel_install: Path,
444475
coverage_install: Path,
@@ -456,17 +487,17 @@ def virtualenv_template(
456487
# Install setuptools, wheel and pip.
457488
install_pth_link(venv, "setuptools", setuptools_install)
458489
install_pth_link(venv, "wheel", wheel_install)
459-
pip_editable = tmpdir_factory.mktemp("pip") / "pip"
460-
shutil.copytree(pip_src, pip_editable, symlinks=True)
461-
# noxfile.py is Python 3 only
462-
assert compileall.compile_dir(
463-
str(pip_editable),
464-
quiet=1,
465-
rx=re.compile("noxfile.py$"),
466-
)
467-
subprocess.check_call(
468-
[os.fspath(venv.bin / "python"), "setup.py", "-q", "develop"], cwd=pip_editable
490+
491+
pth, dist_info = pip_editable_parts
492+
493+
shutil.copy(pth, venv.site)
494+
shutil.copytree(
495+
dist_info, venv.site / dist_info.name, dirs_exist_ok=True, symlinks=True
469496
)
497+
# Create placeholder ``easy-install.pth``, as several tests depend on its
498+
# existance. TODO: Ensure ``tests.lib.TestPipResult.files_updated`` correctly
499+
# detects changed files.
500+
venv.site.joinpath("easy-install.pth").touch()
470501

471502
# Install coverage and pth file for executing it in any spawned processes
472503
# in this virtual environment.

0 commit comments

Comments
 (0)