rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

"Illegal ambiguous match" error with `experimental_index_url`

Open tbarrella opened this issue 8 months ago • 7 comments

🐞 bug report

Affected Rule

pip.parse

Is this a regression?

not sure

Description

When pip.parse with experimental_index_url uses per-platform requirements files and package versions don't match across files, it's possible (at least on OSX, for some packages) that using the package fails with "Illegal ambiguous match"

🔬 Minimal Reproduction

https://github.com/tbarrella/ambiguous

🔥 Exception or Error


Illegal ambiguous match on configurable attribute "actual" in @@rules_python++pip+pypi//debugpy:pkg:
@@rules_python++pip+pypi//_config:is_cp313_py_none_any_osx_aarch64
@@rules_python++pip+pypi//_config:is_cp313_cp313_osx_universal2
Multiple matches are not allowed unless one is unambiguously more specialized or they resolve to the same value. See https://bazel.build/reference/be/functions#select.

Illegal ambiguous match on configurable attribute "actual" in @@rules_python++pip+pypi//tornado:pkg:
@@rules_python++pip+pypi//_config:is_cp313_sdist_osx_aarch64
@@rules_python++pip+pypi//_config:is_cp313_abi3_osx_universal2
Multiple matches are not allowed unless one is unambiguously more specialized or they resolve to the same value. See https://bazel.build/reference/be/functions#select.

🌍 Your Environment

Operating System:

  
macOS, M2, 15.3.1
  

Output of bazel version:

  
Bazelisk version: 1.25.0
Build label: 8.1.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Tue Feb 25 18:53:44 2025 (1740509624)
Build timestamp: 1740509624
Build timestamp as int: 1740509624
  

Rules_python version:

  
1.3.0
  

Anything else relevant?

  • The root cause may be the same as #2648
  • Workaround is to manually make the versions and hashes match when possible

tbarrella avatar Apr 09 '25 03:04 tbarrella

The root cause of this is different from #2648.

The reproduction is trying to include different versions for different target platforms and it seems that it is failing due to us including more than what would be minimally necessary. I was already thinking about the fix for this but did not have time to do it but in quick terms here is what I am thinking about.


First select_whls is returning a list of compatible wheels with the target platform.

  1. the freethreaded/non-freethreaded
  2. manylinux/musllinux
  3. universal2 vs arch wheels

Instead of having all of them, we could just have one wheel that is matching the target platform.

However, the target platform definition is not customizable and in order to have it customizable, we have to first implement #2909. Once that is done, we can revisit this issue.


A workaround for this is to not use different versions for different target platforms or to remove the hashes for some of the requirements.

aignas avatar May 24 '25 15:05 aignas

One trick to avoid ambiguous match is to use a chain of select-default, e.g

alias(
  name = "x" actual = select({
  ":ft_yes": ...,
  "//conditions:default": ":ft_no",
  })
)

alias(
  name = "ft_no", actual = select({
    ":linux": ...,
    ":mac": ...
  })
)

rickeylev avatar May 24 '25 19:05 rickeylev

But to be fully correct we would have to first select the target platform and only then the wheel based config setting.

That would be another solution to this problem.

aignas avatar May 25 '25 00:05 aignas

I hit what I assume is this same issue but a different set of constraints:

ERROR: /private/var/tmp/_bazel_ksmiley/a685f717f9f5cebba0f54a5f41d6fcb3/external/rules_python++python+python_3_13/BUILD.bazel:27:18: Illegal ambiguous match on configurable attribute "actual" in @@rules_python++python+python_3_13//:python_headers:
@@rules_python++python+python_3_13//:aarch64-apple-darwin
@@rules_python++python+python_3_13//:aarch64-apple-darwin-freethreaded

keith avatar Jun 13 '25 18:06 keith

another similar example on linux:

ERROR: /home/ubuntu/.cache/bazel/_bazel_ubuntu/df7f5566547a987550d6a5e4980fc00b/external/rules_python++python+python_3_9/BUILD.bazel:19:18: Illegal ambiguous match on configurable attribute "actual" in @@rules_python++python+python_3_9//:py3_runtime:
@@rules_python++python+python_3_9//:x86_64-unknown-linux-gnu
@@rules_python++python+python_3_9//:x86_64-unknown-linux-musl

keith avatar Jun 13 '25 19:06 keith

I hit what I assume is this same issue but a different set of constraints:

@keith, this is a different issue, as this may happen without the experimental index url. Could you paste the config you have in a new ticket? We will have to solve the python toolchain aliases separately.

aignas avatar Jun 15 '25 00:06 aignas

https://github.com/bazel-contrib/rules_python/issues/2993

keith avatar Jun 16 '25 17:06 keith

I actually hit the original issue here too

A workaround for this is to not use different versions for different target platforms

in my case I am using this:

        requirements_by_platform = {
            "//:.../requirements.txt": "linux_x86_64",
        },

but i am instantiating this repo for N python versions, is that the same case? I can probably come up with another repro

keith avatar Jun 25 '25 01:06 keith

Could you please check if #3058 resolves the original issue?

aignas avatar Jul 07 '25 13:07 aignas

seems to fix my case of it !

keith avatar Jul 07 '25 16:07 keith