Skip to content

Commit f65b2ac

Browse files
authored
fix: run check on interpreter in isolated mode (#2738)
Runs the check on the interpreter in the toolchain repo in isolated mode via `-I`. This ensures it's not influenced by userland environment variables, such as `PYTHONPATH` which will cause issues if it allows this invocation to use into another interpreter versions site-packages.
1 parent f685fe9 commit f65b2ac

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Unreleased changes template.
8282
* (toolchains) The toolchain matching is has been fixed when writing
8383
transitions transitioning on the `python_version` flag.
8484
Fixes [#2685](https://github.com/bazel-contrib/rules_python/issues/2685).
85+
* (toolchains) Run the check on the Python interpreter in isolated mode, to ensure it's not affected by userland environment variables, such as `PYTHONPATH`.
8586

8687
{#v0-0-0-added}
8788
### Added

python/private/toolchains_repo.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,14 @@ assert want_python == got_python, \
275275
repo_utils.execute_checked(
276276
rctx,
277277
op = "CheckHostInterpreter",
278-
arguments = [rctx.path(python_binary), python_tester],
278+
arguments = [
279+
rctx.path(python_binary),
280+
# Run the interpreter in isolated mode, this options implies -E, -P and -s.
281+
# This ensures that environment variables are ignored that are set in userspace, such as PYTHONPATH,
282+
# which may interfere with this invocation.
283+
"-I",
284+
python_tester,
285+
],
279286
)
280287
if not rctx.delete(python_tester):
281288
fail("Failed to delete the python tester")

0 commit comments

Comments
 (0)