@@ -142,6 +142,20 @@ def create_if_needed(d):
142
142
context .bin_name = binname
143
143
context .env_exe = os .path .join (binpath , exename )
144
144
create_if_needed (binpath )
145
+ # Assign and update the command to use when launching the newly created
146
+ # environment, in case it isn't simply the executable script (e.g. bpo-45337)
147
+ context .env_exec_cmd = context .env_exe
148
+ if sys .platform == 'win32' :
149
+ # bpo-45337: Fix up env_exec_cmd to account for file system redirections.
150
+ # Some redirects only apply to CreateFile and not CreateProcess
151
+ real_env_exe = os .path .realpath (context .env_exe )
152
+ if os .path .normcase (real_env_exe ) != os .path .normcase (context .env_exe ):
153
+ logger .warning ('Actual environment location may have moved due to '
154
+ 'redirects, links or junctions.\n '
155
+ ' Requested location: "%s"\n '
156
+ ' Actual location: "%s"' ,
157
+ context .env_exe , real_env_exe )
158
+ context .env_exec_cmd = real_env_exe
145
159
return context
146
160
147
161
def create_configuration (self , context ):
@@ -293,8 +307,8 @@ def _setup_pip(self, context):
293
307
# We run ensurepip in isolated mode to avoid side effects from
294
308
# environment vars, the current directory and anything else
295
309
# intended for the global Python environment
296
- cmd = [context .env_exe , '-Im' , 'ensurepip' , '--upgrade' ,
297
- '--default-pip' ]
310
+ cmd = [context .env_exec_cmd , '-Im' , 'ensurepip' , '--upgrade' ,
311
+ '--default-pip' ]
298
312
subprocess .check_output (cmd , stderr = subprocess .STDOUT )
299
313
300
314
def setup_scripts (self , context ):
@@ -394,11 +408,7 @@ def upgrade_dependencies(self, context):
394
408
logger .debug (
395
409
f'Upgrading { CORE_VENV_DEPS } packages in { context .bin_path } '
396
410
)
397
- if sys .platform == 'win32' :
398
- python_exe = os .path .join (context .bin_path , 'python.exe' )
399
- else :
400
- python_exe = os .path .join (context .bin_path , 'python' )
401
- cmd = [python_exe , '-m' , 'pip' , 'install' , '--upgrade' ]
411
+ cmd = [context .env_exec_cmd , '-m' , 'pip' , 'install' , '--upgrade' ]
402
412
cmd .extend (CORE_VENV_DEPS )
403
413
subprocess .check_call (cmd )
404
414
0 commit comments