-
Notifications
You must be signed in to change notification settings - Fork 543
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Can bzlmod
pip.parse
be inherited by other modules without loading python toolchain again?
#2029
Comments
The problem is that you are not using transitions to ensure that your module is using the right python toolchain. Could you add snippets of BUILD.bazel files where the targets in the 'our_module' are consumed by the 'other_module'. 'our_module' should use the python version aware py_binary in order to ensure that the default toolchain version set by 'other_module' does not influnce the build configuration for the targets in 'our_module'. So right now it is working as intended. |
Hey, thanks for looking into it. Actually the use case is that
load("@our_module//:defs.bzl", "aspect_config")
aspect_config(
name = "custom_aspect_config",
additional_flags = [],
config_files = "@our_module//configs:config_1", # We usually offer a set of predefined configs as well
default_feature = "awesome",
visibility = ["//visibility:public"],
)
build:my_config --@our_module//:my_aspect_config=//:custom_aspect_config
build:my_config --output_groups=my_aspect_output
build:my_config --aspects=@our_module//:defs.bzl%my_aspect And then we call it with, for example,
Usual python target used by our aspects: load("@our_module_pip//:requirements.bzl", "requirement")
load("@our_module_rules_python//python:defs.bzl", "py_binary", "py_library")
py_binary(
name = "runner", # This is then a default (private) attr of our aspects and is invoked by a `ctx.actions.run`
srcs = ["runner.py"],
visibility = ["//visibility:public"],
deps = [":utils"],
)
py_library(
name = "utils",
srcs = ["utils.py"],
visibility = ["//:__subpackages__"],
) |
The problem is the second snippet, you should be declaring the Or you should call |
That did the trick, thanks @aignas. If I may ask one more question, with workspace approach I was using a custom python toolchain name, but with bzlmod the name is directly derived from the python version. Is it possible to change it someway? If not, does it makes sense? I found that it's hard coded here: |
Why would you like to change that? With bzlmod the registration of the hermetic toolchains is happening in rules_python instead of the root module, so there is no need to have a custom name.
…On 4 July 2024 23:23:43 GMT+09:00, Lucas Munaretto ***@***.***> wrote:
That did the trick, thanks @aignas.
If I may ask one more question, with workspace approach I was using a custom python toolchain name, but with bzlmod the name is directly derived from the python version. Is it possible to change it someway? If not, does it makes sense?
I found that it's hard coded here:
https://github.com/bazelbuild/rules_python/blob/084b877c98b580839ceab2b071b02fc6768f3de6/python/private/python.bzl#L96C13-L96C27
--
Reply to this email directly or view it on GitHub:
#2029 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
Yes, for bzlmod itself there is no need for such thing. The idea would be to keep consistency between bzlmod and workspace. With workspace we usually have specialised names to avoid possible name conflicts inside big monorepos. Right now I basically modified the workspace toolchain name to match the bzlmod one. |
The consistency between You may have success in using:
But I am not sure if we can help you here anything beyond here. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
🐞 bug report <> help wanted
Affected Rule
The issue is caused by the rule:
bzlmod
pip.parse
Is this a regression?
I'm not sure, but probably related to this:
Issue: #1548
PR: #1549
Description
I'm adding
bzlmod
support for an internal repo that is loaded by other Bazel modules.In this repo we have some rules, aspects, and python actions that should be executed using our own toolchain. In this regard, we're also switching from our own custom toolchain to the ones offered by
rules_python
.Using the traditional WORKSPACE method we have no issues but when bzlmod is activated other Bazel modules cannot properly load and use our tools.
As additional info, our WORKSPACE.bzlmod is currently empty, we are offering only python3.9, and every python dependency comes from
rules_python
pip
.From what I read from the above Issue and PR this is somewhat intentional, but then I'm not sure how to proceed. Ideally I would want the end user (other module) to be able to inherit our python toolchain / pip requirements with
bzlmod
.🔬 Minimal Reproduction
Not a really a minimal reproduction but a code snippet that might help:
Then a
bazel build //...
in theother_module
is already enough to raise the error below.🔥 Exception or Error
🌍 Your Environment
Operating System:
Output of
bazel version
:Rules_python version:
Anything else relevant?
If I register a python3.9 toolchain in the other_module it works. If I register, for example, python3.8, it raises the same error, as expected.
The text was updated successfully, but these errors were encountered: