Skip to content

Commit 04faacd

Browse files
committed
fix: correctly count the escapes required for the venv created by script bootstrap implementation
1 parent 4ee7e25 commit 04faacd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

python/private/py_executable_bazel.bzl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def _create_executable(
191191
hasattr(runtime_details.effective_runtime, "stage2_bootstrap_template")):
192192
venv = _create_venv(
193193
ctx,
194+
executable = executable,
194195
output_prefix = base_executable_name,
195196
imports = imports,
196197
runtime_details = runtime_details,
@@ -350,7 +351,7 @@ def _create_zip_main(ctx, *, stage2_bootstrap, runtime_details, venv):
350351
# * https://snarky.ca/how-virtual-environments-work/
351352
# * https://github.com/python/cpython/blob/main/Modules/getpath.py
352353
# * https://github.com/python/cpython/blob/main/Lib/site.py
353-
def _create_venv(ctx, output_prefix, imports, runtime_details):
354+
def _create_venv(ctx, executable, output_prefix, imports, runtime_details):
354355
venv = "_{}.venv".format(output_prefix.lstrip("_"))
355356

356357
# The pyvenv.cfg file must be present to trigger the venv site hooks.
@@ -368,8 +369,12 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
368369
# in runfiles is always a symlink. An RBE implementation, for example,
369370
# may choose to write what symlink() points to instead.
370371
interpreter = ctx.actions.declare_symlink("{}/bin/{}".format(venv, py_exe_basename))
371-
interpreter_actual_path = runtime.interpreter.short_path
372-
parent = "/".join([".."] * (interpreter_actual_path.count("/") + 1))
372+
interpreter_actual_path = runtime.interpreter.short_path # Always relative to .runfiles/${workspace}
373+
374+
escapes = 2 # To escape out of ${target}.venv/bin
375+
escapes += executable.short_path.count("/") # To escape into .runfiles/${workspace}
376+
377+
parent = "/".join([".."] * escapes)
373378
rel_path = parent + "/" + interpreter_actual_path
374379
ctx.actions.symlink(output = interpreter, target_path = rel_path)
375380
else:

0 commit comments

Comments
 (0)