Skip to content

Commit f948661

Browse files
committed
refactor(pypi): extract a function for deleting files recursively
1 parent fe43548 commit f948661

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
@@ -535,26 +535,28 @@ def _whl_library_impl(rctx):
535535
rctx.file("MODULE.bazel")
536536
rctx.file("REPO.bazel")
537537

538+
# BUILD files interfere with globbing and Bazel package boundaries.
539+
_remove_files(rctx, "BUILD", "BUILD.bazel")
540+
rctx.file("BUILD.bazel", build_file_contents)
541+
542+
if enable_pipstar and enable_pipstar_extract:
543+
if hasattr(rctx, "repo_metadata"):
544+
return rctx.repo_metadata(reproducible = True)
545+
546+
return None
547+
548+
def _remove_files(rctx, *basenames):
538549
paths = list(rctx.path(".").readdir())
539550
for _ in range(10000000):
540551
if not paths:
541552
break
542553
path = paths.pop()
543554

544-
# BUILD files interfere with globbing and Bazel package boundaries.
545-
if path.basename in ("BUILD", "BUILD.bazel"):
555+
if path.basename in basenames:
546556
rctx.delete(path)
547557
elif path.is_dir:
548558
paths.extend(path.readdir())
549559

550-
rctx.file("BUILD.bazel", build_file_contents)
551-
552-
if enable_pipstar and enable_pipstar_extract:
553-
if hasattr(rctx, "repo_metadata"):
554-
return rctx.repo_metadata(reproducible = True)
555-
556-
return None
557-
558560
def _generate_entry_point_contents(
559561
module,
560562
attribute,

0 commit comments

Comments
 (0)