fix(core): do not assume rules_python runtime (#3134) 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 we will crash with attribute error. I could not think how to add a unit test, which would test this fix because it seems to only happen with a released version of rules_python where we are not using `local_repository` override. Fixes #3119 --------- Co-authored-by: Richard Levasseur <richardlev@gmail.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md index 04979e8..b235989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md
@@ -109,6 +109,8 @@ * (toolchains) use "command -v" to find interpreter in `$PATH` ([#3150](https://github.com/bazel-contrib/rules_python/pull/3150)). * (pypi) `bazel vendor` now works in `bzlmod` ({gh-issue}`3079`). +* (core) builds work again on `7.x` `WORKSPACE` configurations + ([#3119](https://github.com/bazel-contrib/rules_python/issues/3119)). {#v0-0-0-added} ### Added
diff --git a/python/private/py_executable.bzl b/python/private/py_executable.bzl index 7e50247..9927975 100644 --- a/python/private/py_executable.bzl +++ b/python/private/py_executable.bzl
@@ -796,6 +796,7 @@ is_for_zip, runtime_details, venv = None): + """Create a legacy bootstrap script that is written in Python.""" runtime = runtime_details.effective_runtime if venv: @@ -805,8 +806,11 @@ python_binary_actual = venv.interpreter_actual_path if venv else "" - # Runtime may be None on Windows due to the --python_path flag. - if runtime and runtime.supports_build_time_venv: + # Guard against the following: + # * Runtime may be None on Windows due to the --python_path flag. + # * Runtime may not have 'supports_build_time_venv' if a really old version is autoloaded + # on bazel 7.6.x. + if runtime and getattr(runtime, "supports_build_time_venv", False): resolve_python_binary_at_runtime = "0" else: resolve_python_binary_at_runtime = "1"