Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ END_UNRELEASED_TEMPLATE

{#v0-0-0-added}
### Added
* Nothing 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
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
2 changes: 1 addition & 1 deletion python/private/pypi/env_marker_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The {obj}`--//python/config_settings:pip_env_marker_config` flag.
The values to use for environment markers when evaluating an expression.

The keys and values should be compatible with the [PyPA dependency specifiers
specification](https://packaging.python.org/en/latest/specifications/dependency-specifiers/)
specification](https://packaging.python.org/en/latest/specifications/dependency-specifiers/).

Missing values will be set to the specification's defaults or computed using
available toolchain information.
Expand Down
19 changes: 11 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,27 @@ 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, dict[str, str]]` The environments that we for each requirement
file to evaluate. The keys between the platforms and requirements should be shared.

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):
ret.setdefault(req_string, []).append(platform_str)

return ret

Expand Down
Loading