@@ -36,10 +36,9 @@ def _ensure_virtualenv(version: str) -> Path:
3636 return path
3737
3838
39- def _parse_constraints_for_virtualenv (
40- seed_packages : list [str ],
39+ def _parse_pip_constraint_for_virtualenv (
4140 dependency_constraint_flags : Sequence [PathOrStr ],
42- ) -> dict [ str , str ] :
41+ ) -> str :
4342 """
4443 Parses the constraints file referenced by `dependency_constraint_flags` and returns a dict where
4544 the key is the package name, and the value is the constraint version.
@@ -50,8 +49,6 @@ def _parse_constraints_for_virtualenv(
5049 {macos|windows}.setup_python function.
5150 """
5251 assert len (dependency_constraint_flags ) in {0 , 2 }
53- # only seed pip if other seed packages do not appear in a constraint file
54- constraints_dict = {"pip" : "embed" }
5552 if len (dependency_constraint_flags ) == 2 :
5653 assert dependency_constraint_flags [0 ] == "-c"
5754 constraint_path = Path (dependency_constraint_flags [1 ])
@@ -67,7 +64,7 @@ def _parse_constraints_for_virtualenv(
6764 requirement = Requirement (line )
6865 package = requirement .name
6966 if (
70- package not in seed_packages
67+ package != "pip"
7168 or requirement .url is not None
7269 or requirement .marker is not None
7370 or len (requirement .extras ) != 0
@@ -77,10 +74,10 @@ def _parse_constraints_for_virtualenv(
7774 specifier = next (iter (requirement .specifier ))
7875 if specifier .operator != "==" :
7976 continue
80- constraints_dict [ package ] = specifier .version
77+ return specifier .version
8178 except InvalidRequirement :
8279 continue
83- return constraints_dict
80+ return "embed"
8481
8582
8683def virtualenv (
@@ -94,7 +91,7 @@ def virtualenv(
9491 """
9592 Create a virtual environment. If `use_uv` is True,
9693 dependency_constraint_flags are ignored since nothing is installed in the
97- venv. Otherwise, pip is installed, and setuptools + wheel if Python < 3.12 .
94+ venv. Otherwise, pip is installed.
9895 """
9996
10097 # virtualenv may fail if this is a symlink.
@@ -106,28 +103,16 @@ def virtualenv(
106103 call ("uv" , "venv" , venv_path , "--python" , python )
107104 else :
108105 virtualenv_app = _ensure_virtualenv (version )
109- allowed_seed_packages = ["pip" , "setuptools" , "wheel" ]
110- constraints = _parse_constraints_for_virtualenv (
111- allowed_seed_packages , dependency_constraint_flags
112- )
113- additional_flags : list [str ] = []
114- for package in allowed_seed_packages :
115- if package in constraints :
116- additional_flags .append (f"--{ package } ={ constraints [package ]} " )
117- else :
118- additional_flags .append (f"--no-{ package } " )
106+ pip_constraint = _parse_pip_constraint_for_virtualenv (dependency_constraint_flags )
107+ additional_flags = [f"--pip={ pip_constraint } " , "--no-setuptools" , "--no-wheel" ]
119108
120109 # Using symlinks to pre-installed seed packages is really the fastest way to get a virtual
121110 # environment. The initial cost is a bit higher but reusing is much faster.
122111 # Windows does not always allow symlinks so just disabling for now.
123112 # Requires pip>=19.3 so disabling for "embed" because this means we don't know what's the
124113 # version of pip that will end-up installed.
125114 # c.f. https://virtualenv.pypa.io/en/latest/cli_interface.html#section-seeder
126- if (
127- not _IS_WIN
128- and constraints ["pip" ] != "embed"
129- and Version (constraints ["pip" ]) >= Version ("19.3" )
130- ):
115+ if not _IS_WIN and pip_constraint != "embed" and Version (pip_constraint ) >= Version ("19.3" ):
131116 additional_flags .append ("--symlink-app-data" )
132117
133118 call (
0 commit comments