Skip to content

Support universal requirements for multiple python versions#2797

Description

@keith

馃悶 bug report

Affected Rule

pip.parse

Is this a regression?

I don't think so

Description

Some dependencies can vary based on the current python version. In this case for requirements.txt files generated by uv or similar tools, the python version is encoded in the requirements.txt:

numpy==2.0.2 ; python_full_version < '3.10'
    # via -r requirements.in
numpy==2.2.5 ; python_full_version >= '3.10'
    # via -r requirements.in

In this case if you attempt to use this requirements file with pip.parse you get this error:

ERROR: /home/ubuntu/.cache/bazel/_bazel_ubuntu/46f0c9813505c30d178a2aff399354ea/external/rules_python+/python/private/pypi/extension.bzl:224:25: Traceback (most recent call last):
        File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/46f0c9813505c30d178a2aff399354ea/external/rules_python+/python/private/pypi/extension.bzl", line 607, column 25, in _pip_impl
                mods = parse_modules(module_ctx)
        File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/46f0c9813505c30d178a2aff399354ea/external/rules_python+/python/private/pypi/extension.bzl", line 478, column 36, in parse_modules
                out = _create_whl_repos(
        File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/46f0c9813505c30d178a2aff399354ea/external/rules_python+/python/private/pypi/extension.bzl", line 224, column 25, in _create_whl_repos
                fail("Attempting to creating a duplicate library {} for {}".format(
Error in fail: Attempting to creating a duplicate library pip_311_numpy_linux_aarch64_linux_arm_linux_ppc_linux_s390x_linux_x86_64_osx_aarch64_osx_x86_64_windows_x86_64 for numpy

Ideally rules_python would know that there should only be a single repo here since these constraints are mutually exclusive

馃敩 Minimal Reproduction

bazel build ... in #2798

馃實 Your Environment

Operating System:

  
linux x86_64
  

Output of bazel version:

  
8.2.1
  

Rules_python version:

c981569

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: pippip/pypi integration

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions