Skip to content
Open
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
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pip = use_extension("//python/extensions:pip.bzl", "pip")
"//python/config_settings:_is_py_freethreaded_{}".format(
"yes" if freethreaded else "no",
),
"//python/config_settings:_is_py_linux_libc_glibc",
],
env = {"platform_version": "0"},
marker = "python_version >= '3.13'" if freethreaded else "",
Expand Down
42 changes: 0 additions & 42 deletions docs/api/rules_python/python/config_settings/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,48 +274,6 @@ the values used when environment markers are resolved at build time.
:::
::::

::::{bzl:flag} pip_whl
Set what distributions are used in the `pip` integration.

Values:
* `auto`: Prefer `whl` distributions if they are compatible with a target
platform, but fallback to `sdist`. This is the default.
* `only`: Only use `whl` distributions and error out if it is not available.
* `no`: Only use `sdist` distributions. The wheels will be built non-hermetically in the `whl_library` repository rule.
:::{versionadded} 0.33.0
:::
::::

::::{bzl:flag} pip_whl_osx_arch
Set what wheel types we should prefer when building on the OSX platform.

Values:
* `arch`: Prefer architecture specific wheels.
* `universal`: Prefer universal wheels that usually are bigger and contain binaries for both, Intel and ARM architectures in the same wheel.
:::{versionadded} 0.33.0
:::
::::

::::{bzl:flag} pip_whl_glibc_version
Set the minimum `glibc` version that the `py_binary` using `whl` distributions from a PyPI index should support.

Values:
* `""`: Select the lowest available version of each wheel giving you the maximum compatibility. This is the default.
* `X.Y`: The string representation of a `glibc` version. The allowed values depend on the `requirements.txt` lock file contents.
:::{versionadded} 0.33.0
:::
::::

::::{bzl:flag} pip_whl_muslc_version
Set the minimum `muslc` version that the `py_binary` using `whl` distributions from a PyPI index should support.

Values:
* `""`: Select the lowest available version of each wheel giving you the maximum compatibility. This is the default.
* `X.Y`: The string representation of a `muslc` version. The allowed values depend on the `requirements.txt` lock file contents.
:::{versionadded} 0.33.0
:::
::::

::::{bzl:flag} pip_whl_osx_version
Set the minimum `osx` version that the `py_binary` using `whl` distributions from a PyPI index should support.

Expand Down
5 changes: 0 additions & 5 deletions docs/pypi/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,6 @@ that by parsing the `whl` filename based on [PEP600], [PEP656] standards. This
allows the user to configure the behaviour by using the following publicly
available flags:
* {obj}`--@rules_python//python/config_settings:py_linux_libc` for selecting the Linux libc variant.
* {obj}`--@rules_python//python/config_settings:pip_whl` for selecting `whl` distribution preference.
* {obj}`--@rules_python//python/config_settings:pip_whl_osx_arch` for selecting MacOS wheel preference.
* {obj}`--@rules_python//python/config_settings:pip_whl_glibc_version` for selecting the GLIBC version compatibility.
* {obj}`--@rules_python//python/config_settings:pip_whl_muslc_version` for selecting the musl version compatibility.
* {obj}`--@rules_python//python/config_settings:pip_whl_osx_version` for selecting MacOS version compatibility.

[bazel_downloader]: https://bazel.build/rules/lib/builtins/repository_ctx#download
[pep600]: https://peps.python.org/pep-0600/
Expand Down
68 changes: 1 addition & 67 deletions python/config_settings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ load(
"VenvsUseDeclareSymlinkFlag",
rp_string_flag = "string_flag",
)
load(
"//python/private/pypi:flags.bzl",
"UniversalWhlFlag",
"UseWhlFlag",
"define_pypi_internal_flags",
)
load("//python/private/pypi:flags.bzl", "define_pypi_internal_flags")
load(":config_settings.bzl", "construct_config_settings")

