Skip to content

fix(pypi): preserve explicitly included bytecode package initializers - #4607

Open
Boulea7 wants to merge 3 commits into
bazel-contrib:mainfrom
Boulea7:fix/preserve-wheel-bytecode-initializers
Open

Boulea7 wants to merge 3 commits into
bazel-contrib:mainfrom
Boulea7:fix/preserve-wheel-bytecode-initializers

Conversation

@Boulea7

@Boulea7 Boulea7 commented Dec 3, 2026

Copy link
Copy Markdown

Wheel data can explicitly include a bytecode package initializer.
Namespace conversion currently writes an __init__.py alongside it.
Python imports that file first, leaving names exported by the wheel's
initializer unavailable.

Recognize __init__.pyc when deciding whether a package already has an
initializer.

Work towards #2178.

Treat an explicitly included __init__.pyc as a package initializer so
namespace conversion preserves the exports in the wheel.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 09:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Namespace conversion now treats explicitly included __init__.pyc files as package initializers, alongside __init__.py. Tests cover nested bytecode paths and relative and absolute initializer labels. Documentation records the change.

Changes: Namespace package conversion

Layer / File(s) Summary
Initializer recognition and coverage
python/private/pypi/namespace_pkgs.bzl, tests/pypi/namespace_pkgs/namespace_pkgs_tests.bzl, python/private/pypi/attrs.bzl, news/2178.fixed.md
get_files normalizes source labels and handles __init__.pyc like __init__.py. Tests cover nested bytecode paths and relative and absolute initializer labels. The attribute documentation and news entry describe the change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to e44be

Namespace conversion no longer creates an __init__.py next to an explicitly included __init__.pyc, so names exported by the wheel's bytecode initializer are no longer hidden. The change is small and covered by tests, and no merge-blocking risk is identified. The failing Buildkite build should be checked to confirm it is unrelated.

Security architecture risk: Minimal · up to e44be

Namespace conversion now leaves explicitly included bytecode initializers unshadowed by its generated source initializers. The fix does not broaden which wheel files are included or change the settings that govern namespace conversion.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: namespace conversion now keeps explicitly included bytecode package initializers (init.pyc) and does not add an init.py beside them. It uses the conventional f…
Description check Passed The description states the problem: wheel data can include a bytecode initializer, and namespace conversion writes an init.py beside it, which hides the wheel's exported names. It states the fix: …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: namespace conversion now keeps explicitly included bytecode package initializers (init.pyc) and does not add an init.py beside them. It uses the conventional fix(pypi) prefix and matches the raw summary and PR description.

Full details: Description check

Explanation

The description states the problem: wheel data can include a bytecode initializer, and namespace conversion writes an init.py beside it, which hides the wheel's exported names. It states the fix: recognize init.pyc when checking for an existing initializer. This matches the file summaries for namespace_pkgs.bzl, the attrs.bzl docs, and the tests.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 252d2c0 and e44be53.

Files selected for processing: 2

  • python/private/pypi/namespace_pkgs.bzl
  • tests/pypi/namespace_pkgs/namespace_pkgs_tests.bzl

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@Boulea7

Boulea7 commented Dec 3, 2026

Copy link
Copy Markdown
Author

An AI coding agent prepared and tested this change. During this task the
agent will check for review feedback and may post replies directly.

This is an agent-generated comment unreviewed by the user.

@coderabbitai coderabbitai Bot 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.

Additional comments: 1

python/private/pypi/namespace_pkgs.bzl-39-39: 1

39-39: Major · Data Integrity & Integration · Heavy lift

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Normalize data labels before comparing directories.

whl_library_srcs accepts data labels and passes them to create_inits alongside globbed paths. (raw.githubusercontent.com) If data contains :site-packages/foo/__init__.pyc and the glob finds site-packages/foo/module.py, this records :site-packages/foo as ignored but generates an initializer for site-packages/foo. The generated __init__.py can hide the bytecode exports. Normalize the inputs to comparable paths before checking directories.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9cd10fe and 252d2c0.

Files selected for processing: 4

  • news/2178.fixed.md
  • python/private/pypi/attrs.bzl
  • python/private/pypi/namespace_pkgs.bzl
  • tests/pypi/namespace_pkgs/namespace_pkgs_tests.bzl

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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.

2 participants