Skip to content

Can bzlmod pip.parse be inherited by other modules without loading python toolchain again? #2029

@lucasmuna

Description

@lucasmuna

🐞 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:

# our_module/MODULE.bazel
...
bazel_dep(name = "rules_python", repo_name = "our_module_rules_python", version = "0.33.2")

python = use_extension("@our_module_rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    python_version = "3.9",
    configure_coverage_tool = True,
    is_default = True, # From what I understood this is only valid for this root
)

use_repo(python, "python_versions", "python_3_9") # Tested this ...

register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain") # Tested this ...

pip = use_extension("@our_module_rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    hub_name = "our_module_pip",
    python_version = "3.9",
    requirements_lock = "//third_party/pip:requirements_lock.txt",
)
use_repo(pip, "our_module_pip")
...
# other_module/MODULE.bazel
...
bazel_dep(name = "other_module", version = "2.0.0")
local_path_override( # The real final user would actually load us through `http_archive` or `bazel_dep`
    module_name = "other_module",
    path = "../other_module",
)
...

Then a bazel build //... in the other_module is already enough to raise the error below.

🔥 Exception or Error


ERROR: /home/USER/.cache/bazel/_bazel_USER/69ebdc65b3da0709797efa3f05af60d8/external/rules_python~0.33.2~pip~our_module_pip/cvc5/BUILD.bazel:47:6: configurable attribute "actual" in @rules_python~0.33.2~pip~our_module_pip//cvc5:data doesn't match this configuration: No matching wheel for current configuration's Python version.

The current build configuration's Python version doesn't match any of the Python
wheels available for this wheel. This wheel supports the following Python
configuration settings:
    //_config:is_python_3.9

To determine the current configuration's Python version, run:
    `bazel config ` (shown further below)
and look for
    rules_python//python/config_settings:python_version

If the value is missing, then the "default" Python version is being used,
which has a "null" version value and will not match version constraints.


This instance of @rules_python~0.33.2~pip~our_module_pip//cvc5:data has configuration identifier db508b9. To inspect its configuration, run: bazel config db508b9.

For more help, see https://bazel.build/docs/configurable-attributes#faq-select-choose-condition.

🌍 Your Environment

Operating System:

  
Ubuntu 20.04.6 LTS | 5.15.0-113-generic GNU/Linux
  

Output of bazel version:

  
Bazelisk version: v1.11.0
Build label: 6.2.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue May 9 18:33:08 2023 (1683657188)
Build timestamp: 1683657188
Build timestamp as int: 1683657188
  

Rules_python version:

  
0.33.2
  

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions