Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rules_python broken with Bazel 8 on BCR #2361

Closed
rickeylev opened this issue Oct 30, 2024 · 5 comments · Fixed by #2362
Closed

rules_python broken with Bazel 8 on BCR #2361

rickeylev opened this issue Oct 30, 2024 · 5 comments · Fixed by #2362

Comments

@rickeylev
Copy link
Collaborator

🐞 bug report

Affected Rule

Unclear, looks like early module-phase startup code

Is this a regression?

Yes, works in 7.x

Description

(18:10:19) ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/1ae3de34028be386c3858fecaf88706d/external/rules_python+/python/private/full_version.bzl:35:13: Traceback (most recent call last):
	File "/var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/1ae3de34028be386c3858fecaf88706d/external/rules_python+/python/private/python.bzl", line 218, column 43, in _python_impl
		full_python_version = full_version(
	File "/var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/1ae3de34028be386c3858fecaf88706d/external/rules_python+/python/private/full_version.bzl", line 35, column 13, in full_version
		fail(
Error in fail: Unknown Python version '3.8', available values are: 3.10,3.9,3.11

🔬 Minimal Reproduction

Unclear, maybe running the bzlmod example under bazel 8?

@meteorcloudy
Copy link
Member

meteorcloudy commented Oct 30, 2024

I will try to make it easier to set up the environment for reproducing BCR presubmit failures. But for now, yes, you need to run bazel build //... under examples/bzlmod.

bcr_test_module:
module_path: "examples/bzlmod"

@rickeylev
Copy link
Collaborator Author

Luckily, it doesn't look specific to BCR. In rules_python from head:

cd examples/bzlmod
USE_BAZEL_VERSION=last_rc bazel test ...

Will result in the same error as reported.

@rickeylev
Copy link
Collaborator Author

tldr: I think we need to change our bzlmod example to not restrict python versions. Restricting the versions is tenenable with a small constrained dep footprint, but the example isn't that.

So in the bzlmod example, we intentionally restrict the python versions available to 3.9, 3.10, and 3.11. This is mostly just for demonstration purposes of this version-restriction feature.

The examples works with bazel 7, but fails under bazel 8. So, this would imply there's a bug with bazel 7 that got fixed in bazel 8. But...that seems like a weird bug -- failing to traverse the module graph? That would be hard to go unnoticed.

Hm, it looks like different modules are being used under bazel7 vs bazel 8

Modules and py versions that python.toolchain sees

Bazel 8:

example_bzlmod 3.9
example_bzlmod 3.10
rules_python 3.11
protobuf 3.8
protobuf 3.9
protobuf 3.10
protobuf 3.11
protobuf 3.12
other_module 3.9
other_module 3.11
rules_fuzzing 3.8
rules_fuzzing 3.9
rules_fuzzing 3.10
rules_fuzzing 3.11
rules_fuzzing 3.12

Bazel 7:

example_bzlmod 3.9
example_bzlmod 3.10
rules_python 3.11
other_module 3.9
other_module 3.11

Huh. Weird. example_bzlmod is the root module. other_module is one setup for the test. It's almost as if Bazel 7 was only looking at...things defined in the example's module file? and bazel 8 is now (what appears to be properly) traversing the module graph.

Looking at bazel mod graph output, I think what's happening is bazel 8 is using some newer module versions than bazel 7, and those newer versions are registering additional python versions.

If I bump the protobuf version, I bet it'll fail in 7.x...ah yup.

@meteorcloudy
Copy link
Member

Yeah, it might be module updates in https://cs.opensource.google/bazel/bazel/+/master:src/MODULE.tools. We had to include some new modules to support auto load

@rickeylev
Copy link
Collaborator Author

As a side note, I'm thinking the restriction logic we have in the module-phase is overly-eager about its enforcement. The intent is to allow the root module to prevent certain python versions from being used, but I don't think e.g. python 3.8 is actually being used in the build. It's just that e.g. protobuf needs to register something for 3.8 just in case it is used. Instead of failing at the most phase, we could probably let it fail later, at the build phase -- e.g. don't register a 3.8 toolchain, or register a failing toolchain for 3.8, or something like that.

github-merge-queue bot pushed a commit that referenced this issue Oct 30, 2024
Under Bazel 8, the bzlmod example is failing because newer versions of
some dependencies
request Python 3.8 to be available.

To fix, just comment out the restriction in the example. The example has
a somewhat
large dependency footprint, so enforcing this restriction seems
untenable. The config is
left commented out so users can discover the feature.

Fixes #2361
Fixes bazelbuild/bazel-central-registry#3056
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants