29
29
# Parser will be available from the public API in pytest >= 7.0.0:
30
30
# https://github.com/pytest-dev/pytest/commit/538b5c24999e9ebb4fab43faabc8bcc28737bcdf
31
31
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
33
35
34
36
from pip ._internal .cli .main import main as pip_entry_point
35
37
from pip ._internal .locations import _USE_SYSCONFIG
@@ -364,10 +366,29 @@ def _common_wheel_editable_install(
364
366
wheel_candidates = list (common_wheels .glob (f"{ package } -*.whl" ))
365
367
assert len (wheel_candidates ) == 1 , wheel_candidates
366
368
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
371
392
372
393
373
394
@pytest .fixture (scope = "session" )
@@ -389,13 +410,12 @@ def coverage_install(
389
410
return _common_wheel_editable_install (tmpdir_factory , common_wheels , "coverage" )
390
411
391
412
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
394
415
) -> 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
+ )
399
419
400
420
401
421
@pytest .fixture (scope = "session" )
@@ -418,7 +438,7 @@ def virtualenv_template(
418
438
venv = VirtualEnvironment (tmpdir .joinpath ("venv_orig" ), venv_type = venv_type )
419
439
420
440
# Install setuptools and pip.
421
- install_egg_link (venv , "setuptools" , setuptools_install )
441
+ install_pth_link (venv , "setuptools" , setuptools_install )
422
442
pip_editable = tmpdir_factory .mktemp ("pip" ) / "pip"
423
443
shutil .copytree (pip_src , pip_editable , symlinks = True )
424
444
# noxfile.py is Python 3 only
@@ -433,7 +453,7 @@ def virtualenv_template(
433
453
434
454
# Install coverage and pth file for executing it in any spawned processes
435
455
# in this virtual environment.
436
- install_egg_link (venv , "coverage" , coverage_install )
456
+ install_pth_link (venv , "coverage" , coverage_install )
437
457
# zz prefix ensures the file is after easy-install.pth.
438
458
with open (venv .site / "zz-coverage-helper.pth" , "a" ) as f :
439
459
f .write ("import coverage; coverage.process_startup()" )
@@ -481,7 +501,7 @@ def virtualenv(
481
501
482
502
@pytest .fixture
483
503
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 )
485
505
486
506
487
507
class ScriptFactory (Protocol ):
0 commit comments