Gazelle identifies Python source files as *.py files, excluding those matching the # gazelle:python_test_file_pattern directive (defaults to *_test.py and test_*.py).
Libraries
Depending on the # gazelle:python_generation_mode directive:
- package mode: Creates a
py_library named after the package in the BUILD file, collecting all source files in that package. - project mode: Collects source files from subdirectories that lack their own
BUILD files. - file mode: Creates a unique
py_library target for every individual Python source file.
Tests
Gazelle creates py_test targets when it encounters:
- Files named
__test__.py. - Files matching the
# gazelle:python_test_file_pattern directive.
You can customize test naming using the # gazelle:python_test_naming_convention directive.
Binaries
Gazelle creates py_binary targets in two scenarios:
- Entry point file: If a
__main__.py file is found, it creates a target named [package]_bin. - Main block: If no
__main__.py exists, it looks for if __name__ == "__main__": in modules. The target name matches the module name.
Note: In file generation mode, Gazelle creates one py_binary per file containing a main block.