Skip to content

Commit 957345e

Browse files
committed
Update documentation for py_binary generation
1 parent 43db643 commit 957345e

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ A brief description of the categories of changes:
4040
* (toolchains) `py_runtime` can now take an executable target. Note: runfiles
4141
from the target are not supported yet.
4242

43+
* (gazelle) When `python_generation_mode` is set to `file`, create one `py_binary`
44+
target for each file with `if __name__ == "__main__"` instead of just one
45+
`py_binary` for the whole module.
46+
4347
### Fixed
4448

4549
* (gazelle) The gazelle plugin helper was not working with Python toolchains 3.11

gazelle/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,20 @@ When no such entry point exists, Gazelle will look for a line like this in the t
250250
if __name == "__main__":
251251
```
252252

253-
Gazelle will create `py_binary` target will be created for every module with such line, with the target name
254-
being the same as module name.
253+
Gazelle will create a `py_binary` target for every module with such a line, with
254+
the target name the same as the module name.
255+
256+
If `python_generation_mode` is set to `file`, then instead of one `py_binary`
257+
target per module, Gazelle will create one `py_binary` target for each file with
258+
such a line, and the name of the target will match the name of the script.
259+
260+
Note that it's possible for another script to depend on a `py_binary` target and
261+
import from the `py_binary`'s scripts. This can have possible negative effects on
262+
Bazel analysis time and runfiles size compared to depending on a `py_library`
263+
target. The simplest way to avoid these negative effects is to extract library
264+
code into a separate script without a `main` line. Gazelle will then create a
265+
`py_library` target for that library code, and other scripts can depend on that
266+
`py_library` target.
255267

256268
## Developer Notes
257269

0 commit comments

Comments
 (0)