From 1ab491ecef497e9360135894945a7ba0b630275a Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Wed, 2 Apr 2025 23:50:58 +0900 Subject: [PATCH 1/2] fix(pypi): mark the extension reproducible This will remove the merge conflicts and improve the usability when the `MODULE.bazel.lock` is used together with `rules_python`. This means that the lock file will not be used to read the `URL` and `sha256` values for the Python sources when the `experimental_index_url` is used, but the idea is that that information will be kept in repo cache. Fixes #2434 --- CHANGELOG.md | 3 +++ python/private/pypi/extension.bzl | 6 +----- tests/pypi/extension/extension_tests.bzl | 7 ------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc742e6160..490506b38a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,9 @@ Unreleased changes template. * (toolchains) Remove all but `3.8.20` versions of the Python `3.8` interpreter who has reached EOL. If users still need other versions of the `3.8` interpreter, please supply the URLs manually {bzl:ob}`python.toolchain` or {bzl:obj}`python_register_toolchains` calls. +* (pypi) The PyPI extension will no longer write the lock file entries as the + extension has been marked reproducible. + Fixes [#2434](https://github.com/bazel-contrib/rules_python/issues/2434). [20250317]: https://github.com/astral-sh/python-build-standalone/releases/tag/20250317 diff --git a/python/private/pypi/extension.bzl b/python/private/pypi/extension.bzl index be3067d04a..d6871315c2 100644 --- a/python/private/pypi/extension.bzl +++ b/python/private/pypi/extension.bzl @@ -437,8 +437,6 @@ You cannot use both the additive_build_content and additive_build_content_file a extra_aliases = {} whl_libraries = {} - is_reproducible = True - for mod in module_ctx.modules: for pip_attr in mod.tags.parse: hub_name = pip_attr.hub_name @@ -476,7 +474,6 @@ You cannot use both the additive_build_content and additive_build_content_file a get_index_urls = None if pip_attr.experimental_index_url: - is_reproducible = False get_index_urls = lambda ctx, distributions: simpleapi_download( ctx, attr = struct( @@ -553,7 +550,6 @@ You cannot use both the additive_build_content and additive_build_content_file a k: dict(sorted(args.items())) for k, args in sorted(whl_libraries.items()) }, - is_reproducible = is_reproducible, ) def _pip_impl(module_ctx): @@ -650,7 +646,7 @@ def _pip_impl(module_ctx): # In order to be able to dogfood the `experimental_index_url` feature before it gets # stabilized, we have created the `_pip_non_reproducible` function, that will result # in extra entries in the lock file. - return module_ctx.extension_metadata(reproducible = mods.is_reproducible) + return module_ctx.extension_metadata(reproducible = True) else: return None diff --git a/tests/pypi/extension/extension_tests.bzl b/tests/pypi/extension/extension_tests.bzl index 1b18d2a339..12e8293345 100644 --- a/tests/pypi/extension/extension_tests.bzl +++ b/tests/pypi/extension/extension_tests.bzl @@ -64,7 +64,6 @@ def _parse_modules(env, **kwargs): return env.expect.that_struct( parse_modules(**kwargs), attrs = dict( - is_reproducible = subjects.bool, exposed_packages = subjects.dict, hub_group_map = subjects.dict, hub_whl_map = subjects.dict, @@ -160,7 +159,6 @@ def _test_simple(env): }, ) - pypi.is_reproducible().equals(True) pypi.exposed_packages().contains_exactly({"pypi": ["simple"]}) pypi.hub_group_map().contains_exactly({"pypi": {}}) pypi.hub_whl_map().contains_exactly({"pypi": { @@ -209,7 +207,6 @@ def _test_simple_multiple_requirements(env): }, ) - pypi.is_reproducible().equals(True) pypi.exposed_packages().contains_exactly({"pypi": ["simple"]}) pypi.hub_group_map().contains_exactly({"pypi": {}}) pypi.hub_whl_map().contains_exactly({"pypi": { @@ -286,7 +283,6 @@ torch==2.4.1 ; platform_machine != 'x86_64' \ }, ) - pypi.is_reproducible().equals(True) pypi.exposed_packages().contains_exactly({"pypi": ["torch"]}) pypi.hub_group_map().contains_exactly({"pypi": {}}) pypi.hub_whl_map().contains_exactly({"pypi": { @@ -421,7 +417,6 @@ torch==2.4.1+cpu ; platform_machine == 'x86_64' \ simpleapi_download = mocksimpleapi_download, ) - pypi.is_reproducible().equals(False) pypi.exposed_packages().contains_exactly({"pypi": ["torch"]}) pypi.hub_group_map().contains_exactly({"pypi": {}}) pypi.hub_whl_map().contains_exactly({"pypi": { @@ -552,7 +547,6 @@ simple==0.0.3 \ }, ) - pypi.is_reproducible().equals(True) pypi.exposed_packages().contains_exactly({"pypi": ["simple"]}) pypi.hub_group_map().contains_exactly({"pypi": {}}) pypi.hub_whl_map().contains_exactly({"pypi": { @@ -669,7 +663,6 @@ some_pkg==0.0.1 simpleapi_download = mocksimpleapi_download, ) - pypi.is_reproducible().equals(False) pypi.exposed_packages().contains_exactly({"pypi": ["simple", "some_pkg"]}) pypi.hub_group_map().contains_exactly({"pypi": {}}) pypi.hub_whl_map().contains_exactly({ From 84af52437f8b887a79a4e6fdb686e6f71e9342b1 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 6 Apr 2025 01:12:20 +0900 Subject: [PATCH 2/2] Update tests/pypi/extension/extension_tests.bzl --- tests/pypi/extension/extension_tests.bzl | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/pypi/extension/extension_tests.bzl b/tests/pypi/extension/extension_tests.bzl index 2dd1f8378d..1652e76156 100644 --- a/tests/pypi/extension/extension_tests.bzl +++ b/tests/pypi/extension/extension_tests.bzl @@ -667,7 +667,6 @@ git_dep @ git+https://git.server/repo/project@deadbeefdeadbeef simpleapi_download = mocksimpleapi_download, ) - pypi.exposed_packages().contains_exactly({"pypi": [ "direct_sdist_without_sha", "direct_without_sha",