Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ sphinx_stardocs(
"//python:proto",
"//python:py_binary",
"//python:py_cc_link_params_info",
"//python:py_dist_info",
"//python:py_exec_tools_info",
"//python:py_exec_tools_toolchain",
"//python:py_executable_info",
Expand Down Expand Up @@ -139,6 +140,7 @@ sphinx_stardocs(
"//python/private:builders_util",
"//python/private:py_binary_rule",
"//python/private:py_cc_toolchain_rule",
"//python/private:py_dist_info",
"//python/private:py_info",
"//python/private:py_library_rule",
"//python/private:py_runtime_rule",
Expand Down
5 changes: 5 additions & 0 deletions news/4357.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(rules) Added {obj}`py_dist_info` in `@rules_python//python:py_dist_info.bzl`
to generate `.dist-info` metadata (`METADATA` and `entry_points.txt`) in
runfiles so `importlib.metadata` can discover package versions and entry points
at runtime, and added `dist_info` support to {obj}`py_wheel` so wheels can
reuse a {obj}`py_dist_info` target.
10 changes: 10 additions & 0 deletions python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ filegroup(
"defs.bzl",
"packaging.bzl",
"pip.bzl",
"py_dist_info.bzl",
"pytest_test.bzl",
"repositories.bzl",
"versions.bzl",
Expand All @@ -65,6 +66,7 @@ filegroup(

exports_files([
"defs.bzl",
"py_dist_info.bzl",
"pytest_test.bzl",
"python.bzl", # Deprecated, please use defs.bzl
])
Expand Down Expand Up @@ -207,6 +209,7 @@ bzl_library(
deps = [
":py_binary",
"//python/private:bzlmod_enabled",
"//python/private:py_dist_info",
"//python/private:py_package",
"//python/private:py_wheel",
"//python/private:util",
Expand Down Expand Up @@ -276,6 +279,13 @@ alias(
deprecation = "Use //python:py_cc_link_params_info instead",
)

# keep
bzl_library(
name = "py_dist_info",
srcs = ["py_dist_info.bzl"],
deps = ["//python/private:py_dist_info"],
)

bzl_library(
name = "py_exec_tools_info",
srcs = ["py_exec_tools_info.bzl"],
Expand Down
6 changes: 6 additions & 0 deletions python/features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ _TARGETS = {
"//python:proto": True,
"//python:py_binary": True,
"//python:py_cc_link_params_info": True,
"//python:py_dist_info": True,
"//python:py_exec_tools_info": True,
"//python:py_exec_tools_toolchain": True,
"//python:py_executable_info": True,
Expand All @@ -140,6 +141,11 @@ _LOADABLE_SYMBOLS = {
# keep sorted
"py_extension",
],
"//python:py_dist_info.bzl": [
# keep sorted
"PyDistInfo",
"py_dist_info",
],
"//python:py_info.bzl": [
# keep sorted
"PyInfo",
Expand Down
27 changes: 27 additions & 0 deletions python/packaging.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("//python:py_binary.bzl", "py_binary")
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED")
load(
"//python/private:py_dist_info.bzl",
"DIST_INFO_ATTR_NAMES",
"py_dist_info",
)
load("//python/private:py_package.bzl", "py_package_lib")
load("//python/private:py_wheel.bzl", _PyWheelInfo = "PyWheelInfo", _py_wheel = "py_wheel")
load("//python/private:util.bzl", "copy_propagating_kwargs")
Expand Down Expand Up @@ -169,6 +174,12 @@ def py_wheel(
//path/to:my_wheel.publish --repository testpypi
```

:::{versionchanged} VERSION_NEXT_FEATURE
Added support for passing a {obj}`py_dist_info` target via `dist_info`, and
automatically generates `<name>.dist_info` when `dist_info` is not
specified.
:::

Args:
name: A unique name for this target.
twine: A label of the external location of the py_library target for twine
Expand All @@ -190,6 +201,22 @@ def py_wheel(
**copy_propagating_kwargs(kwargs)
)

if "dist_info" not in kwargs or kwargs["dist_info"] == None:
dist_info_target = "{}.dist_info".format(name)
dist_info_kwargs = {
attr_name: kwargs[attr_name]
for attr_name in DIST_INFO_ATTR_NAMES
if attr_name in kwargs
}
if "toolchains" in kwargs:
dist_info_kwargs["toolchains"] = kwargs["toolchains"]
py_dist_info(
name = dist_info_target,
tags = manual_tags,
**copy_propagating_kwargs(kwargs, dist_info_kwargs)
)
kwargs["dist_info"] = dist_info_target

_py_wheel(
name = name,
tags = tags,
Expand Down
14 changes: 13 additions & 1 deletion python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,10 @@ bzl_library(
srcs = ["py_wheel.bzl"],
deps = [
":attributes",
":py_dist_info",
":py_info",
":py_package",
":rule_builders",
":stamp_impl",
":toolchain_types",
":transition_labels",
":version",
Expand Down Expand Up @@ -995,6 +995,18 @@ bzl_library(
srcs = ["py_console_script_gen.bzl"],
)

bzl_library(
name = "py_dist_info",
srcs = ["py_dist_info.bzl"],
deps = [
":attributes",
":rule_builders",
":stamp_impl",
":toolchain_types",
":transition_labels",
],
)

bzl_library(
name = "py_exec_tools_info",
srcs = ["py_exec_tools_info.bzl"],
Expand Down
Loading
Loading