5
5
import os
6
6
import re
7
7
import shutil
8
+ import subprocess
8
9
import sys
9
10
import threading
10
11
from dataclasses import dataclass
@@ -371,6 +372,37 @@ def not_code_files_and_folders(path: str, names: List[str]) -> Iterable[str]:
371
372
return pip_src
372
373
373
374
375
+ @pytest .fixture (scope = "session" )
376
+ def pip_editable_parts (
377
+ pip_src : Path , tmpdir_factory : pytest .TempPathFactory
378
+ ) -> Tuple [Path , Path , str ]:
379
+ pip_editable = tmpdir_factory .mktemp ("pip" ) / "pip"
380
+ shutil .copytree (pip_src , pip_editable , symlinks = True )
381
+ # noxfile.py is Python 3 only
382
+ assert compileall .compile_dir (
383
+ pip_editable ,
384
+ quiet = 1 ,
385
+ rx = re .compile ("noxfile.py$" ),
386
+ )
387
+ pip_self_install_path = tmpdir_factory .mktemp ("pip_self_install" )
388
+ subprocess .check_call (
389
+ [
390
+ sys .executable ,
391
+ "-m" ,
392
+ "pip" ,
393
+ "install" ,
394
+ "--target" ,
395
+ pip_self_install_path ,
396
+ "-e" ,
397
+ pip_editable ,
398
+ ]
399
+ )
400
+ pth = next (pip_self_install_path .glob ("*pip*.pth" ))
401
+ dist_info = next (pip_self_install_path .glob ("*.dist-info" ))
402
+ dist_info_name = os .path .basename (dist_info )
403
+ return (pth , dist_info , dist_info_name )
404
+
405
+
374
406
def _common_wheel_editable_install (
375
407
tmpdir_factory : pytest .TempPathFactory , common_wheels : Path , package : str
376
408
) -> Path :
@@ -434,6 +466,7 @@ def virtualenv_template(
434
466
request : pytest .FixtureRequest ,
435
467
tmpdir_factory : pytest .TempPathFactory ,
436
468
pip_src : Path ,
469
+ pip_editable_parts : Tuple [Path , Path , str ],
437
470
setuptools_install : Path ,
438
471
wheel_install : Path ,
439
472
coverage_install : Path ,
@@ -451,16 +484,16 @@ def virtualenv_template(
451
484
# Install setuptools, wheel and pip.
452
485
install_pth_link (venv , "setuptools" , setuptools_install )
453
486
install_pth_link (venv , "wheel" , wheel_install )
454
- pip_editable = tmpdir_factory .mktemp ("pip" ) / "pip"
455
- shutil .copytree (pip_src , pip_editable , symlinks = True )
456
487
457
- # noxfile.py is Python 3 only
458
- assert compileall .compile_dir (
459
- str (pip_editable ),
460
- quiet = 1 ,
461
- rx = re .compile ("noxfile.py$" ),
462
- )
463
- install_pth_link (venv , "pip" , pip_editable / "src" )
488
+ pth , dist_info , dist_info_name = pip_editable_parts
489
+
490
+ # Preserve ``.dist-info`` directory inside ``site-packages``
491
+ dist_info_path = os .path .join (venv .site , dist_info_name )
492
+ os .mkdir (dist_info_path )
493
+
494
+ shutil .copy (pth , venv .site )
495
+ shutil .copytree (dist_info , dist_info_path , dirs_exist_ok = True , symlinks = True )
496
+ venv .site .joinpath ("easy-install.pth" ).touch ()
464
497
465
498
# Install coverage and pth file for executing it in any spawned processes
466
499
# in this virtual environment.
0 commit comments