@@ -124,12 +124,15 @@ def _search_path(name):
124124 return None
125125
126126
127- # NOTE: We do not add _RUNFILES_ROOT to sys.path for two reasons:
128- # 1. Under workspace, it makes every external repository importable. If a Bazel
129- # repository matches a Python import name, they conflict.
130- # 2. Under bzlmod, the repo names in the runfiles directory aren't importable
131- # Python names, so there's no point in adding the runfiles root to sys.path.
132127def _setup_sys_path ():
128+ """Perform Bazel/binary specific sys.path setup.
129+
130+ NOTE: We do not add _RUNFILES_ROOT to sys.path for two reasons:
131+ 1. Under workspace, it makes every external repository importable. If a Bazel
132+ repository matches a Python import name, they conflict.
133+ 2. Under bzlmod, the repo names in the runfiles directory aren't importable
134+ Python names, so there's no point in adding the runfiles root to sys.path.
135+ """
133136 seen = set (sys .path )
134137 python_path_entries = []
135138
@@ -200,12 +203,15 @@ def _maybe_add_path(path):
200203 return coverage_setup
201204
202205
203- # The pyvenv.cfg created for py_binary leaves the `home` key unset. A
204- # side-effect of this is `sys._base_executable` points to the venv executable,
205- # not the actual executable. This mostly doesn't matter, but does affect
206- # using the venv module to create venvs (they point to the venv executable, not
207- # the actual executable).
208206def _fixup_sys_base_executable ():
207+ """Fixup sys._base_executable to account for Bazel-specific pyvenv.cfg
208+
209+ The pyvenv.cfg created for py_binary leaves the `home` key unset. A
210+ side-effect of this is `sys._base_executable` points to the venv executable,
211+ not the actual executable. This mostly doesn't matter, but does affect
212+ using the venv module to create venvs (they point to the venv executable, not
213+ the actual executable).
214+ """
209215 # Must have been set correctly?
210216 if sys .executable != sys ._base_executable :
211217 return
0 commit comments