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

pip.override in upstream modules but got "overrides are only supported in root modules" #2513

Open
fucangfy opened this issue Dec 19, 2024 · 3 comments

Comments

@fucangfy
Copy link

fucangfy commented Dec 19, 2024

🐞 bug report

Affected Rule

The issue is caused by the rule: https://github.com/bazelbuild/rules_python/blob/66a8b5b595710bd107c31ad5d449593536effb76/python/private/pypi/extension.bzl#L404

Is this a regression?

No

Description

I'm migrating from WORKSPACE to bzlmod.
There is a library A, in which it has patches like

pip.override(
    file = "torch-2.3.0-cp311-cp311-manylinux1_x86_64.whl",
    patch_strip = 1,
    patches = [
        # FIXME: https://github.com/pytorch/pytorch/issues/117350
        "//bazel/patches:pytorch.patch",
        "//bazel/patches:pytorch_record.patch",
    ],
)

And I have another project B, which depends on A, however after adding deps like
bazel_dep(name = "A", version = "x.y.z")
I got the error

ERROR: /xxxx/df5a01bdd2671083bb14bf68b19a3f38/external/rules_python~/python/private/pypi/extension.bzl:406:21: Traceback (most recent call last):
        File "/xx/.cache/bazel/xxxxx/df5a01bdd2671083bb14bf68b19a3f38/external/rules_python~/python/private/pypi/extension.bzl", line 406, column 21, in _pip_impl
                fail("overrides are only supported in root modules")
Error in fail: overrides are only supported in root modules
ERROR: Analysis of target '//xxx' failed; build aborted: error evaluating module extension pip in @@rules_python~//python/extensions:pip.bzl

🔬 Minimal Reproduction

🔥 Exception or Error





🌍 Your Environment

Operating System:

  
Ubuntu 24.04.1 LTS
  

Output of bazel version:

  
7.4.1
  

Rules_python version:

  
0.34.0
  

Anything else relevant?

@fucangfy
Copy link
Author

fucangfy commented Dec 19, 2024

After I deleting the patch part of dependent module, the error is gone, so I'm sure it is introduced by the pip.override.
Does it means the upstream modules can not override packages? Or maybe my understanding is not correct, could you please give an example about how to resolve this?

@aignas
Copy link
Collaborator

aignas commented Dec 23, 2024

What is the setup? I am not sure I fully understand why the non-root module needs to do the overrides? Just like bzlmod, the overrides are only done in the root module. Non-root modules may be redistributed and thus should not have overrides.

@fucangfy
Copy link
Author

Hi @aignas,

Thank you for your response. I'd like to provide some additional context regarding our situation.

We are currently working with an upstream project, referred to as "A", which is an independent entity. Project "A" has an override for torch specified in its MODULE.bazel file, as shown below:

pip.parse(
    extra_pip_args = [
        "--extra-index-url=https://mirrors.aliyun.com/pypi/simple/",
    ],
    hub_name = "spu_pip_dev",
    python_version = DEFAULT_PYTHON_VERSION,
    requirements_lock = "//:requirements_dev_lock.txt",
)

pip.override(
    file = "torch-2.3.0-cp311-cp311-manylinux1_x86_64.whl",
    patch_strip = 1,
    patches = [
        # FIXME: https://github.com/pytorch/pytorch/issues/117350
        "//bazel/patches:pytorch.patch",
        "//bazel/patches:pytorch_record.patch",
    ],
)

Our own project, "B", which depends on project "A", is encountering an error during compilation:

ERROR: /xxxx/df5a01bdd2671083bb14bf68b19a3f38/external/rules_python~/python/private/pypi/extension.bzl:406:21: Traceback (most recent call last):
        File "/xx/.cache/bazel/xxxxx/df5a01bdd2671083bb14bf68b19a3f38/external/rules_python~/python/private/pypi/extension.bzl", line 406, column 21, in _pip_impl
                fail("overrides are only supported in root modules")
Error in fail: overrides are only supported in root modules
ERROR: Analysis of target '//xxx' failed; build aborted: error evaluating module extension pip in @@rules_python~//python/extensions:pip.bzl

We are uncertain whether the override in project "A" is implemented correctly, or if there is a method for us to incorporate patches for pip packages within "A" without impacting downstream projects that rely on "A". Any guidance you could provide on this matter would be greatly appreciated.

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

No branches or pull requests

2 participants