From c74a8cecb48e1f1ff8ef0f26f1701a07a0772157 Mon Sep 17 00:00:00 2001 From: yushan Date: Mon, 16 Jun 2025 19:51:42 +0000 Subject: [PATCH 1/5] (gazelle) Always generate BUILD rules in a new folder regardless if it has entrypoint file --- gazelle/python/generate.go | 2 -- gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out | 2 +- gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/gazelle/python/generate.go b/gazelle/python/generate.go index 5eedbd9601..2f7ee02036 100644 --- a/gazelle/python/generate.go +++ b/gazelle/python/generate.go @@ -85,8 +85,6 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes if parent != nil && parent.CoarseGrainedGeneration() { return language.GenerateResult{} } - } else if !hasEntrypointFile(args.Dir) { - return language.GenerateResult{} } } diff --git a/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out index 1c56f722d4..5f131b5730 100644 --- a/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out +++ b/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out @@ -11,5 +11,5 @@ py_binary( srcs = ["__main__.py"], main = "__main__.py", visibility = ["//:__subpackages__"], - deps = [":has_main"], + deps = ["//foo"], ) diff --git a/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out index a99278ec79..0ce1c5d378 100644 --- a/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out +++ b/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out @@ -10,5 +10,5 @@ py_test( name = "has_test_test", srcs = ["__test__.py"], main = "__test__.py", - deps = [":has_test"], + deps = ["//foo"], ) From d11a7c5b2e130e05adabb1af32444f1fd693d4fb Mon Sep 17 00:00:00 2001 From: yushan Date: Mon, 16 Jun 2025 20:06:07 +0000 Subject: [PATCH 2/5] update --- gazelle/python/testdata/subdir_sources/BUILD.in | 1 + gazelle/python/testdata/subdir_sources/BUILD.out | 3 +++ gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out | 2 +- gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gazelle/python/testdata/subdir_sources/BUILD.in b/gazelle/python/testdata/subdir_sources/BUILD.in index e69de29bb2..adfdefdc8a 100644 --- a/gazelle/python/testdata/subdir_sources/BUILD.in +++ b/gazelle/python/testdata/subdir_sources/BUILD.in @@ -0,0 +1 @@ +# gazelle:python_generation_mode project diff --git a/gazelle/python/testdata/subdir_sources/BUILD.out b/gazelle/python/testdata/subdir_sources/BUILD.out index d03a8f05ac..5d77890d4f 100644 --- a/gazelle/python/testdata/subdir_sources/BUILD.out +++ b/gazelle/python/testdata/subdir_sources/BUILD.out @@ -1,5 +1,8 @@ + load("@rules_python//python:defs.bzl", "py_binary") +# gazelle:python_generation_mode project + py_binary( name = "subdir_sources_bin", srcs = ["__main__.py"], diff --git a/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out index 5f131b5730..1c56f722d4 100644 --- a/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out +++ b/gazelle/python/testdata/subdir_sources/foo/has_main/BUILD.out @@ -11,5 +11,5 @@ py_binary( srcs = ["__main__.py"], main = "__main__.py", visibility = ["//:__subpackages__"], - deps = ["//foo"], + deps = [":has_main"], ) diff --git a/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out b/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out index 0ce1c5d378..a99278ec79 100644 --- a/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out +++ b/gazelle/python/testdata/subdir_sources/foo/has_test/BUILD.out @@ -10,5 +10,5 @@ py_test( name = "has_test_test", srcs = ["__test__.py"], main = "__test__.py", - deps = ["//foo"], + deps = [":has_test"], ) From 3ae39ee51d213bb735b12258571a93c67a05000a Mon Sep 17 00:00:00 2001 From: yushan Date: Mon, 23 Jun 2025 17:53:24 +0000 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4facff4917..f5f058a595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ END_UNRELEASED_TEMPLATE to the package path. This is enabled via the `# gazelle:experimental_allow_relative_imports` true directive ({gh-issue}`2203`). * (gazelle) Types for exposed members of `python.ParserOutput` are now all public. +* (gazelle) Remove entry point file requirements when generating rules. {#v0-0-0-fixed} ### Fixed From 24cee46703932b190e83a3224244e27a4f59830b Mon Sep 17 00:00:00 2001 From: yushan Date: Mon, 30 Jun 2025 16:44:41 +0000 Subject: [PATCH 4/5] Remove entrypoint requirements to generate .py files --- gazelle/python/generate.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gazelle/python/generate.go b/gazelle/python/generate.go index 2f7ee02036..c1edec4731 100644 --- a/gazelle/python/generate.go +++ b/gazelle/python/generate.go @@ -170,9 +170,6 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes // 2. The directory has a BUILD or BUILD.bazel files. Then // it doesn't matter at all what it has since it's a // separate Bazel package. - // 3. (only for package generation) The directory has an - // __init__.py, __main__.py or __test__.py, meaning a - // BUILD file will be generated. if cfg.PerFileGeneration() { return fs.SkipDir } @@ -182,7 +179,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes return nil } - if !cfg.CoarseGrainedGeneration() && hasEntrypointFile(path) { + if !cfg.CoarseGrainedGeneration() { return fs.SkipDir } From d4c362b13864d512193f56af7f98d308a18eaf0e Mon Sep 17 00:00:00 2001 From: yushan Date: Tue, 1 Jul 2025 18:01:51 +0000 Subject: [PATCH 5/5] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f058a595..9bc4e7b7b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,7 +58,8 @@ END_UNRELEASED_TEMPLATE to the package path. This is enabled via the `# gazelle:experimental_allow_relative_imports` true directive ({gh-issue}`2203`). * (gazelle) Types for exposed members of `python.ParserOutput` are now all public. -* (gazelle) Remove entry point file requirements when generating rules. +* (gazelle) Removed the requirement for `__init__.py`, `__main__.py`, or `__test__.py` files to be + present in a directory to generate a `BUILD.bazel` file. {#v0-0-0-fixed} ### Fixed