Skip to content

Don't fail when override is called from a non-root module #2550

@mailto-jonas

Description

@mailto-jonas

🐞 bug report

Affected Rule

The error is in pypi module extension when using the override tag class. See attached patch for location.

The issue is caused by the rule:

Non-root modules are failing to load.

Is this a regression?

This has never worked since the introduction of bzlmod.

Description

I have a Bazel module that I use in two different setup, where it in the first scenario acts as the root module and in the second scenario it is exported and used as a non-root module. The module is using rules_python and needs to apply a pip patch using the override tag class. However, in the current implementation, rules_python does not allow any calls to override when non-root, leading to a failure. Since there is no support for selects of if-cases within the MODULE.bazel file, this behavior prevents the second setup described above.

It would be beneficial if rules_python would trigger a warning instead of failing, to support the above use cases.

🔬 Minimal Reproduction

Add the following code to a non root module:
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.override()

🔥 Exception or Error

The module extension calls: fail("overrides are only supported in root modules")

🌍 Your Environment

Ubuntu 22.04
Bazel 8.0.0
rules_python 1.0.0
non_root_override.patch.txt

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