feat(gazelle) Remove entry point file requirements when generating rules (#2998)
Remove entry point file requirements when generating rules. Enable
python rule generation as long as there are .py source files under the
directory so all new packages will have python rules generated in the
package.
The extension used to require entrypoints for generation but:
- entry point for tests (i.e., `__test__.py` ) is no longer required
after https://github.com/bazel-contrib/rules_python/pull/999 and
https://github.com/bazel-contrib/rules_python/pull/2044
- entry point for binaries (i.e., `__main__.py` ) is no longer required
after https://github.com/bazel-contrib/rules_python/pull/1584
The entry point for libraries (`__init__.py` ) shouldn't be required
either, especially for Python 3.3 and after when namespace packages are
supported.
---------
Co-authored-by: yushan <yushan@uber.com>
Co-authored-by: Douglas Thor <dougthor42@users.noreply.github.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8cb5ca3..da59ecf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,6 +58,8 @@
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) 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
diff --git a/gazelle/python/generate.go b/gazelle/python/generate.go
index 5eedbd9..c1edec4 100644
--- a/gazelle/python/generate.go
+++ b/gazelle/python/generate.go
@@ -85,8 +85,6 @@
if parent != nil && parent.CoarseGrainedGeneration() {
return language.GenerateResult{}
}
- } else if !hasEntrypointFile(args.Dir) {
- return language.GenerateResult{}
}
}
@@ -172,9 +170,6 @@
// 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
}
@@ -184,7 +179,7 @@
return nil
}
- if !cfg.CoarseGrainedGeneration() && hasEntrypointFile(path) {
+ if !cfg.CoarseGrainedGeneration() {
return fs.SkipDir
}
diff --git a/gazelle/python/testdata/subdir_sources/BUILD.in b/gazelle/python/testdata/subdir_sources/BUILD.in
index e69de29..adfdefd 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 d03a8f0..5d77890 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"],