Skip to content

Commit 2769bf9

Browse files
committed
fix(core): do not assume rules_python runtime
This change reverts the behaviour where we assume that particular attributes will be always present - if bazel is doing autoloading for WORKSPACE builds (7.6.1), then this will crash. I could not think how to add a unit test, so just adding the fix here and a comment. Fixes #3119
1 parent f02c9c7 commit 2769bf9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ END_UNRELEASED_TEMPLATE
9191
* Multi-line python imports (e.g. with escaped newlines) are now correctly processed by Gazelle.
9292
* (toolchains) `local_runtime_repo` works with multiarch Debian with Python 3.8
9393
([#3099](https://github.com/bazel-contrib/rules_python/issues/3099)).
94+
* (core) builds work again on `7.x` `WORKSPACE` configurations ({gh-issue}`3119`).
9495

9596
{#v0-0-0-added}
9697
### Added

python/private/py_executable.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ def _create_stage1_bootstrap(
796796
is_for_zip,
797797
runtime_details,
798798
venv = None):
799+
"""Create a legacy bootstrap script that is written in Python."""
799800
runtime = runtime_details.effective_runtime
800801

801802
if venv:
@@ -805,8 +806,11 @@ def _create_stage1_bootstrap(
805806

806807
python_binary_actual = venv.interpreter_actual_path if venv else ""
807808

808-
# Runtime may be None on Windows due to the --python_path flag.
809-
if runtime and runtime.supports_build_time_venv:
809+
# Guard against the following:
810+
# * Runtime may be None on Windows due to the --python_path flag.
811+
# * Runtime may not have 'supports_build_time_venv' if a really old version is autoloaded
812+
# on bazel 7.6.x.
813+
if runtime and getattr(runtime, "supports_build_time_venv", False):
810814
resolve_python_binary_at_runtime = "0"
811815
else:
812816
resolve_python_binary_at_runtime = "1"

0 commit comments

Comments
 (0)