@@ -540,6 +540,7 @@ def _ensure_virtualenv() -> Path:
540
540
541
541
542
542
def _parse_constraints_for_virtualenv (
543
+ seed_packages : list [str ],
543
544
dependency_constraint_flags : Sequence [PathOrStr ],
544
545
) -> dict [str , str ]:
545
546
"""
@@ -552,8 +553,8 @@ def _parse_constraints_for_virtualenv(
552
553
{macos|windows}.setup_python function.
553
554
"""
554
555
assert len (dependency_constraint_flags ) in {0 , 2 }
555
- packages = [ " pip" , "setuptools" , "wheel" ]
556
- constraints_dict = {package : "embed" for package in packages }
556
+ # only seed pip if other seed packages do not appear in a constraint file
557
+ constraints_dict = {"pip" : "embed" }
557
558
if len (dependency_constraint_flags ) == 2 :
558
559
assert dependency_constraint_flags [0 ] == "-c"
559
560
constraint_path = Path (dependency_constraint_flags [1 ])
@@ -569,7 +570,7 @@ def _parse_constraints_for_virtualenv(
569
570
requirement = Requirement (line )
570
571
package = requirement .name
571
572
if (
572
- package not in packages
573
+ package not in seed_packages
573
574
or requirement .url is not None
574
575
or requirement .marker is not None
575
576
or len (requirement .extras ) != 0
@@ -590,8 +591,16 @@ def virtualenv(
590
591
) -> dict [str , str ]:
591
592
assert python .exists ()
592
593
virtualenv_app = _ensure_virtualenv ()
593
- constraints = _parse_constraints_for_virtualenv (dependency_constraint_flags )
594
- additional_flags = [f"--{ package } ={ version } " for package , version in constraints .items ()]
594
+ allowed_seed_packages = ["pip" , "setuptools" , "wheel" ]
595
+ constraints = _parse_constraints_for_virtualenv (
596
+ allowed_seed_packages , dependency_constraint_flags
597
+ )
598
+ additional_flags : list [str ] = []
599
+ for package in allowed_seed_packages :
600
+ if package in constraints :
601
+ additional_flags .append (f"--{ package } ={ constraints [package ]} " )
602
+ else :
603
+ additional_flags .append (f"--no-{ package } " )
595
604
596
605
# Using symlinks to pre-installed seed packages is really the fastest way to get a virtual
597
606
# environment. The initial cost is a bit higher but reusing is much faster.
0 commit comments