fix(pypi): mark the extension reproducible (#2730)
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
Created #2731 to leverage the bazel feature to write immutable facts to
the lock file once it becomes available.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac41e81..69e9330 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -69,6 +69,9 @@
* (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 f782e69..8fce476 100644
--- a/python/private/pypi/extension.bzl
+++ b/python/private/pypi/extension.bzl
@@ -419,8 +419,6 @@
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
@@ -458,7 +456,6 @@
get_index_urls = None
if pip_attr.experimental_index_url:
- is_reproducible = False
skip_sources = [
normalize_name(s)
for s in pip_attr.simpleapi_skip
@@ -543,7 +540,6 @@
k: dict(sorted(args.items()))
for k, args in sorted(whl_libraries.items())
},
- is_reproducible = is_reproducible,
)
def _pip_impl(module_ctx):
@@ -640,7 +636,7 @@
# 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 ab7a135..1652e76 100644
--- a/tests/pypi/extension/extension_tests.bzl
+++ b/tests/pypi/extension/extension_tests.bzl
@@ -64,7 +64,6 @@
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 @@
},
)
- 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 @@
},
)
- 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": {
@@ -278,7 +275,6 @@
},
)
- 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": {
@@ -404,7 +400,6 @@
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": {
@@ -535,7 +530,6 @@
},
)
- 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": {
@@ -673,7 +667,6 @@
simpleapi_download = mocksimpleapi_download,
)
- pypi.is_reproducible().equals(False)
pypi.exposed_packages().contains_exactly({"pypi": [
"direct_sdist_without_sha",
"direct_without_sha",