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> (cherry picked from commit acf75079fa5d7837ca4f3e45ff57b3b07adf4919) Cherry-pick notes: adjusted changelog to mention 1.5.2
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e1d72b..aaa95d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md
@@ -62,6 +62,8 @@ ### Fixed * (pypi) Correctly pull `sdist` distributions using `pip` ([#3131](https://github.com/bazel-contrib/rules_python/pull/3131)). +* (core) builds work again on `7.x` `WORKSPACE` configurations + ([#3119](https://github.com/bazel-contrib/rules_python/issues/3119)). {#1-5-1} ## [1.5.1] - 2025-07-06
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"