Skip to content

fix: do not include transitive sources from pyi_deps in runtime runfiles - #4178

Open
faximan wants to merge 2 commits into
bazel-contrib:mainfrom
faximan:faximan/fix-pyi-deps-runfiles
Open

faximan wants to merge 2 commits into
bazel-contrib:mainfrom
faximan:faximan/fix-pyi-deps-runfiles

Conversation

@faximan

@faximan faximan commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

pyi_deps are documented as build-time only dependencies for type checking and static analysis, but currently leaks into the runfiles.

Before: create_py_info merged pyi_deps targets using py_info.merge(), which caused all transitive sources from type stubs and their dependencies to be placed in PyInfo.transitive_sources and included in downstream binary/test runfiles.

After: create_py_info only propagates imports (for module import resolution during type checking), transitive_pyi_files, and transitive_original_sources from pyi_deps. Adds unit tests verifying transitive_sources and binary runfiles exclusion.

Tested: in our repo using rules_python and pyi_deps for type checking, this reduced the runfile tree size with 20M for a sample py_test.

…runfiles

`pyi_deps` are documented as build-time only dependencies for type
checking and static analysis. Previously, `create_py_info` merged
`pyi_deps` targets using `py_info.merge()`, which caused all transitive
sources from type stubs and their dependencies to be placed in
`PyInfo.transitive_sources` and included in downstream binary/test runfiles.

This change updates `create_py_info` to only propagate `imports`,
`transitive_pyi_files`, and `transitive_original_sources` from `pyi_deps`,
preventing them from leaking into runtime runfiles. Adds unit tests
verifying `transitive_sources` and binary runfiles exclusion.
@faximan faximan changed the title fix: do not include pyi_deps in runtime runfiles fix: do not include transitive sources from pyi_deps in runtime runfiles Sep 24, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant