@@ -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 ):
@@ -294,8 +308,8 @@ def _setup_pip(self, context):
294
308
# We run ensurepip in isolated mode to avoid side effects from
295
309
# environment vars, the current directory and anything else
296
310
# intended for the global Python environment
297
- cmd = [context .env_exe , '-Im' , 'ensurepip' , '--upgrade' ,
298
- '--default-pip' ]
311
+ cmd = [context .env_exec_cmd , '-Im' , 'ensurepip' , '--upgrade' ,
312
+ '--default-pip' ]
299
313
subprocess .check_output (cmd , stderr = subprocess .STDOUT )
300
314
301
315
def setup_scripts (self , context ):
@@ -395,11 +409,7 @@ def upgrade_dependencies(self, context):
395
409
logger .debug (
396
410
f'Upgrading { CORE_VENV_DEPS } packages in { context .bin_path } '
397
411
)
398
- if sys .platform == 'win32' :
399
- python_exe = os .path .join (context .bin_path , 'python.exe' )
400
- else :
401
- python_exe = os .path .join (context .bin_path , 'python' )
402
- cmd = [python_exe , '-m' , 'pip' , 'install' , '--upgrade' ]
412
+ cmd = [context .env_exec_cmd , '-m' , 'pip' , 'install' , '--upgrade' ]
403
413
cmd .extend (CORE_VENV_DEPS )
404
414
subprocess .check_call (cmd )
405
415
0 commit comments