You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, the previous version in which this bug was not present was: Bazel 6.5.0.
Description
When using Bazel 7.0.0 or 7.3.1 (and presumably others in that range), the system Python is used where the @rules_python//python/config_settings:python_version was previously respected (by Bazel 6.5.0) when running with a WORKSPACE file instead of a MODULE.bazel file. The rules_python/examples/multi_python_versions/ example in this very repository exhibits the problem, if you remove the MODULE.bazel* files and WORKSPACE.bzlmod.
This makes it difficult to upgrade to Bazel 7 first and do the MODULE.bazel migration after, which otherwise would seem like an attractive migration path.
🔬 Minimal Reproduction
Setup:
git clone https://github.com/bazelbuild/rules_python
cd rules_python/examples/multi_python_versions/
rm WORKSPACE.bzlmod MODULE.bazel*
By removing WORKSPACE.bzlmod and MODULE.bazel*, we're now in a situation with just a WORKSPACE file. The following command works, and correctly reports 3.11:
USE_BAZEL_VERSION=6.5.0 bazelisk run \
--@rules_python//python/config_settings:python_version=3.11 //tests:version_default
When I test the same thing under Bazel 7.3.1 reports 3.10 (which is the system Python on Ubuntu 22) or 3.12 (which is the system Python on Ubuntu 24), depending on the system I run it on.
USE_BAZEL_VERSION=7.3.1 bazelisk run \
--@rules_python//python/config_settings:python_version=3.11 //tests:version_default
When on bazel 7.3.2, you also need to specify --noenable_bzlmod because by default bzlmod is going to be used.
The following will behave as you expect:
USE_BAZEL_VERSION=7.3.1 bazelisk run \ --noenable_bzlmod \ --@rules_python//python/config_settings:python_version=3.11 //tests:version_default
Because with bazel 7 onwards, it will create an empty MODULE.bazel file and if you don't specify explicitly to disable bzlmod the absence or presence of MODULE.bazel won't make a difference.
That said, I think the problem why it was falling back to the auto-detecting toolchain was because of #1675, which got fixed in #2289. By default rules_python was not registering any toolchains in WORKSPACE files when bzlmod is enabled and thus it would only know to fallback to the system python.
🐞 bug report
Affected Rule
The issue is caused by the rule:
py_binary
Is this a regression?
Yes, the previous version in which this bug was not present was: Bazel 6.5.0.Description
When using Bazel 7.0.0 or 7.3.1 (and presumably others in that range), the system Python is used where the
@rules_python//python/config_settings:python_version
was previously respected (by Bazel 6.5.0) when running with aWORKSPACE
file instead of aMODULE.bazel
file. Therules_python/examples/multi_python_versions/
example in this very repository exhibits the problem, if you remove theMODULE.bazel*
files andWORKSPACE.bzlmod
.This makes it difficult to upgrade to Bazel 7 first and do the
MODULE.bazel
migration after, which otherwise would seem like an attractive migration path.🔬 Minimal Reproduction
Setup:
By removing
WORKSPACE.bzlmod
andMODULE.bazel*
, we're now in a situation with just aWORKSPACE
file. The following command works, and correctly reports 3.11:When I test the same thing under Bazel 7.3.1 reports 3.10 (which is the system Python on Ubuntu 22) or 3.12 (which is the system Python on Ubuntu 24), depending on the system I run it on.
🌍 Your Environment
Operating System:
Output of
bazel version
:Rules_python version:
Anything else relevant?
Previously mentioned on https://bazelbuild.slack.com/archives/CA306CEV6/p1727352240596449
The text was updated successfully, but these errors were encountered: