Skip to content

Commit 9661dd7

Browse files
fix(activate): Don't set PYTHONEXECUTABLE (#699)
Paired with @alexeagle. It used to be before recent improvements to runfiles tree identification and the venv shim that we relied on the activate script to set PYTHONEXECUTABLE. This proved to be unreliable, in part because many tools just don't evaluate the activate script. Setting the PYTHONEXECUTABLE without also setting PYTHONHOME breaks non-Bazel Python invocations and so is a bug. Furthermore we didn't save/restore or more importantly unset PYTHONEXECUTABLE during deactivate, which broke shell environments. Just don't set this. Fixes #671. ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: yes - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: yes Fixed #671, `activate` scripts no longer poison the shell env. ### Test plan - Manual testing --------- Co-authored-by: aspect-marvin[bot] <[email protected]>
1 parent 4715b89 commit 9661dd7

File tree

3 files changed

+2
-8
lines changed

3 files changed

+2
-8
lines changed

py/tests/py_venv_image_layer/my_app_amd64_layers_listing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,7 @@ files:
25132513
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/
25142514
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/
25152515
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/
2516-
- -rwxr-xr-x 0 0 0 2801 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/activate
2516+
- -rwxr-xr-x 0 0 0 2503 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/activate
25172517
- -rwxr-xr-x 0 0 0 734360 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/python
25182518
- -rwxr-xr-x 0 0 0 734360 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/python3
25192519
- -rwxr-xr-x 0 0 0 734360 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/python3.9

py/tests/py_venv_image_layer/my_app_arm64_layers_listing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2494,7 +2494,7 @@ files:
24942494
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/
24952495
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/
24962496
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/
2497-
- -rwxr-xr-x 0 0 0 2801 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/activate
2497+
- -rwxr-xr-x 0 0 0 2503 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/activate
24982498
- -rwxr-xr-x 0 0 0 701472 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/python
24992499
- -rwxr-xr-x 0 0 0 701472 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/python3
25002500
- -rwxr-xr-x 0 0 0 701472 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/_main/py/tests/py_venv_image_layer/.my_app_bin/bin/python3.9

py/tools/py/src/activate.tmpl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ deactivate nondestructive
5757
VIRTUAL_ENV="$(dirname "$(dirname "${BASH_SOURCE}")")"
5858
export VIRTUAL_ENV
5959

60-
# HACK: (Ab)use the MacOS $PYTHONEXECUTABLE to record the `.runfiles`-relative
61-
# interpreter path. This helps us avoid issues with the interpreter's path being
62-
# `realpath`-ed in such a way that it escapes the `.runfiles` tree.
63-
PYTHONEXECUTABLE="${VIRTUAL_ENV}/bin/python"
64-
export PYTHONEXECUTABLE
65-
6660
# unset PYTHONHOME if set
6761
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
6862
# could use `if (set -u; : $PYTHONHOME) ;` in bash.

0 commit comments

Comments
 (0)