From f948661b6fba53ffae239a2deebf0aa74b594dbd Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Fri, 24 Apr 2026 23:24:31 +0900 Subject: [PATCH] refactor(pypi): extract a function for deleting files recursively --- python/private/pypi/whl_library.bzl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/python/private/pypi/whl_library.bzl b/python/private/pypi/whl_library.bzl index 31da3b94cb..a4e145a051 100644 --- a/python/private/pypi/whl_library.bzl +++ b/python/private/pypi/whl_library.bzl @@ -535,26 +535,28 @@ def _whl_library_impl(rctx): rctx.file("MODULE.bazel") rctx.file("REPO.bazel") + # BUILD files interfere with globbing and Bazel package boundaries. + _remove_files(rctx, "BUILD", "BUILD.bazel") + rctx.file("BUILD.bazel", build_file_contents) + + if enable_pipstar and enable_pipstar_extract: + if hasattr(rctx, "repo_metadata"): + return rctx.repo_metadata(reproducible = True) + + return None + +def _remove_files(rctx, *basenames): paths = list(rctx.path(".").readdir()) for _ in range(10000000): if not paths: break path = paths.pop() - # BUILD files interfere with globbing and Bazel package boundaries. - if path.basename in ("BUILD", "BUILD.bazel"): + if path.basename in basenames: rctx.delete(path) elif path.is_dir: paths.extend(path.readdir()) - rctx.file("BUILD.bazel", build_file_contents) - - if enable_pipstar and enable_pipstar_extract: - if hasattr(rctx, "repo_metadata"): - return rctx.repo_metadata(reproducible = True) - - return None - def _generate_entry_point_contents( module, attribute,