Skip to content

Commit

Permalink
python: Don't assume py2_runtime toolchain attribute exists.
Browse files Browse the repository at this point in the history
There's a test that purposefully omits the attribute to test error messages.
To fix, just guard the access with hasattr().

Work towards #15897

PiperOrigin-RevId: 505715279
Change-Id: I4c8fe51783ac4f07e9c8ce32f457a65d941bf6b0
  • Loading branch information
rickeylev authored and hvadehra committed Feb 14, 2023
1 parent 2f84a2f commit e08602f
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,12 @@ def _maybe_get_runtime_from_ctx(ctx):
# --python_path. See tools/python/toolchain.bzl.
# TODO(#7844): Remove this hack when the autodetecting toolchain has a
# Windows implementation.
if toolchain.py2_runtime and toolchain.py2_runtime.interpreter_path == "/_magic_pyruntime_sentinel_do_not_use":
if (
# BazelPyBinaryConfiguredTargetTest.toolchainInfoFieldHasBadVersion purposefully
# omits the py2_runtime attribute to test for other error messages.
hasattr(toolchain, "py2_runtime") and toolchain.py2_runtime and
toolchain.py2_runtime.interpreter_path == "/_magic_pyruntime_sentinel_do_not_use"
):
return None, None

if not hasattr(toolchain, "py3_runtime"):
Expand Down

0 comments on commit e08602f

Please sign in to comment.