Exercises # gazelle:python_generation_mode project — every .py file under
the directive's directory is rolled up into a single py_library (and a
single py_test), and subdirectories produce no rules of their own.
.
└── myproj/
├── BUILD.bazel # # gazelle:python_generation_mode project
├── main.py # rolled in
├── main_test.py # → :myproj_test
├── models/
│ └── user.py # rolled in (no BUILD file here)
└── utils/
└── format.py # rolled in (no BUILD file here)
- The directive at
myproj/BUILD.bazelrolls up every.pyundermyproj/into one:myprojlibrary —srcslistsmain.py,models/user.py, andutils/format.py. - Subdirectories (
models/,utils/) do not get their own BUILD files. Bazel treatsmyproj/as one package and the cross-directorysrcsonly work because no nested BUILD file marks a sub-package boundary. If you adopt project mode in an existing tree you must clear pre-existingBUILD.bazelfiles in the subtree first. - Imports between the rolled-up files (
main.py→myproj.models.user,utils.format→myproj.models.user) resolve to the same library, so the generated rule has no self-dep on:myproj. - The single test file in the project root becomes
:myproj_testwithdeps = [":myproj"], picking up everything the library brings in.
bazel run //:gazelle # generate / update BUILD files
bazel test //... # run the rolled-up tests
bazel run //:gazelle -- update -mode=diff # idempotency checkThe BUILD files here are checked in pre-generated; the diff check should report no changes.