@@ -350,6 +350,7 @@ def _create_executable(
350350 main_py = main_py ,
351351 imports = imports ,
352352 runtime_details = runtime_details ,
353+ venv = venv ,
353354 )
354355 extra_runfiles = ctx .runfiles ([stage2_bootstrap ] + venv .files_without_interpreter )
355356 zip_main = _create_zip_main (
@@ -557,6 +558,8 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
557558 ctx .actions .write (interpreter , "actual:{}" .format (interpreter_actual_path ))
558559
559560 elif runtime .interpreter :
561+ # Some wrappers around the interpreter (e.g. pyenv) use the program
562+ # name to decide what to do, so preserve the name.
560563 py_exe_basename = paths .basename (runtime .interpreter .short_path )
561564
562565 # Even though ctx.actions.symlink() is used, using
@@ -594,7 +597,8 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
594597 if "t" in runtime .abi_flags :
595598 version += "t"
596599
597- site_packages = "{}/lib/python{}/site-packages" .format (venv , version )
600+ venv_site_packages = "lib/python{}/site-packages" .format (version )
601+ site_packages = "{}/{}" .format (venv , venv_site_packages )
598602 pth = ctx .actions .declare_file ("{}/bazel.pth" .format (site_packages ))
599603 ctx .actions .write (pth , "import _bazel_site_init\n " )
600604
@@ -620,6 +624,7 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
620624 # Runfiles root relative path or absolute path
621625 interpreter_actual_path = interpreter_actual_path ,
622626 files_without_interpreter = [pyvenv_cfg , pth , site_init ] + site_packages_symlinks ,
627+ venv_site_packages = venv_site_packages ,
623628 )
624629
625630def _create_site_packages_symlinks (ctx , site_packages ):
@@ -716,7 +721,8 @@ def _create_stage2_bootstrap(
716721 output_sibling ,
717722 main_py ,
718723 imports ,
719- runtime_details ):
724+ runtime_details ,
725+ venv = None ):
720726 output = ctx .actions .declare_file (
721727 # Prepend with underscore to prevent pytest from trying to
722728 # process the bootstrap for files starting with `test_`
@@ -742,6 +748,7 @@ def _create_stage2_bootstrap(
742748 "%main_module%" : ctx .attr .main_module ,
743749 "%target%" : str (ctx .label ),
744750 "%workspace_name%" : ctx .workspace_name ,
751+ "%site_packages%" : venv .venv_site_packages if venv else "" ,
745752 },
746753 is_executable = True ,
747754 )
0 commit comments