Skip to content

Commit 83e8f4b

Browse files
yushan26yushan8dougthor42
authored
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 #999 and #2044 - entry point for binaries (i.e., `__main__.py` ) is no longer required after #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 <[email protected]> Co-authored-by: Douglas Thor <[email protected]>
1 parent cd6948a commit 83e8f4b

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ END_UNRELEASED_TEMPLATE
5858
to the package path. This is enabled via the
5959
`# gazelle:experimental_allow_relative_imports` true directive ({gh-issue}`2203`).
6060
* (gazelle) Types for exposed members of `python.ParserOutput` are now all public.
61+
* (gazelle) Removed the requirement for `__init__.py`, `__main__.py`, or `__test__.py` files to be
62+
present in a directory to generate a `BUILD.bazel` file.
6163

6264
{#v0-0-0-fixed}
6365
### Fixed

gazelle/python/generate.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
8585
if parent != nil && parent.CoarseGrainedGeneration() {
8686
return language.GenerateResult{}
8787
}
88-
} else if !hasEntrypointFile(args.Dir) {
89-
return language.GenerateResult{}
9088
}
9189
}
9290

@@ -172,9 +170,6 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
172170
// 2. The directory has a BUILD or BUILD.bazel files. Then
173171
// it doesn't matter at all what it has since it's a
174172
// separate Bazel package.
175-
// 3. (only for package generation) The directory has an
176-
// __init__.py, __main__.py or __test__.py, meaning a
177-
// BUILD file will be generated.
178173
if cfg.PerFileGeneration() {
179174
return fs.SkipDir
180175
}
@@ -184,7 +179,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
184179
return nil
185180
}
186181

187-
if !cfg.CoarseGrainedGeneration() && hasEntrypointFile(path) {
182+
if !cfg.CoarseGrainedGeneration() {
188183
return fs.SkipDir
189184
}
190185

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# gazelle:python_generation_mode project

gazelle/python/testdata/subdir_sources/BUILD.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
12
load("@rules_python//python:defs.bzl", "py_binary")
23

4+
# gazelle:python_generation_mode project
5+
36
py_binary(
47
name = "subdir_sources_bin",
58
srcs = ["__main__.py"],

0 commit comments

Comments
 (0)