filegroup(
Expand All @@ -34,10 +29,6 @@ construct_config_settings(
name = "construct_config_settings",
default_version = DEFAULT_PYTHON_VERSION,
documented_flags = [
":pip_whl",
":pip_whl_glibc_version",
":pip_whl_muslc_version",
":pip_whl_osx_arch",
":pip_whl_osx_version",
":py_freethreaded",
":py_linux_libc",
Expand Down Expand Up @@ -157,63 +148,6 @@ string_flag(

# pip.parse related flags

string_flag(
name = "pip_whl",
build_setting_default = UseWhlFlag.AUTO,
values = sorted(UseWhlFlag.__members__.values()),
# NOTE: Only public because it is used in pip hub repos.
visibility = ["//visibility:public"],
)

config_setting(
name = "is_pip_whl_auto",
flag_values = {
":pip_whl": UseWhlFlag.AUTO,
},
# NOTE: Only public because it is used in pip hub repos.
visibility = ["//visibility:public"],
)

config_setting(
name = "is_pip_whl_no",
flag_values = {
":pip_whl": UseWhlFlag.NO,
},
# NOTE: Only public because it is used in pip hub repos.
visibility = ["//visibility:public"],
)

config_setting(
name = "is_pip_whl_only",
flag_values = {
":pip_whl": UseWhlFlag.ONLY,
},
# NOTE: Only public because it is used in pip hub repos.
visibility = ["//visibility:public"],
)

string_flag(
name = "pip_whl_osx_arch",
build_setting_default = UniversalWhlFlag.ARCH,
values = sorted(UniversalWhlFlag.__members__.values()),
# NOTE: Only public because it is used in pip hub repos.
visibility = ["//visibility:public"],
)

string_flag(
name = "pip_whl_glibc_version",
build_setting_default = "",
# NOTE: Only public because it is used in pip hub repos.
visibility = ["//visibility:public"],
)

string_flag(
name = "pip_whl_muslc_version",
build_setting_default = "",
# NOTE: Only public because it is used in pip hub repos.
visibility = ["//visibility:public"],
)

string_flag(
name = "pip_whl_osx_version",
build_setting_default = "",
Expand Down
4 changes: 0 additions & 4 deletions python/private/common_labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ labels = struct(
EXEC_TOOLS_TOOLCHAIN = str(Label("//python/config_settings:exec_tools_toolchain")),
NONE = str(Label("//python:none")),
PIP_ENV_MARKER_CONFIG = str(Label("//python/config_settings:pip_env_marker_config")),
PIP_WHL = str(Label("//python/config_settings:pip_whl")),
PIP_WHL_GLIBC_VERSION = str(Label("//python/config_settings:pip_whl_glibc_version")),
PIP_WHL_MUSLC_VERSION = str(Label("//python/config_settings:pip_whl_muslc_version")),
PIP_WHL_OSX_ARCH = str(Label("//python/config_settings:pip_whl_osx_arch")),
PIP_WHL_OSX_VERSION = str(Label("//python/config_settings:pip_whl_osx_version")),
PLATFORMS_OS_WINDOWS = str(Label("@platforms//os:windows")),
PRECOMPILE = str(Label("//python/config_settings:precompile")),
Expand Down
1 change: 0 additions & 1 deletion python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ bzl_library(
deps = [
":env_marker_info.bzl",
":pep508_env_bzl",
"//python/private:enum_bzl",
"@bazel_skylib//rules:common_settings",
],
)
Expand Down
74 changes: 1 addition & 73 deletions python/private/pypi/flags.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ NOTE: The transitive loads of this should be kept minimal. This avoids loading
unnecessary files when all that are needed are flag definitions.
"""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo", "string_flag")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//python/private:common_labels.bzl", "labels")
load("//python/private:enum.bzl", "enum")
load(":env_marker_info.bzl", "EnvMarkerInfo")
load(
":pep508_env.bzl",
Expand All @@ -31,87 +30,16 @@ load(
"sys_platform_select_map",
)

# Determines if we should use whls for third party
#
# buildifier: disable=name-conventions
UseWhlFlag = enum(
# Automatically decide the effective value based on environment, target
# platform and the presence of distributions for a particular package.
AUTO = "auto",
# Do not use `sdist` and fail if there are no available whls suitable for the target platform.
ONLY = "only",
# Do not use whl distributions and instead build the whls from `sdist`.
NO = "no",
)

# Determines whether universal wheels should be preferred over arch platform specific ones.
#
# buildifier: disable=name-conventions
UniversalWhlFlag = enum(
# Prefer platform-specific wheels over universal wheels.
ARCH = "arch",
# Prefer universal wheels over platform-specific wheels.
UNIVERSAL = "universal",
)

_STRING_FLAGS = [
"dist",
"whl_plat",
"whl_plat_py3",
"whl_plat_py3_abi3",
"whl_plat_pycp3x",
"whl_plat_pycp3x_abi3",
"whl_plat_pycp3x_abicp",
"whl_py3",
"whl_py3_abi3",
"whl_pycp3x",
"whl_pycp3x_abi3",
"whl_pycp3x_abicp",
]

INTERNAL_FLAGS = [
"whl",
] + _STRING_FLAGS

def define_pypi_internal_flags(name):
"""define internal PyPI flags used in PyPI hub repository by pkg_aliases.

Args:
name: not used
"""
for flag in _STRING_FLAGS:
string_flag(
name = "_internal_pip_" + flag,
build_setting_default = "",
values = [""],
visibility = ["//visibility:public"],
)

_allow_wheels_flag(
name = "_internal_pip_whl",
visibility = ["//visibility:public"],
)

_default_env_marker_config(
name = "_pip_env_marker_default_config",
)

def _allow_wheels_flag_impl(ctx):
input = ctx.attr._setting[BuildSettingInfo].value
value = "yes" if input in ["auto", "only"] else "no"
return [config_common.FeatureFlagInfo(value = value)]

_allow_wheels_flag = rule(
implementation = _allow_wheels_flag_impl,
attrs = {
"_setting": attr.label(default = labels.PIP_WHL),
},
doc = """
This rule allows us to greatly reduce the number of config setting targets at no cost even
if we are duplicating some of the functionality of the `native.config_setting`.
""",
)

def _default_env_marker_config(**kwargs):
_env_marker_config(
os_name = select(os_name_select_map),
Expand Down
4 changes: 2 additions & 2 deletions python/private/pypi/hub_builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load("//python/private:text_util.bzl", "render")
load("//python/private:version.bzl", "version")
load("//python/private:version_label.bzl", "version_label")
load(":attrs.bzl", "use_isolated")
load(":evaluate_markers.bzl", evaluate_markers_star = "evaluate_markers")
load(":evaluate_markers.bzl", "evaluate_markers")
load(":parse_requirements.bzl", "parse_requirements")
load(":pep508_env.bzl", "env")
load(":pep508_evaluate.bzl", "evaluate")
Expand Down Expand Up @@ -469,7 +469,7 @@ def _evaluate_markers(self, pip_attr):
if self._evaluate_markers_fn:
return self._evaluate_markers_fn

return lambda _, requirements: evaluate_markers_star(
return lambda requirements: evaluate_markers(
requirements = requirements,
platforms = self._platforms[pip_attr.python_version],
)
Expand Down
4 changes: 2 additions & 2 deletions python/private/pypi/parse_requirements.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parse_requirements(

The second element is extra_pip_args should be passed to `whl_library`.
"""
evaluate_markers = evaluate_markers or (lambda _ctx, _requirements: {})
evaluate_markers = evaluate_markers or (lambda _requirements: {})
options = {}
requirements = {}
reqs_with_env_markers = {}
Expand Down Expand Up @@ -130,7 +130,7 @@ def parse_requirements(

# This may call to Python, so execute it early (before calling to the
# internet below) and ensure that we call it only once.
resolved_marker_platforms = evaluate_markers(ctx, reqs_with_env_markers)
resolved_marker_platforms = evaluate_markers(reqs_with_env_markers)
logger.trace(lambda: "Evaluated env markers from:\n{}\n\nTo:\n{}".format(
reqs_with_env_markers,
resolved_marker_platforms,
Expand Down
6 changes: 3 additions & 3 deletions python/private/pypi/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def _pip_repository_impl(rctx):
python_interpreter = rctx.attr.python_interpreter,
python_interpreter_target = rctx.attr.python_interpreter_target,
)
result = rctx.execute([python_interpreter, "--version"])
result = rctx.execute([python_interpreter, "-c", "import sys; print(sys.version.split()[0])"])
if result.stdout:
python_version = result.stdout.strip().split(" ")[-1]
python_version = result.stdout.strip()
else:
fail("Could not determine Python version")
platforms = [
Expand Down Expand Up @@ -120,7 +120,7 @@ def _pip_repository_impl(rctx):
platforms = platforms,
),
extra_pip_args = rctx.attr.extra_pip_args,
evaluate_markers = lambda rctx, requirements: evaluate_markers(
evaluate_markers = lambda requirements: evaluate_markers(
requirements = {
# NOTE @aignas 2025-07-07: because we don't distinguish between
# freethreaded and non-freethreaded, it is a 1:1 mapping.
Expand Down
10 changes: 1 addition & 9 deletions python/private/pypi/whl_installer/wheel_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,13 @@ def _parse_requirement_for_extra(

def _extract_wheel(
wheel_file: str,
extras: Dict[str, Set[str]],
installation_dir: Path = Path("."),
) -> None:
"""Extracts wheel into given directory and creates py_library and filegroup targets.

Args:
wheel_file: the filepath of the .whl
installation_dir: the destination directory for installation of the wheel.
extras: a list of extras to add as dependencies for the installed wheel
"""

whl = wheel.Wheel(wheel_file)
Expand All @@ -103,13 +101,7 @@ def main() -> None:

if args.whl_file:
whl = Path(args.whl_file)

name, extras_for_pkg = _parse_requirement_for_extra(args.requirement)
extras = {name: extras_for_pkg} if extras_for_pkg and name else dict()
_extract_wheel(
wheel_file=whl,
extras=extras,
)
_extract_wheel(wheel_file=whl)
return

pip_args = (
Expand Down
4 changes: 0 additions & 4 deletions python/private/transition_labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ _BASE_TRANSITION_LABELS = [
labels.DEBUGGER,
labels.EXEC_TOOLS_TOOLCHAIN,
labels.PIP_ENV_MARKER_CONFIG,
labels.PIP_WHL_MUSLC_VERSION,
labels.PIP_WHL,
labels.PIP_WHL_GLIBC_VERSION,
labels.PIP_WHL_OSX_ARCH,
labels.PIP_WHL_OSX_VERSION,
labels.PRECOMPILE,
labels.PRECOMPILE_SOURCE_RETENTION,
Expand Down
7 changes: 0 additions & 7 deletions tests/pypi/config_settings/config_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ _subject = rule(

_flag = struct(
platform = lambda x: ("//command_line_option:platforms", str(Label("//tests/support/platforms:" + x))),
pip_whl = lambda x: (str(Label("//python/config_settings:pip_whl")), str(x)),
pip_whl_glibc_version = lambda x: (str(Label("//python/config_settings:pip_whl_glibc_version")), str(x)),
pip_whl_muslc_version = lambda x: (str(Label("//python/config_settings:pip_whl_muslc_version")), str(x)),
pip_whl_osx_version = lambda x: (str(Label("//python/config_settings:pip_whl_osx_version")), str(x)),
pip_whl_osx_arch = lambda x: (str(Label("//python/config_settings:pip_whl_osx_arch")), str(x)),
py_linux_libc = lambda x: (str(Label("//python/config_settings:py_linux_libc")), str(x)),
python_version = lambda x: (str(Label("//python/config_settings:python_version")), str(x)),
py_freethreaded = lambda x: (str(Label("//python/config_settings:py_freethreaded")), str(x)),
)

def _analysis_test(*, name, dist, want, config_settings = [_flag.platform("linux_aarch64")]):
Expand Down
2 changes: 1 addition & 1 deletion tests/pypi/hub_builder/hub_builder_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def _test_simple_with_markers(env):
for (host_os, host_arch), want_requirement in sub_tests.items():
builder = hub_builder(
env,
evaluate_markers_fn = lambda _, requirements, **__: {
evaluate_markers_fn = lambda requirements: {
key: [
platform
for platform in platforms
Expand Down
Loading