Skip to content

feat(gazelle) Remove entry point file requirements when generating rules #2998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +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) 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
Expand Down
7 changes: 1 addition & 6 deletions gazelle/python/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
}

Expand Down Expand Up @@ -172,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
}
Expand All @@ -184,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
}

Expand Down
1 change: 1 addition & 0 deletions gazelle/python/testdata/subdir_sources/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# gazelle:python_generation_mode project
Copy link
Contributor Author

@yushan26 yushan26 Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an existing test that is testing if subdirectory srcs gets added to a py_library target. Subdirectory sources will only be added to a py_library target in project mode.

3 changes: 3 additions & 0 deletions gazelle/python/testdata/subdir_sources/BUILD.out
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy