@@ -222,18 +222,23 @@ def _py_zipapp_executable_impl(ctx):
222222 if target_platform_has_any_constraint (ctx , ctx .attr ._windows_constraints ):
223223 executable = ctx .actions .declare_file (ctx .label .name + ".exe" )
224224
225- python_exe = py_executable . venv_python_exe
226- if python_exe :
227- python_exe_path = runfiles_root_path ( ctx , python_exe . short_path )
228- elif py_runtime .interpreter :
229- python_exe_path = runfiles_root_path ( ctx , py_runtime .interpreter . short_path )
225+ # The zipapp is an opaque zip file, so the Bazel Python launcher doesn't
226+ # know how to look inside it to find the Python interpreter. This means
227+ # we can only use system paths or programs on PATH to bootstrap.
228+ if py_runtime .interpreter_path :
229+ bootstrap_python_path = py_runtime .interpreter_path
230230 else :
231- python_exe_path = py_runtime .interpreter_path
231+ # A special value the Bazel Python launcher recognized to skip
232+ # lookup in the runfiles and uses `python.exe` from PATH.
233+ bootstrap_python_path = "python"
232234
233235 create_windows_exe_launcher (
234236 ctx ,
235237 output = executable ,
236- python_binary_path = python_exe_path ,
238+ # The path to a python to use to invoke e.g. `python.exe foo.zip`
239+ python_binary_path = bootstrap_python_path ,
240+ # Tell the launcher to invoke `python_binary_path` on itself
241+ # after removing its file extension and appending `.zip`.
237242 use_zip_file = True ,
238243 )
239244 default_outputs = [executable , zip_file ]
0 commit comments