Skip to content

Commit 9351efd

Browse files
authored
Merge pull request #11291 from sbidoul/testsuite-with-installer-sbi
Use installer instead of setuptools in test suite
2 parents 0d4e9eb + 3f5436c commit 9351efd

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

tests/conftest.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
# Parser will be available from the public API in pytest >= 7.0.0:
3030
# https://github.com/pytest-dev/pytest/commit/538b5c24999e9ebb4fab43faabc8bcc28737bcdf
3131
from _pytest.config.argparsing import Parser
32-
from setuptools.wheel import Wheel
32+
from installer import install
33+
from installer.destinations import SchemeDictionaryDestination
34+
from installer.sources import WheelFile
3335

3436
from pip._internal.cli.main import main as pip_entry_point
3537
from pip._internal.locations import _USE_SYSCONFIG
@@ -364,10 +366,29 @@ def _common_wheel_editable_install(
364366
wheel_candidates = list(common_wheels.glob(f"{package}-*.whl"))
365367
assert len(wheel_candidates) == 1, wheel_candidates
366368
install_dir = tmpdir_factory.mktemp(package) / "install"
367-
Wheel(wheel_candidates[0]).install_as_egg(install_dir)
368-
(install_dir / "EGG-INFO").rename(install_dir / f"{package}.egg-info")
369-
assert compileall.compile_dir(str(install_dir), quiet=1)
370-
return install_dir
369+
lib_install_dir = install_dir / "lib"
370+
bin_install_dir = install_dir / "bin"
371+
with WheelFile.open(wheel_candidates[0]) as source:
372+
install(
373+
source,
374+
SchemeDictionaryDestination(
375+
{
376+
"purelib": os.fspath(lib_install_dir),
377+
"platlib": os.fspath(lib_install_dir),
378+
"scripts": os.fspath(bin_install_dir),
379+
},
380+
interpreter=sys.executable,
381+
script_kind="posix",
382+
),
383+
additional_metadata={},
384+
)
385+
# The scripts are not necessary for our use cases, and they would be installed with
386+
# the wrong interpreter, so remove them.
387+
# TODO consider a refactoring by adding a install_from_wheel(path) method
388+
# to the virtualenv fixture.
389+
if bin_install_dir.exists():
390+
shutil.rmtree(bin_install_dir)
391+
return lib_install_dir
371392

372393

373394
@pytest.fixture(scope="session")
@@ -389,13 +410,12 @@ def coverage_install(
389410
return _common_wheel_editable_install(tmpdir_factory, common_wheels, "coverage")
390411

391412

392-
def install_egg_link(
393-
venv: VirtualEnvironment, project_name: str, egg_info_dir: Path
413+
def install_pth_link(
414+
venv: VirtualEnvironment, project_name: str, lib_dir: Path
394415
) -> None:
395-
with open(venv.site / "easy-install.pth", "a") as fp:
396-
fp.write(str(egg_info_dir.resolve()) + "\n")
397-
with open(venv.site / (project_name + ".egg-link"), "w") as fp:
398-
fp.write(str(egg_info_dir) + "\n.")
416+
venv.site.joinpath(f"_pip_testsuite_{project_name}.pth").write_text(
417+
str(lib_dir.resolve()), encoding="utf-8"
418+
)
399419

400420

401421
@pytest.fixture(scope="session")
@@ -418,7 +438,7 @@ def virtualenv_template(
418438
venv = VirtualEnvironment(tmpdir.joinpath("venv_orig"), venv_type=venv_type)
419439

420440
# Install setuptools and pip.
421-
install_egg_link(venv, "setuptools", setuptools_install)
441+
install_pth_link(venv, "setuptools", setuptools_install)
422442
pip_editable = tmpdir_factory.mktemp("pip") / "pip"
423443
shutil.copytree(pip_src, pip_editable, symlinks=True)
424444
# noxfile.py is Python 3 only
@@ -433,7 +453,7 @@ def virtualenv_template(
433453

434454
# Install coverage and pth file for executing it in any spawned processes
435455
# in this virtual environment.
436-
install_egg_link(venv, "coverage", coverage_install)
456+
install_pth_link(venv, "coverage", coverage_install)
437457
# zz prefix ensures the file is after easy-install.pth.
438458
with open(venv.site / "zz-coverage-helper.pth", "a") as f:
439459
f.write("import coverage; coverage.process_startup()")
@@ -481,7 +501,7 @@ def virtualenv(
481501

482502
@pytest.fixture
483503
def with_wheel(virtualenv: VirtualEnvironment, wheel_install: Path) -> None:
484-
install_egg_link(virtualenv, "wheel", wheel_install)
504+
install_pth_link(virtualenv, "wheel", wheel_install)
485505

486506

487507
class ScriptFactory(Protocol):

tests/functional/test_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_local_columns_flag(simple_script: PipTestEnvironment) -> None:
109109
assert "Package" in result.stdout
110110
assert "Version" in result.stdout
111111
assert "simple (1.0)" not in result.stdout
112-
assert "simple 1.0" in result.stdout, str(result)
112+
assert "simple 1.0" in result.stdout, str(result)
113113

114114

115115
def test_multiple_exclude_and_normalization(

tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cryptography
22
freezegun
3+
installer
34
pytest
45
pytest-cov
56
pytest-rerunfailures

0 commit comments

Comments
 (0)