Skip to content

Commit

Permalink
[7.1.0] python: rules_python 0.22.0 -> 0.22.1 soas to register Python…
Browse files Browse the repository at this point in the history
… toolchain by default (#21369)

A regression from upgrading to rules_python 0.22.0 is that a Python
toolchain is no longer registered by default (the prior 0.4.0 version
registered the "autodetecting" toolchain). Subsequent versions of
rules_python (0.23.0 or later) register a toolchain by default again,
but it's a downloaded runtime, which makes upgrading more involved.

To fix, upgrade to 0.22.1, which registers the autodetecting toolchain.
This restores the rules_python 0.4.0 behavior and should suffice until
bazel_tools is upgraded to 0.23.0 or later.

Fixes #20458

Closes #20514

PiperOrigin-RevId: 592578175
Change-Id: I707a4c96829063536f81cc10e144652102da1e7e

Fixes #21348

Co-authored-by: Richard Levasseur <[email protected]>
  • Loading branch information
meteorcloudy and rickeylev authored Feb 15, 2024
1 parent 2141968 commit 23addd6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
4 changes: 2 additions & 2 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/MODULE.tools
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_java", version = "7.1.0")
bazel_dep(name = "rules_license", version = "0.0.3")
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_python", version = "0.22.0")
bazel_dep(name = "rules_python", version = "0.22.1")

bazel_dep(name = "buildozer", version = "6.4.0.2")
bazel_dep(name = "platforms", version = "0.0.7")
Expand Down
28 changes: 28 additions & 0 deletions src/test/shell/bazel/python_version_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,34 @@ EOF
expect_log "I am Python 3"
}

# Verify that a bzlmod without any workspace interference is able to
# run Python rules.
# This test is obsolete once the Python rules are removed from Bazel itself.
function test_pure_bzlmod_can_build_py_binary() {
mkdir -p test

cat > test/BUILD << EOF
py_binary(
name = "main3",
python_version = "PY3",
srcs = ["main3.py"],
)
EOF

touch test/main3.py

# Tell bzlmod to ignore workspace entirely
touch WORKSPACE.bzlmod
# Also clear out workspace, just to be safe. If workspace is triggered at all,
# then internal logic as part of the Python rules registration will trigger
# registering a Python toolchain, which we explicitly want to avoid.
cat > WORKSPACE

# Build instead of run. The autodetecting toolchain may not produce something
# that actually works (it could be a fake or some arbitrary system python).
bazel build --enable_bzlmod //test:main3 &> $TEST_log || fail "unable to build py binary"
}

# Test that access to runfiles works (in general, and under our test environment
# specifically).
function test_can_access_runfiles() {
Expand Down
38 changes: 20 additions & 18 deletions src/test/tools/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23addd6

Please sign in to comment.