Skip to content

Commit

Permalink
Mark internal deps extension as reproducible
Browse files Browse the repository at this point in the history
This avoids an unnecessary lockfile entry for users of rules_python.

Also adopts `bazel mod tidy` to update the `use_repo` call.
  • Loading branch information
fmeum committed May 12, 2024
1 parent 01ae7e7 commit 74d0e3d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0
7.1.2
1 change: 1 addition & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
1. Modify the `./python/pip_install/tools/requirements.txt` file and run:
```
bazel run //tools/private/update_deps:update_pip_deps
bazel mod tidy
```
1. Bump the coverage dependencies using the script using:
```
Expand Down
8 changes: 3 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module(
)

bazel_dep(name = "bazel_features", version = "1.9.1")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "platforms", version = "0.0.4")

Expand All @@ -14,11 +14,9 @@ bazel_dep(name = "rules_proto", version = "6.0.0-rc1")
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")

internal_deps = use_extension("//python/private/bzlmod:internal_deps.bzl", "internal_deps")
internal_deps.install()
use_repo(
internal_deps,
"rules_python_internal",
# START: maintained by 'bazel run //tools/private/update_deps:update_pip_deps'
# Updated by bazel mod tidy.
"pypi__build",
"pypi__click",
"pypi__colorama",
Expand All @@ -34,7 +32,7 @@ use_repo(
"pypi__tomli",
"pypi__wheel",
"pypi__zipp",
# END: maintained by 'bazel run //tools/private/update_deps:update_pip_deps'
"rules_python_internal",
)

# We need to do another use_extension call to expose the "pythons_hub"
Expand Down
13 changes: 5 additions & 8 deletions python/private/bzlmod/internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@

"Python toolchain module extension for internal rule use"

load("@bazel_skylib//lib:modules.bzl", "modules")
load("//python/pip_install:repositories.bzl", "pip_install_dependencies")
load("//python/private:internal_config_repo.bzl", "internal_config_repo")

# buildifier: disable=unused-variable
def _internal_deps_impl(module_ctx):
def _internal_deps():
internal_config_repo(name = "rules_python_internal")
pip_install_dependencies()

internal_deps = module_extension(
doc = "This extension to register internal rules_python dependecies.",
implementation = _internal_deps_impl,
tag_classes = {
"install": tag_class(attrs = dict()),
},
internal_deps = modules.as_extension(
_internal_deps,
doc = "This extension registers internal rules_python dependencies.",
)
2 changes: 0 additions & 2 deletions tools/private/update_deps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ py_binary(
name = "update_pip_deps",
srcs = ["update_pip_deps.py"],
data = [
"//:MODULE.bazel",
"//python/pip_install:repositories",
"//python/pip_install:requirements_txt",
],
env = {
"MODULE_BAZEL": "$(rlocationpath //:MODULE.bazel)",
"REPOSITORIES_BZL": "$(rlocationpath //python/pip_install:repositories)",
"REQUIREMENTS_TXT": "$(rlocationpath //python/pip_install:requirements_txt)",
},
Expand Down
22 changes: 0 additions & 22 deletions tools/private/update_deps/update_pip_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ def _dep_snippet(deps: list[Dep]) -> str:
return textwrap.indent("".join(lines), " " * 4)


def _module_snippet(deps: list[Dep]) -> str:
lines = []
for dep in deps:
lines.append(f'"{dep.name}",\n')

return textwrap.indent("".join(lines), " " * 4)


def _generate_report(requirements_txt: pathlib.Path) -> dict:
with tempfile.NamedTemporaryFile() as tmp:
tmp_path = pathlib.Path(tmp.name)
Expand Down Expand Up @@ -131,12 +123,6 @@ def main():
default=os.environ.get("REQUIREMENTS_TXT"),
help="The requirements.txt path for the pip_install tools, defaults to the value taken from REQUIREMENTS_TXT",
)
parser.add_argument(
"--module-bazel",
type=path_from_runfiles,
default=os.environ.get("MODULE_BAZEL"),
help="The path for the file to be updated, defaults to the value taken from MODULE_BAZEL",
)
parser.add_argument(
"--repositories-bzl",
type=path_from_runfiles,
Expand All @@ -156,14 +142,6 @@ def main():
dry_run=args.dry_run,
)

update_file(
path=args.module_bazel,
snippet=_module_snippet(deps),
start_marker=args.start,
end_marker=args.end,
dry_run=args.dry_run,
)


if __name__ == "__main__":
main()

0 comments on commit 74d0e3d

Please sign in to comment.