Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ BEGIN_UNRELEASED_TEMPLATE
END_UNRELEASED_TEMPLATE
-->

{#v0-0-0}
## Unreleased

[0.0.0]: https://github.com/bazel-contrib/rules_python/releases/tag/0.0.0

{#v0-0-0-changed}
### Changed
* Nothing changed.

{#v0-0-0-fixed}
### Fixed
* Nothing fixed.

{#v0-0-0-added}
### Added
* (pypi) To configure the environment for `requirements.txt` evaluation, use the newly added
developer preview of the `pip.default` tag class. Only `rules_python` and root modules can use
this feature.

{#v0-0-0-removed}
### Removed
* Nothing removed.

{#1-5-0}
## [1.5.0] - 2025-06-11

Expand Down
5 changes: 3 additions & 2 deletions python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ bzl_library(
name = "evaluate_markers_bzl",
srcs = ["evaluate_markers.bzl"],
deps = [
":pep508_env_bzl",
":deps_bzl",
":pep508_evaluate_bzl",
":pep508_platform_bzl",
":pep508_requirement_bzl",
":pypi_repo_utils_bzl",
],
)

Expand All @@ -113,6 +113,7 @@ bzl_library(
":hub_repository_bzl",
":parse_requirements_bzl",
":parse_whl_name_bzl",
":pep508_env_bzl",
":pip_repository_attrs_bzl",
":simpleapi_download_bzl",
":whl_config_setting_bzl",
Expand Down
18 changes: 10 additions & 8 deletions python/private/pypi/evaluate_markers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
"""A simple function that evaluates markers using a python interpreter."""

load(":deps.bzl", "record_files")
load(":pep508_env.bzl", "env")
load(":pep508_evaluate.bzl", "evaluate")
load(":pep508_platform.bzl", "platform_from_str")
load(":pep508_requirement.bzl", "requirement")
load(":pypi_repo_utils.bzl", "pypi_repo_utils")

Expand All @@ -30,22 +28,26 @@ SRCS = [
Label("//python/private/pypi/whl_installer:platform.py"),
]

def evaluate_markers(requirements, python_version = None):
def evaluate_markers(*, requirements, platforms):
"""Return the list of supported platforms per requirements line.

Args:
requirements: {type}`dict[str, list[str]]` of the requirement file lines to evaluate.
python_version: {type}`str | None` the version that can be used when evaluating the markers.
platforms: {type}`dict[str | struct]` TODO

Returns:
dict of string lists with target platforms
"""
ret = {}
for req_string, platforms in requirements.items():
for req_string, platform_strings in requirements.items():
req = requirement(req_string)
for platform in platforms:
if evaluate(req.marker, env = env(platform_from_str(platform, python_version))):
ret.setdefault(req_string, []).append(platform)
for platform_str in platform_strings:
env = platforms.get(platform_str)
if not env:
fail("Please define platform: '{}'".format(platform_str))

if evaluate(req.marker, env = env):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We evaluate during the bzlmod phase to basically pre-filter, right?

e.g if you have {"linux": "requirements_universal.txt"}, then we're basically stripping out all the foo; os=="windows" lines so that we don't bother traversing (in the index) anything for foo for linux, and also avoid generating any targets for foo (for linux, anyways)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

ret.setdefault(req_string, []).append(platform_str)

return ret

Expand Down
Loading