Skip to content

fix(pypi): support source-less wheels with dependencies - #4054

Open
hartikainen wants to merge 1 commit into
bazel-contrib:mainfrom
hartikainen:py-spy-fix
Open

fix(pypi): support source-less wheels with dependencies#4054
hartikainen wants to merge 1 commit into
bazel-contrib:mainfrom
hartikainen:py-spy-fix

Conversation

@hartikainen

Copy link
Copy Markdown
Contributor

Source-less wheels with dependency metadata fail analysis because the generated wrapper py_library puts an empty :srcs target in its srcs attribute.

This forwards :srcs through the wrapper only when it produces Python sources, while retaining it in deps for PyInfo propagation. Before this change, py-spy==0.4.1 dependency fails during analysis. Afterward, it can be used as a dependency.

Adds regression coverage for source-less, sourceful, and generated namespace-package source targets, along with a news entry.

Largely implemented with Opus.

Fixes #4053.

`rules_python` `2.3.x` wraps source-less wheels in a `py_library`
whose `srcs` target has no Python files. Forward the target only when
it has valid sources, and cover the wrapper behavior with unit tests.
Copilot AI lite review requested due to automatic review settings August 15, 2026 06:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an analysis-time failure in pip.parse-generated per-wheel repositories when consuming source-less wheels that still declare dependencies. It prevents the generated wrapper py_library from pointing its srcs at an empty source target (which Bazel rejects), while still keeping the source target in deps so PyInfo continues to propagate.

Changes:

  • Plumbs a computed wrapper_srcs value out of whl_library_srcs() and into whl_library_deps_targets() so the wrapper py_library(srcs=...) is only populated when it would be source-producing.
  • Adds regression tests covering sourceless wheels, normal sourceful wheels, and the “generated namespace-package init files” case.
  • Adds a news entry documenting the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
python/private/pypi/whl_library_targets.bzl Computes and forwards wrapper srcs to avoid analysis errors for source-less wheels while preserving PyInfo propagation via deps.
tests/pypi/whl_library_targets/whl_library_targets_tests.bzl Adds targeted regression coverage for sourceless/sourceful/namespace-init scenarios by asserting the generated py_library calls.
news/sourceless-wheel-srcs.fixed.md Documents the bugfix in the changelog/news system.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

pip.parse fails for source-less wheels with dependencies

2 participants