Skip to content

Commit 3f6daa8

Browse files
authored
refactor(pypi): extract a function for deleting files recursively (#3733)
It's high time we did some cleanup and I'd like to start modularizing the code a little to make future maintenance easier.
1 parent 1c38124 commit 3f6daa8

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

python/private/pypi/whl_library.bzl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -546,26 +546,28 @@ def _whl_library_impl(rctx):
546546
rctx.file("MODULE.bazel")
547547
rctx.file("REPO.bazel")
548548

549+
# BUILD files interfere with globbing and Bazel package boundaries.
550+
_remove_files(rctx, "BUILD", "BUILD.bazel")
551+
rctx.file("BUILD.bazel", build_file_contents)
552+
553+
if enable_pipstar and enable_pipstar_extract:
554+
if hasattr(rctx, "repo_metadata"):
555+
return rctx.repo_metadata(reproducible = True)
556+
557+
return None
558+
559+
def _remove_files(rctx, *basenames):
549560
paths = list(rctx.path(".").readdir())
550561
for _ in range(10000000):
551562
if not paths:
552563
break
553564
path = paths.pop()
554565

555-
# BUILD files interfere with globbing and Bazel package boundaries.
556-
if path.basename in ("BUILD", "BUILD.bazel"):
566+
if path.basename in basenames:
557567
rctx.delete(path)
558568
elif path.is_dir:
559569
paths.extend(path.readdir())
560570

561-
rctx.file("BUILD.bazel", build_file_contents)
562-
563-
if enable_pipstar and enable_pipstar_extract:
564-
if hasattr(rctx, "repo_metadata"):
565-
return rctx.repo_metadata(reproducible = True)
566-
567-
return None
568-
569571
def _generate_entry_point_contents(
570572
module,
571573
attribute,

0 commit comments

Comments
 (0)