Skip to content

Enable using experimental_index_url without having hashes in the lock file #2023

@aignas

Description

@aignas

🚀 feature request

Relevant Rules

pip.parse with experimental_index_url set to a non-empty value.

Description

Quite often the users create a requirements.txt file by just using pip freeze. This is not ideal, but it is the reality.

Describe the solution you'd like

Supporting the setting up of the select statements with all available wheels would be beneficial in making the code more robust. It would also enable to more easily support a niche usecase where bazel is used in an integration test where the latest package, so in there we have no version number and no hashes at all.

Describe alternatives you've considered

Do not do it and error without hashes specified. This might not work in cases where the hashes might not be required:

  • VCS URL. The sha is the hash, but we should instead just support the direct download URLs better in the experimental_index_url code path.
  • Direct download URL. The hash is something that we don't strictly need and bazel could just print a warning message that the hash needs to be added.

Description of the implementation

The parse_requirements function invokes get_index_urls which returns a dict where we have the package URLS by its sha256 hash. Then a subsequent call to _add_dists would get all of the files for a particular distribution based on the hash.

Changes needed:

  • Change _add_dists so that it gets all of the files by hash only if at least one hash is provided, otherwise, get values by version.
  • Add unit tests under //tests/pypi/parse_requirements

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions