From ccd8994a92d1e26733b203bfdb58b0adabc2611a Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 23 Aug 2026 23:05:33 +0900 Subject: [PATCH 1/3] fix: various fixes for the deps library Correctly wire args around and disable precompiling for the deps nodes. Work towards #2948 --- .../private/pypi/whl_library_deps_targets.bzl | 11 +++++--- python/private/pypi/whl_library_targets.bzl | 28 ++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/python/private/pypi/whl_library_deps_targets.bzl b/python/private/pypi/whl_library_deps_targets.bzl index 89e9b74dc7..967c66363a 100644 --- a/python/private/pypi/whl_library_deps_targets.bzl +++ b/python/private/pypi/whl_library_deps_targets.bzl @@ -23,8 +23,8 @@ def whl_library_deps_targets( repo, aliases = None, metadata_name, - requires_dist, - extras, + requires_dist = [], + extras = [], include = [], group_deps = [], group_name = None, @@ -46,8 +46,8 @@ def whl_library_deps_targets( direct cycles. These dependencies will be provided at runtime by the group rules which wrap this library and its fellows together. requires_dist: {type}`list[str]` The list of `Requires-Dist` values from - the whl `METADATA`. - extras: {type}`list[str]` The list of requested extras. This essentially includes extra transitive dependencies in the final targets depending on the wheel `METADATA`. + the whl `METADATA`. Optional because some packages don't have them. + extras: {type}`list[str]` The list of requested extras. This essentially includes extra transitive dependencies in the final targets depending on the wheel `METADATA`. Optional because some packages don't request them. include: {type}`list[str]` The list of packages to include. group_name: {type}`str | None` name of the dependency group (if any). dep_template: {type}`str | None` The dep_template to use. @@ -168,6 +168,9 @@ def whl_library_deps_targets( package_deps = package_deps, tmpl = dep_template.format(name = "{}", target = PY_LIBRARY_PUBLIC_LABEL), ), + # do not precomple `pyc` because this does not have any sources. The sources + # will be pre-compiled in the srcs folder once and for all. + precompile = "disabled", tags = tags, visibility = impl_vis, ) diff --git a/python/private/pypi/whl_library_targets.bzl b/python/private/pypi/whl_library_targets.bzl index b8d51d0bd7..07b51ea458 100644 --- a/python/private/pypi/whl_library_targets.bzl +++ b/python/private/pypi/whl_library_targets.bzl @@ -86,16 +86,18 @@ def whl_library_targets( **kwargs ) - whl_library_deps_targets( - name = name, - metadata_name = metadata_name, - requires_dist = requires_dist, - dep_template = dep_template, # only needed if requires_dist or group_name is present - group_deps = group_deps, # only needed if group_name is present - group_name = group_name, # must specify group_deps together - extras = extras, # only needed if requires_dist is present - include = include, # only needed if requires_dist is present - repo = None, # set aliases in the same repo - aliases = {}, - **kwargs - ) + if deps_template: + # allow to not define the targets if we invoke `whl_archive` without deps_template + whl_library_deps_targets( + name = name, + metadata_name = metadata_name, + requires_dist = requires_dist, + dep_template = dep_template, # only needed if requires_dist or group_name is present + group_deps = group_deps, # only needed if group_name is present + group_name = group_name, # must specify group_deps together + extras = extras, # only needed if requires_dist is present + include = include, # only needed if requires_dist is present + repo = None, # set aliases in the same repo + aliases = {}, + **kwargs + ) From a350f3a1a8b095c55f69fc4481153cbb2fb7d6ae Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 23 Aug 2026 15:59:49 -0700 Subject: [PATCH 2/3] fix(pypi): resolve undefined dep_template variable and update test expectation Fix CI analysis and test failures caused by an undefined variable in whl_library_targets and missing precompile attribute expectation in analysis tests. Change deps_template to dep_template in whl_library_targets and add "precompile": "disabled" to the expected py_library dictionary in whl_library_deps_targets tests. --- python/private/pypi/whl_library_deps_targets.bzl | 2 +- python/private/pypi/whl_library_targets.bzl | 4 ++-- .../whl_library_deps_targets_tests.bzl | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/python/private/pypi/whl_library_deps_targets.bzl b/python/private/pypi/whl_library_deps_targets.bzl index 967c66363a..a9ad78c73a 100644 --- a/python/private/pypi/whl_library_deps_targets.bzl +++ b/python/private/pypi/whl_library_deps_targets.bzl @@ -168,7 +168,7 @@ def whl_library_deps_targets( package_deps = package_deps, tmpl = dep_template.format(name = "{}", target = PY_LIBRARY_PUBLIC_LABEL), ), - # do not precomple `pyc` because this does not have any sources. The sources + # do not precompile `pyc` because this does not have any sources. The sources # will be pre-compiled in the srcs folder once and for all. precompile = "disabled", tags = tags, diff --git a/python/private/pypi/whl_library_targets.bzl b/python/private/pypi/whl_library_targets.bzl index 07b51ea458..31cae03ff8 100644 --- a/python/private/pypi/whl_library_targets.bzl +++ b/python/private/pypi/whl_library_targets.bzl @@ -86,8 +86,8 @@ def whl_library_targets( **kwargs ) - if deps_template: - # allow to not define the targets if we invoke `whl_archive` without deps_template + if dep_template: + # allow to not define the targets if we invoke `whl_archive` without dep_template whl_library_deps_targets( name = name, metadata_name = metadata_name, diff --git a/tests/pypi/whl_library_deps_targets/whl_library_deps_targets_tests.bzl b/tests/pypi/whl_library_deps_targets/whl_library_deps_targets_tests.bzl index ad6ab6f5fb..e8659ff642 100644 --- a/tests/pypi/whl_library_deps_targets/whl_library_deps_targets_tests.bzl +++ b/tests/pypi/whl_library_deps_targets/whl_library_deps_targets_tests.bzl @@ -74,6 +74,7 @@ def _test_whl_library_deps_targets(env): ":is_include_bar_baz_true": ["@pypi//bar_baz:pkg"], "//conditions:default": [], }), + "precompile": "disabled", "tags": [], "visibility": ["//visibility:public"], }) # buildifier: @unsorted-dict-items From e89513b0be8249597e8101665c8480dfde91bbbb Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 23 Aug 2026 17:27:31 -0700 Subject: [PATCH 3/3] refactor(pypi): address review comments on docstrings and comments Address code review feedback on PR #4106 by wrapping docstrings and improving comment clarity. Wrap whl_library_deps_targets docstrings to 80 columns, clarify the rationale for setting precompile = "disabled" on the wrapper target, and remove a redundant comment in whl_library_targets. --- .../private/pypi/whl_library_deps_targets.bzl | 25 ++++++++++++------- python/private/pypi/whl_library_targets.bzl | 1 - 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/python/private/pypi/whl_library_deps_targets.bzl b/python/private/pypi/whl_library_deps_targets.bzl index a9ad78c73a..e549f52a47 100644 --- a/python/private/pypi/whl_library_deps_targets.bzl +++ b/python/private/pypi/whl_library_deps_targets.bzl @@ -40,25 +40,32 @@ def whl_library_deps_targets( Args: name: {type}`str` The wheel filename - metadata_name: {type}`str` The package name as written in wheel `METADATA`. + metadata_name: {type}`str` The package name as written in wheel + `METADATA`. group_deps: {type}`list[str]` names of fellow members of the group (if any). These will be excluded from generated deps lists so as to avoid direct cycles. These dependencies will be provided at runtime by the group rules which wrap this library and its fellows together. requires_dist: {type}`list[str]` The list of `Requires-Dist` values from the whl `METADATA`. Optional because some packages don't have them. - extras: {type}`list[str]` The list of requested extras. This essentially includes extra transitive dependencies in the final targets depending on the wheel `METADATA`. Optional because some packages don't request them. + extras: {type}`list[str]` The list of requested extras. This essentially + includes extra transitive dependencies in the final targets + depending on the wheel `METADATA`. Optional because some packages + don't request them. include: {type}`list[str]` The list of packages to include. group_name: {type}`str | None` name of the dependency group (if any). dep_template: {type}`str | None` The dep_template to use. tags: {type}`list[str]` The tags set on the targets. - repo: {type}`str | Label | None` The BUILD.bazel label to the parent repo that has the - sources. If none, then will take the targets from the current dir. - aliases: {type}`dict[str, str] | None` The list of aliases to create in the parent repo. If None, will create - the default values. Empty list means no aliases. + repo: {type}`str | Label | None` The BUILD.bazel label to the parent + repo that has the sources. If none, then will take the targets from + the current dir. + aliases: {type}`dict[str, str] | None` The list of aliases to create in + the parent repo. If None, will create the default values. Empty list + means no aliases. visibility: {type}`list[str]` The visibility of the targets. native: {type}`native` The native struct for overriding in tests. - rules: {type}`struct` A struct with references to rules for creating targets. + rules: {type}`struct` A struct with references to rules for creating + targets. """ repo_label = Label(repo).same_package_label if repo else (lambda x: x) if aliases == None: @@ -168,8 +175,8 @@ def whl_library_deps_targets( package_deps = package_deps, tmpl = dep_template.format(name = "{}", target = PY_LIBRARY_PUBLIC_LABEL), ), - # do not precompile `pyc` because this does not have any sources. The sources - # will be pre-compiled in the srcs folder once and for all. + # Disable precompilation on this wrapper target to prevent duplicate + # pyc generation; the underlying PY_SRCS_LABEL target handles it. precompile = "disabled", tags = tags, visibility = impl_vis, diff --git a/python/private/pypi/whl_library_targets.bzl b/python/private/pypi/whl_library_targets.bzl index 31cae03ff8..4f7bf8e98a 100644 --- a/python/private/pypi/whl_library_targets.bzl +++ b/python/private/pypi/whl_library_targets.bzl @@ -87,7 +87,6 @@ def whl_library_targets( ) if dep_template: - # allow to not define the targets if we invoke `whl_archive` without dep_template whl_library_deps_targets( name = name, metadata_name = metadata_name,