Skip to content

Conversation

dougthor42
Copy link
Collaborator

@dougthor42 dougthor42 commented Oct 15, 2025

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 dougthor42 changed the title feat (gazelle): Add python_generate_pyi_srcs directive feat(gazelle): Add python_generate_pyi_srcs directive Oct 15, 2025
@dougthor42 dougthor42 force-pushed the u/dthor/gazelle-pyi_srcs-gh3354 branch from 6dc8a0e to 7a7f1d3 Compare October 15, 2025 03:07
@dougthor42 dougthor42 added type: feature request gazelle Gazelle plugin related issues labels Oct 15, 2025
@dougthor42 dougthor42 marked this pull request as ready for review October 15, 2025 03:13
// file names if GeneratePyiSrcs is set. Otherwise, returns an empty set.
func getPyiFilenames(filenames *treeset.Set, generatePyiSrcs bool, basePath string) (*treeset.Set, error) {
pyiSrcs := treeset.NewWith(godsutils.StringComparator)
if generatePyiSrcs {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

invert logic:

if !generatePyiSrcs {
    return pyiSrcs, nil
}
it := filenames.Iterator()
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gazelle Gazelle plugin related issues type: feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gazelle: include .pyi sibling files in pyi_srcs

1 participant