@@ -137,7 +137,7 @@ def __init__(self, executable: str, shared: str, overlay: str) -> None:
137137 for path in (overlay , shared ):
138138 paths = get_sys_config_paths (executable , vars = {"base" : path , "platbase" : path }, kind = "prefix" )
139139 self .bin_dirs .append (paths ["scripts" ])
140- self .lib_dirs .extend ([ paths ["platlib" ], paths ["purelib" ]] )
140+ self .lib_dirs .extend ({ paths ["platlib" ], paths ["purelib" ]} )
141141 self .site_dir = os .path .join (overlay , "site" )
142142 if os .path .isdir (self .site_dir ):
143143 # Clear existing site dir as .pyc may be cached.
@@ -181,7 +181,7 @@ class EnvBuilder:
181181 if TYPE_CHECKING :
182182 _hook : BuildBackendHookCaller
183183 _requires : list [str ]
184- _prefix : _Prefix
184+ _prefix : _Prefix | None
185185
186186 def get_shared_env (self , key : int ) -> str :
187187 if key in self ._shared_envs :
@@ -234,21 +234,24 @@ def init_build_system(self, build_system: dict[str, Any]) -> None:
234234 python_executable = self .executable ,
235235 )
236236 self ._requires = build_system ["requires" ]
237- self ._prefix = _Prefix (
238- self .executable ,
239- # Build backends with the same requires list share the cached base env.
240- shared = self .get_shared_env (hash (frozenset (self ._requires ))),
241- # Overlay envs are unique for each source to be built.
242- overlay = self .get_overlay_env (os .path .normcase (self .src_dir ).rstrip ("\\ /" )),
237+ self ._prefix = (
238+ _Prefix (
239+ self .executable ,
240+ # Build backends with the same requires list share the cached base env.
241+ shared = self .get_shared_env (hash (frozenset (self ._requires ))),
242+ # Overlay envs are unique for each source to be built.
243+ overlay = self .get_overlay_env (os .path .normcase (self .src_dir ).rstrip ("\\ /" )),
244+ )
245+ if self .isolated
246+ else None
243247 )
244248
245249 @property
246250 def _env_vars (self ) -> dict [str , str ]:
247- paths = self ._prefix .bin_dirs
248- if "PATH" in os .environ :
249- paths .append (os .getenv ("PATH" , "" ))
250251 env : dict [str , str ] = {}
251252 if self .isolated :
253+ assert self ._prefix is not None
254+ paths = self ._prefix .bin_dirs [:]
252255 env .update (
253256 {
254257 "PYTHONPATH" : self ._prefix .site_dir ,
@@ -257,14 +260,15 @@ def _env_vars(self) -> dict[str, str]:
257260 )
258261 else :
259262 env_paths = self ._env .get_paths ()
260- project_libs = env_paths ["purelib" ]
261- pythonpath = [* self ._prefix .lib_dirs , project_libs ]
263+ pythonpath = list ({env_paths ["purelib" ], env_paths ["platlib" ]})
262264 if "PYTHONPATH" in os .environ :
263265 pythonpath .append (os .getenv ("PYTHONPATH" , "" ))
264266 env .update (
265267 PYTHONPATH = os .pathsep .join (pythonpath ),
266268 )
267- paths .append (env_paths ["scripts" ])
269+ paths = [env_paths ["scripts" ]]
270+ if "PATH" in os .environ :
271+ paths .append (os .getenv ("PATH" , "" ))
268272 env ["PATH" ] = os .pathsep .join (paths )
269273 return env
270274
@@ -279,8 +283,12 @@ def subprocess_runner(
279283 def check_requirements (self , reqs : Iterable [str ]) -> Iterable [Requirement ]:
280284 missing = set ()
281285 conflicting = set ()
282- project_lib = self ._env .get_paths ()["purelib" ]
283- libs = self ._prefix .lib_dirs + ([project_lib ] if not self .isolated else [])
286+ env_paths = self ._env .get_paths ()
287+ libs = (
288+ list ({env_paths ["purelib" ], env_paths ["platlib" ]})
289+ if not self .isolated
290+ else cast (_Prefix , self ._prefix ).lib_dirs
291+ )
284292 if reqs :
285293 ws = WorkingSet (libs )
286294 for req in reqs :
@@ -308,6 +316,7 @@ def install(self, requirements: Iterable[str], shared: bool = False) -> None:
308316 missing = list (self .check_requirements (requirements ))
309317 if not missing :
310318 return
319+ assert self ._prefix is not None
311320 path = self ._prefix .shared if shared else self ._prefix .overlay
312321 env = PythonEnvironment (self ._env .project , python = str (self ._env .interpreter .path ), prefix = path )
313322 install_requirements (missing , env )
0 commit comments