@@ -107,15 +107,13 @@ impl CachedEnvironment {
107107 printer : Printer ,
108108 preview : PreviewMode ,
109109 ) -> Result < Self , ProjectError > {
110- // Resolve the "base" interpreter, which resolves to an underlying parent interpreter if the
111- // given interpreter is a virtual environment.
112- let base_interpreter = Self :: base_interpreter ( interpreter, cache) ?;
110+ let interpreter = Self :: base_interpreter ( interpreter, cache) ?;
113111
114112 // Resolve the requirements with the interpreter.
115113 let resolution = Resolution :: from (
116114 resolve_environment (
117115 spec,
118- & base_interpreter ,
116+ & interpreter ,
119117 build_constraints. clone ( ) ,
120118 & settings. resolver ,
121119 network_settings,
@@ -143,29 +141,20 @@ impl CachedEnvironment {
143141 // Use the canonicalized base interpreter path since that's the interpreter we performed the
144142 // resolution with and the interpreter the environment will be created with.
145143 //
146- // We also include the canonicalized `sys.prefix` of the non-base interpreter, that is, the
147- // virtual environment's path. Originally, we shared cached environments independent of the
148- // environment they'd be layered on top of. However, this causes collisions as the overlay
149- // `.pth` file can be overridden by another instance of uv. Including this element in the key
150- // avoids this problem at the cost of creating separate cached environments for identical
151- // `--with` invocations across projects. We use `sys.prefix` rather than `sys.executable` so
152- // we can canonicalize it without invalidating the purpose of the element — it'd probably be
153- // safe to just use the absolute `sys.executable` as well.
154- //
155- // TODO(zanieb): Since we're not sharing these environmments across projects, we should move
156- // [`CachedEvnvironment::set_overlay`] etc. here since the values there should be constant
157- // now.
144+ // We cache environments independent of the environment they'd be layered on top of. The
145+ // assumption is such that the environment will _not_ be modified by the user or uv;
146+ // otherwise, we risk cache poisoning. For example, if we were to write a `.pth` file to
147+ // the cached environment, it would be shared across all projects that use the same
148+ // interpreter and the same cached dependencies.
158149 //
159150 // TODO(zanieb): We should include the version of the base interpreter in the hash, so if
160151 // the interpreter at the canonicalized path changes versions we construct a new
161152 // environment.
162- let environment_hash = cache_digest ( & (
163- & canonicalize_executable ( base_interpreter. sys_executable ( ) ) ?,
164- & interpreter. sys_prefix ( ) . canonicalize ( ) ?,
165- ) ) ;
153+ let interpreter_hash =
154+ cache_digest ( & canonicalize_executable ( interpreter. sys_executable ( ) ) ?) ;
166155
167156 // Search in the content-addressed cache.
168- let cache_entry = cache. entry ( CacheBucket :: Environments , environment_hash , resolution_hash) ;
157+ let cache_entry = cache. entry ( CacheBucket :: Environments , interpreter_hash , resolution_hash) ;
169158
170159 if cache. refresh ( ) . is_none ( ) {
171160 if let Ok ( root) = cache. resolve_link ( cache_entry. path ( ) ) {
@@ -179,7 +168,7 @@ impl CachedEnvironment {
179168 let temp_dir = cache. venv_dir ( ) ?;
180169 let venv = uv_virtualenv:: create_venv (
181170 temp_dir. path ( ) ,
182- base_interpreter ,
171+ interpreter ,
183172 uv_virtualenv:: Prompt :: None ,
184173 false ,
185174 false ,
0 commit comments