diff --git a/python/private/pypi/whl_library_deps_targets.bzl b/python/private/pypi/whl_library_deps_targets.bzl index 89e9b74dc7..e549f52a47 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, @@ -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`. - 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. 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,6 +175,9 @@ def whl_library_deps_targets( package_deps = package_deps, tmpl = dep_template.format(name = "{}", target = PY_LIBRARY_PUBLIC_LABEL), ), + # 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 b8d51d0bd7..4f7bf8e98a 100644 --- a/python/private/pypi/whl_library_targets.bzl +++ b/python/private/pypi/whl_library_targets.bzl @@ -86,16 +86,17 @@ 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 dep_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 + ) 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