From 3f6daa8ded64f0e32773aab83707bfb4afc5cf63 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 26 Apr 2026 12:24:43 +0900 Subject: [PATCH 1/2] 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. --- 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 5639d9143f..3586494dc2 100644 --- a/python/private/pypi/whl_library.bzl +++ b/python/private/pypi/whl_library.bzl @@ -546,26 +546,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, From b81b287f9f6554ba076e863d2c89843a84182e22 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 26 Apr 2026 14:11:07 +0900 Subject: [PATCH 2/2] fix(entry_point): ignore type lints on the generated files (#3736) Fixes #3126 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 ++ python/private/py_console_script_gen.py | 2 +- tests/entry_points/py_console_script_gen_test.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24a25f7421..225a1c1c00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,8 @@ END_UNRELEASED_TEMPLATE ### Fixed * (gazelle) Fixed handling of auto-included `__init__.py` files when generating `py_binary` targets ([#3729](https://github.com/bazel-contrib/rules_python/issues/3729)). +* (entry_point) From now on `mypy` type checking will be skipped on the generated + files ([#3126](https://github.com/bazel-contrib/rules_python/issues/3126)). {#v0-0-0-added} ### Added diff --git a/python/private/py_console_script_gen.py b/python/private/py_console_script_gen.py index 4b4f2f6986..a1df2c2a06 100644 --- a/python/private/py_console_script_gen.py +++ b/python/private/py_console_script_gen.py @@ -62,7 +62,7 @@ raise if __name__ == "__main__": - sys.exit({entry_point}()) + sys.exit({entry_point}()) # type: ignore """ diff --git a/tests/entry_points/py_console_script_gen_test.py b/tests/entry_points/py_console_script_gen_test.py index 1bbf5fbf25..77ad1a5faa 100644 --- a/tests/entry_points/py_console_script_gen_test.py +++ b/tests/entry_points/py_console_script_gen_test.py @@ -162,7 +162,7 @@ def test_a_single_entry_point(self): raise if __name__ == "__main__": - sys.exit(baz()) + sys.exit(baz()) # type: ignore """ ) self.assertEqual(want, got)