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.parse doesn't fetch anything with conflicting markers #2337

Closed
keith opened this issue Oct 24, 2024 · 2 comments · Fixed by #2377
Closed

pip.parse doesn't fetch anything with conflicting markers #2337

keith opened this issue Oct 24, 2024 · 2 comments · Fixed by #2377

Comments

@keith
Copy link
Member

keith commented Oct 24, 2024

If I have a requirements.in like this:

--extra-index-url https://download.pytorch.org/whl/cpu
torch==2.4.1; platform_machine != "x86_64"
torch==2.4.1+cpu; platform_machine == "x86_64"

Which I use to generate a universal requirements.txt with uv using: uv pip compile --universal requirements.in -o requirements_lock.txt --emit-index-url --no-strip-markers, I end up with multiple entries for torch in that lockfile:

SNIP
torch==2.4.1+cpu ; platform_machine == 'x86_64'
    # via -r requirements.in
torch==2.4.1 ; platform_machine != 'x86_64'
    # via -r requirements.in
SNIP

When I attempt to pull those in with:

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    hub_name = "pip",
    python_version = "3.11",
    requirements_lock = "//:requirements_lock.txt",
)
use_repo(pip, "pip")

and use them with:

load("@pip//:requirements.bzl", "requirement")

alias(
    name = "foo",
    actual = requirement("torch"),
)

It fails with:

ERROR: no such package '@@rules_python~~pip~pip//torch': BUILD file not found in directory 'torch' of external repository @@rules_python~~pip~pip. Add a BUILD file to a directory to mark it as a package.
ERROR: /tmp/pyrepro/BUILD.bazel:3:6: no such package '@@rules_python~~pip~pip//torch': BUILD file not found in directory 'torch' of external repository @@rules_python~~pip~pip. Add a BUILD file to a directory to mark it as a package. and referenced by '//:foo'

If I remove the non-matching entry from the lockfile it works, so I assume it's the nature of having 2 conflicting requirements even though they are disambiguated by the marker.

To repro in this project: repro.zip

Run bazel fetch ...

@aignas
Copy link
Collaborator

aignas commented Oct 25, 2024

I think the reason for this surprising behaviour is

# Replicate a surprising behavior that WORKSPACE builds allowed:

We would have to have a fix there and ensure that it works with env markers.

@ewianda
Copy link
Contributor

ewianda commented Nov 6, 2024

This can fixed by

experimental_index_url_overrides = {
      "torch": "https://download.pytorch.org/whl/cpu",
},

github-merge-queue bot pushed a commit that referenced this issue Nov 13, 2024
This just cleans up the code and moves more logic from the
repository_rule
(i.e. generation of `BUILD.bazel` files) to loading time (macro
evaluation).
This makes the unit testing easier and I plan to also move the code that
is
generating config setting names from filenames to this new macro, but
wanted to
submit this PR to reduce the review chunks.

Summary:
- Add a new `pkg_aliases` macro.
- Move logic and tests for creating WORKSPACE aliases.
- Move logic and tests bzlmod aliases.
- Move logic and tests bzlmod aliases with groups.
- Add a test for extra alias creation.
- Use `whl_alias` in `pypi` extension integration tests.
- Improve the serialization of `whl_alias` for passing to the pypi hub
repo.

Related to #260, #2386, #2337, #2319 - hopefully cleaning the code up
will make
it easier to address those feature requests later.

---------

Co-authored-by: Richard Levasseur <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Nov 18, 2024
…requirements files (#2377)

This change makes it possible to handle local versions of packages,
which is extremely useful with PyTorch. With this change, it is
possible to have different local versions of the same package in the
`requirements.txt` file translated to valid `whl_library` repositories.

Fixes #2337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants