From 5f6fe90bf2c8099fa1028c57788bf4bc5d1a7978 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:35:17 +0900 Subject: [PATCH 1/4] wip --- MODULE.bazel | 1 + .../python/config_settings/index.md | 42 ----------- docs/pypi/download.md | 5 -- python/config_settings/BUILD.bazel | 68 +---------------- python/private/common_labels.bzl | 4 - python/private/pypi/BUILD.bazel | 1 - python/private/pypi/flags.bzl | 74 +------------------ python/private/pypi/hub_builder.bzl | 4 +- python/private/pypi/pip_repository.bzl | 4 +- .../pypi/whl_installer/wheel_installer.py | 10 +-- python/private/transition_labels.bzl | 4 - .../config_settings/config_settings_tests.bzl | 7 -- .../whl_installer/wheel_installer_test.py | 1 - 13 files changed, 8 insertions(+), 217 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index b5f67c204e..befa987eb1 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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 "", diff --git a/docs/api/rules_python/python/config_settings/index.md b/docs/api/rules_python/python/config_settings/index.md index 19f5b8bc37..0eb531e6a3 100644 --- a/docs/api/rules_python/python/config_settings/index.md +++ b/docs/api/rules_python/python/config_settings/index.md @@ -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. diff --git a/docs/pypi/download.md b/docs/pypi/download.md index d4159eb3a7..f0e70cf850 100644 --- a/docs/pypi/download.md +++ b/docs/pypi/download.md @@ -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/ diff --git a/python/config_settings/BUILD.bazel b/python/config_settings/BUILD.bazel index fc0ac51451..5b1317872f 100644 --- a/python/config_settings/BUILD.bazel +++ b/python/config_settings/BUILD.bazel @@ -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( @@ -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", @@ -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 = "", diff --git a/python/private/common_labels.bzl b/python/private/common_labels.bzl index b6594cf0b9..ff4e7e1dad 100644 --- a/python/private/common_labels.bzl +++ b/python/private/common_labels.bzl @@ -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")), diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index e7d19ea636..b11013f10e 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -145,7 +145,6 @@ bzl_library( deps = [ ":env_marker_info.bzl", ":pep508_env_bzl", - "//python/private:enum_bzl", "@bazel_skylib//rules:common_settings", ], ) diff --git a/python/private/pypi/flags.bzl b/python/private/pypi/flags.bzl index f88690d843..36cb5373ff 100644 --- a/python/private/pypi/flags.bzl +++ b/python/private/pypi/flags.bzl @@ -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", @@ -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), diff --git a/python/private/pypi/hub_builder.bzl b/python/private/pypi/hub_builder.bzl index 85a31cfc3c..1bce648dce 100644 --- a/python/private/pypi/hub_builder.bzl +++ b/python/private/pypi/hub_builder.bzl @@ -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") @@ -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], ) diff --git a/python/private/pypi/pip_repository.bzl b/python/private/pypi/pip_repository.bzl index b449f8dd85..aee05469c5 100644 --- a/python/private/pypi/pip_repository.bzl +++ b/python/private/pypi/pip_repository.bzl @@ -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 = [ diff --git a/python/private/pypi/whl_installer/wheel_installer.py b/python/private/pypi/whl_installer/wheel_installer.py index 1f00068060..c5ad14eaf7 100644 --- a/python/private/pypi/whl_installer/wheel_installer.py +++ b/python/private/pypi/whl_installer/wheel_installer.py @@ -79,7 +79,6 @@ 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. @@ -87,7 +86,6 @@ def _extract_wheel( 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) @@ -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 = ( diff --git a/python/private/transition_labels.bzl b/python/private/transition_labels.bzl index 04fcecb5ec..5f0aa69056 100644 --- a/python/private/transition_labels.bzl +++ b/python/private/transition_labels.bzl @@ -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, diff --git a/tests/pypi/config_settings/config_settings_tests.bzl b/tests/pypi/config_settings/config_settings_tests.bzl index ed95bd4877..c7e51b78b4 100644 --- a/tests/pypi/config_settings/config_settings_tests.bzl +++ b/tests/pypi/config_settings/config_settings_tests.bzl @@ -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")]): diff --git a/tests/pypi/whl_installer/wheel_installer_test.py b/tests/pypi/whl_installer/wheel_installer_test.py index 52c44cf2de..a03a10a8a7 100644 --- a/tests/pypi/whl_installer/wheel_installer_test.py +++ b/tests/pypi/whl_installer/wheel_installer_test.py @@ -71,7 +71,6 @@ def test_wheel_exists(self) -> None: wheel_installer._extract_wheel( Path(self.wheel_path), installation_dir=Path(self.wheel_dir), - extras={}, ) want_files = [ From 60b889481a1823ac57e254bf3c92d5eae9249154 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:42:45 +0900 Subject: [PATCH 2/4] fixup marker signature --- python/private/pypi/parse_requirements.bzl | 4 ++-- tests/pypi/parse_requirements/parse_requirements_tests.bzl | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/python/private/pypi/parse_requirements.bzl b/python/private/pypi/parse_requirements.bzl index 2a7793212a..d047cc607d 100644 --- a/python/private/pypi/parse_requirements.bzl +++ b/python/private/pypi/parse_requirements.bzl @@ -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 = {} @@ -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, diff --git a/tests/pypi/parse_requirements/parse_requirements_tests.bzl b/tests/pypi/parse_requirements/parse_requirements_tests.bzl index 1786c4e664..4ed1870309 100644 --- a/tests/pypi/parse_requirements/parse_requirements_tests.bzl +++ b/tests/pypi/parse_requirements/parse_requirements_tests.bzl @@ -433,7 +433,7 @@ def _test_select_requirement_none_platform(env): _tests.append(_test_select_requirement_none_platform) def _test_env_marker_resolution(env): - def _mock_eval_markers(_, input): + def _mock_eval_markers(input): ret = { "foo[extra]==0.0.1 ;marker --hash=sha256:deadbeef": ["cp311_windows_x86_64"], } @@ -781,7 +781,7 @@ def _test_get_index_urls_different_versions(env): }, ), }, - evaluate_markers = lambda _, requirements: evaluate_markers( + evaluate_markers = lambda requirements: evaluate_markers( requirements = requirements, platforms = { "cp310_linux_x86_64": struct( @@ -859,7 +859,7 @@ def _test_get_index_urls_single_py_version(env): }, ), }, - evaluate_markers = lambda _, requirements: evaluate_markers( + evaluate_markers = lambda requirements: evaluate_markers( requirements = requirements, platforms = { "cp310_linux_x86_64": struct( From fa78923df28e083579664e6a04505c289288824b Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:47:25 +0900 Subject: [PATCH 3/4] fixup evaluate_markers signature in WORKSPACE --- python/private/pypi/pip_repository.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/private/pypi/pip_repository.bzl b/python/private/pypi/pip_repository.bzl index aee05469c5..b09ac892d0 100644 --- a/python/private/pypi/pip_repository.bzl +++ b/python/private/pypi/pip_repository.bzl @@ -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. From aabe01f8a10c2ee0a82b235484cc61a6635a16b8 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 27 Apr 2026 22:51:30 +0900 Subject: [PATCH 4/4] fix hub_builder --- tests/pypi/hub_builder/hub_builder_tests.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pypi/hub_builder/hub_builder_tests.bzl b/tests/pypi/hub_builder/hub_builder_tests.bzl index ccf72c2774..216528fc9b 100644 --- a/tests/pypi/hub_builder/hub_builder_tests.bzl +++ b/tests/pypi/hub_builder/hub_builder_tests.bzl @@ -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