Skip to content

pip.parse fails for a package with multiple extras over multiple requirements files #3374

@hartikainen

Description

@hartikainen

🐞 bug report

This has already been discussed in #2797 and #3193 but I wanted to open an issue for tracking purposes.

Affected Rule

pip.parse.

Is this a regression?

No.

Description

Installing a package with two different extras in two different platform fails. A simplified example of requirements files that fail:
requirements.linux_arm64.txt:

package==0.7.0 \
    --hash=sha256:4dd8924f171ed73a4f1a6191e2f800ae1745069989b69fabc45593d6b6504003 \
    --hash=sha256:62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76

requirements.linux_x86_64.txt:

package[extra]==0.7.0 \
    --hash=sha256:62833036cbaf4641d66ae94c61c0446890a91b2c0d153946583a0ebe04877a76

This happens, I believe, because pip.parse tries to create a duplicate whl_library when a package is referenced multiple times with different extras.

🔬 Minimal Reproduction

See the _test_multiple_extras_multiple_requirements test case in main...hartikainen:rules_python:bug/multiple-platforms-with-extras-v2.

🔥 Exception or Error

Exception
$ bazel test //tests/pypi/hub_builder:test_multiple_extras_multiple_requirements
ERROR: /Users/user/bazel-contrib/rules_python/main/tests/pypi/hub_builder/BUILD.bazel:3:23: in test_multiple_extras_multiple_requirements_test rule //tests/pypi/hub_builder:test_multiple_extras_multiple_requirements:
Traceback (most recent call last):
        File "/Users/user/.cache/bazel/_bazel_user/07a78f2e19ea2b267dc879919d0b00c5/external/rules_testing+/lib/private/analysis_test.bzl", line 309, column 13, in wrapped_impl
                impl(env, target)
        File "/Users/user/.cache/bazel/_bazel_user/07a78f2e19ea2b267dc879919d0b00c5/external/rules_testing+/lib/unit_test.bzl", line 43, column 40, in lambda
                impl = lambda env, target: impl(env),
        File "/Users/user/bazel-contrib/rules_python/main/tests/pypi/hub_builder/hub_builder_tests.bzl", line 1150, column 22, in _test_multiple_extras_multiple_requirements
                builder.pip_parse(
        File "/Users/user/bazel-contrib/rules_python/main/python/private/pypi/hub_builder.bzl", line 58, column 47, in lambda
                pip_parse = lambda *a, **k: _pip_parse(self, *a, **k),
        File "/Users/user/bazel-contrib/rules_python/main/python/private/pypi/hub_builder.bzl", line 125, column 22, in _pip_parse
                _create_whl_repos(
        File "/Users/user/bazel-contrib/rules_python/main/python/private/pypi/hub_builder.bzl", line 440, column 29, in _create_whl_repos
                _add_whl_library(
        File "/Users/user/bazel-contrib/rules_python/main/python/private/pypi/hub_builder.bzl", line 185, column 13, in _add_whl_library
                fail("attempting to create a duplicate library {} for {}".format(
Error in fail: attempting to create a duplicate library pypi_312_package_py3_none_any_62833036 for package
ERROR: /Users/user/bazel-contrib/rules_python/main/tests/pypi/hub_builder/BUILD.bazel:3:23: Analysis of target '//tests/pypi/hub_builder:test_multiple_extras_multiple_requirements' (config: c4919df) failed
ERROR: Analysis of target '//tests/pypi/hub_builder:test_multiple_extras_multiple_requirements' failed; build aborted
INFO: Elapsed time: 0.078s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: No test targets were found, yet testing was requested

🌍 Your Environment

Operating System:

$ lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:        24.04
Codename:       noble

Output of bazel version:

$ bazel --version
bazel 8.2.1

Rules_python version:

cf594f7

Anything else relevant?

Nope.

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