Skip to content

Commit a419cf5

Browse files
committed
remove defunct code paths
1 parent b0164d5 commit a419cf5

1 file changed

Lines changed: 36 additions & 41 deletions

File tree

python/private/py_executable.bzl

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -513,23 +513,21 @@ def _create_zip_main(ctx, *, stage2_bootstrap, runtime_details, venv):
513513
# * https://github.com/python/cpython/blob/main/Modules/getpath.py
514514
# * https://github.com/python/cpython/blob/main/Lib/site.py
515515
def _create_venv(ctx, output_prefix, imports, runtime_details, add_runfiles_root_to_sys_path):
516-
create_full_venv = True
517516
venv = "_{}.venv".format(output_prefix.lstrip("_"))
518517

519-
if create_full_venv:
520-
# The pyvenv.cfg file must be present to trigger the venv site hooks.
521-
# Because it's paths are expected to be absolute paths, we can't reliably
522-
# put much in it. See https://github.com/python/cpython/issues/83650
523-
pyvenv_cfg = ctx.actions.declare_file("{}/pyvenv.cfg".format(venv))
524-
ctx.actions.write(pyvenv_cfg, "")
525-
else:
526-
pyvenv_cfg = None
518+
# The pyvenv.cfg file must be present to trigger the venv site hooks.
519+
# Because it's paths are expected to be absolute paths, we can't reliably
520+
# put much in it. See https://github.com/python/cpython/issues/83650
521+
pyvenv_cfg = ctx.actions.declare_file("{}/pyvenv.cfg".format(venv))
522+
ctx.actions.write(pyvenv_cfg, "")
527523

528524
runtime = runtime_details.effective_runtime
529525

530526
venvs_use_declare_symlink_enabled = (
531527
VenvsUseDeclareSymlinkFlag.get_value(ctx) == VenvsUseDeclareSymlinkFlag.YES
532528
)
529+
530+
# todo: default this to True for bootstrap=system_python ?
533531
recreate_venv_at_runtime = False
534532

535533
if runtime.interpreter:
@@ -539,40 +537,37 @@ def _create_venv(ctx, output_prefix, imports, runtime_details, add_runfiles_root
539537

540538
bin_dir = "{}/bin".format(venv)
541539

542-
if create_full_venv:
543-
# Some wrappers around the interpreter (e.g. pyenv) use the program
544-
# name to decide what to do, so preserve the name.
545-
py_exe_basename = paths.basename(interpreter_actual_path)
546-
547-
if not venvs_use_declare_symlink_enabled or not runtime.supports_build_time_venv:
548-
recreate_venv_at_runtime = True
549-
550-
# When the venv symlinks are disabled, the $venv/bin/python3 file isn't
551-
# needed or used at runtime. However, the zip code uses the interpreter
552-
# File object to figure out some paths.
553-
interpreter = ctx.actions.declare_file("{}/{}".format(bin_dir, py_exe_basename))
554-
ctx.actions.write(interpreter, "actual:{}".format(interpreter_actual_path))
555-
556-
elif runtime.interpreter:
557-
# Even though ctx.actions.symlink() is used, using
558-
# declare_symlink() is required to ensure that the resulting file
559-
# in runfiles is always a symlink. An RBE implementation, for example,
560-
# may choose to write what symlink() points to instead.
561-
interpreter = ctx.actions.declare_symlink("{}/{}".format(bin_dir, py_exe_basename))
562-
563-
rel_path = relative_path(
564-
# dirname is necessary because a relative symlink is relative to
565-
# the directory the symlink resides within.
566-
from_ = paths.dirname(runfiles_root_path(ctx, interpreter.short_path)),
567-
to = interpreter_actual_path,
568-
)
540+
# Some wrappers around the interpreter (e.g. pyenv) use the program
541+
# name to decide what to do, so preserve the name.
542+
py_exe_basename = paths.basename(interpreter_actual_path)
543+
544+
if not venvs_use_declare_symlink_enabled or not runtime.supports_build_time_venv:
545+
recreate_venv_at_runtime = True
546+
547+
# When the venv symlinks are disabled, the $venv/bin/python3 file isn't
548+
# needed or used at runtime. However, the zip code uses the interpreter
549+
# File object to figure out some paths.
550+
interpreter = ctx.actions.declare_file("{}/{}".format(bin_dir, py_exe_basename))
551+
ctx.actions.write(interpreter, "actual:{}".format(interpreter_actual_path))
552+
553+
elif runtime.interpreter:
554+
# Even though ctx.actions.symlink() is used, using
555+
# declare_symlink() is required to ensure that the resulting file
556+
# in runfiles is always a symlink. An RBE implementation, for example,
557+
# may choose to write what symlink() points to instead.
558+
interpreter = ctx.actions.declare_symlink("{}/{}".format(bin_dir, py_exe_basename))
559+
560+
rel_path = relative_path(
561+
# dirname is necessary because a relative symlink is relative to
562+
# the directory the symlink resides within.
563+
from_ = paths.dirname(runfiles_root_path(ctx, interpreter.short_path)),
564+
to = interpreter_actual_path,
565+
)
569566

570-
ctx.actions.symlink(output = interpreter, target_path = rel_path)
571-
else:
572-
interpreter = ctx.actions.declare_symlink("{}/{}".format(bin_dir, py_exe_basename))
573-
ctx.actions.symlink(output = interpreter, target_path = runtime.interpreter_path)
567+
ctx.actions.symlink(output = interpreter, target_path = rel_path)
574568
else:
575-
interpreter = None
569+
interpreter = ctx.actions.declare_symlink("{}/{}".format(bin_dir, py_exe_basename))
570+
ctx.actions.symlink(output = interpreter, target_path = runtime.interpreter_path)
576571

577572
if runtime.interpreter_version_info:
578573
version = "{}.{}".format(

0 commit comments

Comments
 (0)