Skip to content

Commit 45363a1

Browse files
fmeumaignas
andauthored
refactor: Mark internal and python extension as reproducible (#1892)
This avoids unnecessary lockfile entries for users of rules_python. --------- Co-authored-by: aignas <[email protected]>
1 parent 3744e4d commit 45363a1

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ A brief description of the categories of changes:
2323

2424
### Changed
2525

26+
* (deps): Bumped `bazel_skylib` to 1.6.1.
27+
* (bzlmod): The `python` and internal `rules_python` extensions have been
28+
marked as `reproducible` and will not include any lock file entries from now
29+
on.
30+
2631
### Fixed
2732

2833
* (gazelle) Remove `visibility` from `NonEmptyAttr`.
@@ -54,7 +59,7 @@ A brief description of the categories of changes:
5459
sorted in the attributes section. We are also removing values that are not
5560
default in order to reduce the size of the lock file.
5661
* (coverage) Bump `coverage.py` to [7.4.3](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst#version-743--2024-02-23).
57-
* (deps): Bumped bazel_features to 1.9.1 to detect optional support
62+
* (deps): Bumped `bazel_features` to 1.9.1 to detect optional support
5863
non-blocking downloads.
5964
* (deps): Updated `pip_tools` to >= 7.4.0
6065
* (toolchains): Change some old toolchain versions to use [20240224] release to

MODULE.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module(
55
)
66

77
bazel_dep(name = "bazel_features", version = "1.9.1")
8-
bazel_dep(name = "bazel_skylib", version = "1.3.0")
8+
bazel_dep(name = "bazel_skylib", version = "1.6.1")
99
bazel_dep(name = "rules_cc", version = "0.0.9")
1010
bazel_dep(name = "platforms", version = "0.0.4")
1111

@@ -14,7 +14,6 @@ bazel_dep(name = "rules_proto", version = "6.0.0-rc1")
1414
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
1515

1616
internal_deps = use_extension("//python/private/bzlmod:internal_deps.bzl", "internal_deps")
17-
internal_deps.install()
1817
use_repo(
1918
internal_deps,
2019
"rules_python_internal",

gazelle/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module(
44
compatibility_level = 1,
55
)
66

7-
bazel_dep(name = "bazel_skylib", version = "1.5.0")
7+
bazel_dep(name = "bazel_skylib", version = "1.6.1")
88
bazel_dep(name = "rules_python", version = "0.18.0")
99
bazel_dep(name = "rules_go", version = "0.41.0", repo_name = "io_bazel_rules_go")
1010
bazel_dep(name = "gazelle", version = "0.33.0", repo_name = "bazel_gazelle")

python/extensions/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bzl_library(
3737
visibility = ["//:__subpackages__"],
3838
deps = [
3939
"//python/private:util_bzl",
40+
"//python/private/bzlmod:bazel_features_bzl",
4041
"//python/private/bzlmod:python_bzl",
4142
],
4243
)

python/private/bzlmod/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bzl_library(
4545

4646
bzl_library(
4747
name = "bazel_features_bzl",
48-
srcs = ["@bazel_features//:bzl_files"],
48+
deps = ["@bazel_features//:features"],
4949
)
5050

5151
bzl_library(

python/private/bzlmod/internal_deps.bzl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88

99
"Python toolchain module extension for internal rule use"
1010

11+
load("@bazel_skylib//lib:modules.bzl", "modules")
1112
load("//python/pip_install:repositories.bzl", "pip_install_dependencies")
1213
load("//python/private:internal_config_repo.bzl", "internal_config_repo")
1314

14-
# buildifier: disable=unused-variable
15-
def _internal_deps_impl(module_ctx):
15+
def _internal_deps():
1616
internal_config_repo(name = "rules_python_internal")
1717
pip_install_dependencies()
1818

19-
internal_deps = module_extension(
20-
doc = "This extension to register internal rules_python dependecies.",
21-
implementation = _internal_deps_impl,
22-
tag_classes = {
23-
"install": tag_class(attrs = dict()),
24-
},
19+
internal_deps = modules.as_extension(
20+
_internal_deps,
21+
doc = "This extension registers internal rules_python dependencies.",
2522
)

python/private/bzlmod/python.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"Python toolchain module extensions for use with bzlmod"
1616

17+
load("@bazel_features//:features.bzl", "bazel_features")
1718
load("//python:repositories.bzl", "python_register_toolchains")
1819
load("//python/private:toolchains_repo.bzl", "multi_toolchain_aliases")
1920
load("//python/private:util.bzl", "IS_BAZEL_6_4_OR_HIGHER")
@@ -230,6 +231,11 @@ def _python_impl(module_ctx):
230231
debug_info = json.encode_indent(debug_info),
231232
)
232233

234+
if bazel_features.external_deps.extension_metadata_has_reproducible:
235+
return module_ctx.extension_metadata(reproducible = True)
236+
else:
237+
return None
238+
233239
def _fail_duplicate_module_toolchain_version(version, module):
234240
fail(("Duplicate module toolchain version: module '{module}' attempted " +
235241
"to use version '{version}' multiple times in itself").format(

0 commit comments

Comments
 (0)