rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

feat(gazelle): Add python_generate_pyi_srcs directive

Open dougthor42 opened this issue 3 months ago • 0 comments

Fixes #3354

This adds a new Gazelle directive python_generate_pyi_srcs which accepts a boolean value true or false. It defaults to false for backwards compatibility.

When true, the directive causes .pyi files, whose name matches with a .py file found in srcs, to be added to the pyi_srcs target attribute.

This helps with cases where manually-generated .pyi files are present in the project and are needed for things such as rules_mypy.

Given the following files in a my_dir package:

BUILD.bazel
__init__.py
a.py
a.pyi
b.py
c.py
c.pyi

# gazelle:python_generate_pyi_srcs true will cause Gazelle to generate:

py_library(
    name = "my_dir",
    srcs = [
        "__init__.py",
        "a.py",
        "b.py",
        "c.py",
    ],
    pyi_srcs = [
        "a.py",
        "c.py",
    ],
)

dougthor42 avatar Oct 15 '25 00:10 dougthor42