Skip to content

Commit 5b1db07

Browse files
aignasrickeylev
andauthored
feat(pypi): pip.defaults API for customizing pipstar 1/n (bazel-contrib#2987)
Parse env markers in pip.parse using starlark Summary: - Allow switching to the Starlark implementation of the marker evaluation function. - Add a way for users to modify the `env` for the marker evaluation when parsing the requirements. This can only be done by `rules_python` or the root module. - Limit the platform selection when parsing the requirements files. Work towards bazel-contrib#2747 Work towards bazel-contrib#2949 Split out from bazel-contrib#2909 --------- Co-authored-by: Richard Levasseur <richardlev@gmail.com>
1 parent 175a336 commit 5b1db07

File tree

10 files changed

+437
-69
lines changed

10 files changed

+437
-69
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ END_UNRELEASED_TEMPLATE
6262

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

6769
{#v0-0-0-removed}
6870
### Removed

python/private/pypi/BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ bzl_library(
9797
name = "evaluate_markers_bzl",
9898
srcs = ["evaluate_markers.bzl"],
9999
deps = [
100-
":pep508_env_bzl",
100+
":deps_bzl",
101101
":pep508_evaluate_bzl",
102-
":pep508_platform_bzl",
103102
":pep508_requirement_bzl",
103+
":pypi_repo_utils_bzl",
104104
],
105105
)
106106

@@ -113,6 +113,7 @@ bzl_library(
113113
":hub_repository_bzl",
114114
":parse_requirements_bzl",
115115
":parse_whl_name_bzl",
116+
":pep508_env_bzl",
116117
":pip_repository_attrs_bzl",
117118
":simpleapi_download_bzl",
118119
":whl_config_setting_bzl",

python/private/pypi/env_marker_info.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The {obj}`--//python/config_settings:pip_env_marker_config` flag.
1717
The values to use for environment markers when evaluating an expression.
1818
1919
The keys and values should be compatible with the [PyPA dependency specifiers
20-
specification](https://packaging.python.org/en/latest/specifications/dependency-specifiers/)
20+
specification](https://packaging.python.org/en/latest/specifications/dependency-specifiers/).
2121
2222
Missing values will be set to the specification's defaults or computed using
2323
available toolchain information.

python/private/pypi/evaluate_markers.bzl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
"""A simple function that evaluates markers using a python interpreter."""
1616

1717
load(":deps.bzl", "record_files")
18-
load(":pep508_env.bzl", "env")
1918
load(":pep508_evaluate.bzl", "evaluate")
20-
load(":pep508_platform.bzl", "platform_from_str")
2119
load(":pep508_requirement.bzl", "requirement")
2220
load(":pypi_repo_utils.bzl", "pypi_repo_utils")
2321

@@ -30,22 +28,27 @@ SRCS = [
3028
Label("//python/private/pypi/whl_installer:platform.py"),
3129
]
3230

33-
def evaluate_markers(requirements, python_version = None):
31+
def evaluate_markers(*, requirements, platforms):
3432
"""Return the list of supported platforms per requirements line.
3533
3634
Args:
3735
requirements: {type}`dict[str, list[str]]` of the requirement file lines to evaluate.
38-
python_version: {type}`str | None` the version that can be used when evaluating the markers.
36+
platforms: {type}`dict[str, dict[str, str]]` The environments that we for each requirement
37+
file to evaluate. The keys between the platforms and requirements should be shared.
3938
4039
Returns:
4140
dict of string lists with target platforms
4241
"""
4342
ret = {}
44-
for req_string, platforms in requirements.items():
43+
for req_string, platform_strings in requirements.items():
4544
req = requirement(req_string)
46-
for platform in platforms:
47-
if evaluate(req.marker, env = env(platform_from_str(platform, python_version))):
48-
ret.setdefault(req_string, []).append(platform)
45+
for platform_str in platform_strings:
46+
env = platforms.get(platform_str)
47+
if not env:
48+
fail("Please define platform: '{}'".format(platform_str))
49+
50+
if evaluate(req.marker, env = env):
51+
ret.setdefault(req_string, []).append(platform_str)
4952

5053
return ret
5154

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy