Skip to content

feat(rules): add py_dist_info rule for importlib.metadata - #4357

Draft
pganssle-google wants to merge 2 commits into
bazel-contrib:mainfrom
pganssle-google:py-dist-info
Draft

pganssle-google wants to merge 2 commits into
bazel-contrib:mainfrom
pganssle-google:py-dist-info

Conversation

@pganssle-google

@pganssle-google pganssle-google commented Oct 26, 2026 •

Copy link
Copy Markdown

Libraries built from source with py_library (rather than installed
from a wheel) do not have a .dist-info directory in runfiles, so
runtime queries via importlib.metadata.version() or
importlib.metadata.entry_points() fail unless the library is patched.
Additionally, targets that also build a py_wheel previously had no way
to share .dist-info metadata definitions between runfiles and wheel
packaging.

This adds py_dist_info and PyDistInfo in //python:py_dist_info.bzl
to generate .dist-info metadata (METADATA, entry_points.txt, and
extra_distinfo_files) staged via root_symlinks under
<repo>/[target_path/]<distribution>.dist-info in runfiles. py_wheel
now delegates .dist-info metadata generation to py_dist_info via a
new dist_info attribute (defaulting to an implicit <name>.dist_info
target when metadata attributes are passed directly to py_wheel).

Libraries built directly from source with py_library (rather than
installed from a wheel) do not have a .dist-info directory in runfiles,
so runtime queries via importlib.metadata.version() or
importlib.metadata.entry_points() fail unless the library is patched.

This adds py_dist_info in //python:py_dist_info.bzl, which writes
METADATA and entry_points.txt files and stages them via root_symlinks
under <repo>/[target_path/]<package_name>.dist-info in runfiles so
importlib.metadata can discover them on sys.path.
@pganssle-google

pganssle-google commented Oct 26, 2026 •

Copy link
Copy Markdown
Author

AI Disclosure: This PR was drafted with an AI coding assistant under @pganssle's close direction and review. @pganssle will review all feedback on this PR and either respond directly or review and approve any agent-assisted updates before they are posted.

This is an automatically generated agent comment.

--

I will not move this out of draft until after I have personally reviewed it.

This is a human generated comment

Previously, `py_wheel` constructed `.dist-info` metadata (`metadata.txt`
and `entry_points.txt`) directly inside `_py_wheel_impl`, duplicating
the metadata generation logic needed by `py_dist_info`.

This expands `py_dist_info` to accept the full set of `.dist-info`
metadata attributes (`distribution`, `version`, `author`, `classifiers`,
`description_file`, `entry_points`, `extra_distinfo_files`,
`extra_requires`, `requires`, `stamp`, etc.) and return a `PyDistInfo`
provider alongside its runfiles `.dist-info` directory. `py_wheel` now
accepts a `dist_info` attribute (defaulting to an implicit
`<name>.dist_info` target generated by the `py_wheel` macro when
metadata attributes are passed directly to `py_wheel`), and fails during
analysis if an explicit `dist_info` target is combined with direct
`.dist-info` attributes on `py_wheel`.

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