Thanks to visit codestin.com
Credit goes to github.com

Skip to content

1.5.0-rc2 has an error with enable_implicit_namespace_pkgs and _copy_file argumentsΒ #3023

Closed
@philsc

Description

@philsc

🐞 bug report

Affected Rule

whl_library_targets

Is this a regression?

We're currently using 1.3.0 without issues.

πŸ”¬ Minimal Reproduction

I don't have a minimal reproduction handy, but I am hoping that the code snippets I provided below are illuminating enough to understand the issue.

πŸ”₯ Exception or Error

When pointing our repo against 1.5.0-rc2 I get the following error:

$ bazel query --output=build @my_deps_3_10_nbconvert//:all --override_repository=rules_python=$HOME/repos/rules_python
ERROR: /data/phil_cache/bazel/_bazel_philipp.schrader/a6af040577d5b4b6bfde0651e3589549/external/my_deps_3_10_nbconvert/BUILD.bazel:5:20: @@my_deps_3_10_nbconvert//:_cp_site-packages/nbconvert/tests/exporter_entrypoint_namespace: no such attribute 'srcs' in '_copy_file' rule (did you mean 'src'?)
ERROR: /data/phil_cache/bazel/_bazel_philipp.schrader/a6af040577d5b4b6bfde0651e3589549/external/my_deps_3_10_nbconvert/BUILD.bazel:5:20: @@my_deps_3_10_nbconvert//:_cp_site-packages/nbconvert/tests/exporter_entrypoint_namespace: no such attribute 'ignored_dirnames' in '_copy_file' rule
ERROR: /data/phil_cache/bazel/_bazel_philipp.schrader/a6af040577d5b4b6bfde0651e3589549/external/my_deps_3_10_nbconvert/BUILD.bazel:5:20: @@my_deps_3_10_nbconvert//:_cp_site-packages/nbconvert/tests/exporter_entrypoint_namespace: no such attribute 'root' in '_copy_file' rule
ERROR: /data/phil_cache/bazel/_bazel_philipp.schrader/a6af040577d5b4b6bfde0651e3589549/external/my_deps_3_10_nbconvert/BUILD.bazel:5:20: @@my_deps_3_10_nbconvert//:_cp_site-packages/nbconvert/tests/files_namespace: no such attribute 'srcs' in '_copy_file' rule (did you mean 'src'?)
ERROR: /data/phil_cache/bazel/_bazel_philipp.schrader/a6af040577d5b4b6bfde0651e3589549/external/my_deps_3_10_nbconvert/BUILD.bazel:5:20: @@my_deps_3_10_nbconvert//:_cp_site-packages/nbconvert/tests/files_namespace: no such attribute 'ignored_dirnames' in '_copy_file' rule
ERROR: /data/phil_cache/bazel/_bazel_philipp.schrader/a6af040577d5b4b6bfde0651e3589549/external/my_deps_3_10_nbconvert/BUILD.bazel:5:20: @@my_deps_3_10_nbconvert//:_cp_site-packages/nbconvert/tests/files_namespace: no such attribute 'root' in '_copy_file' rule
ERROR: /data/phil_cache/bazel/_bazel_philipp.schrader/a6af040577d5b4b6bfde0651e3589549/external/my_deps_3_10_nbconvert/BUILD.bazel:5:20: @@my_deps_3_10_nbconvert//:pkg: expected value of type 'string' for element 0 of each branch in select expression of attribute 'srcs' in 'py_library' rule (including '//conditions:default'), but got [..., ...] (list)
ERROR: package contains errors: : @@my_deps_3_10_nbconvert//:_cp_site-packages/nbconvert/tests/exporter_entrypoint_namespace: no such attribute 'srcs' in '_copy_file' rule (did you mean 'src'?)
ERROR: Evaluation of query "@my_deps_3_10_nbconvert//:all" failed

I see this code here in python/private/pypi/whl_library_targets.bzl:

if enable_implicit_namespace_pkgs:
    srcs = srcs + getattr(native, "select", select)({
        Label("//python/config_settings:is_venvs_site_packages"): [],
        "//conditions:default": create_inits(
            srcs = srcs + data + pyi_srcs,
            ignored_dirnames = [],  # If you need to ignore certain folders, you can patch rules_python here to do so.
            root = "site-packages",
        ),
    })

And looking at python/private/pypi/namespace_pkgs.bzl we see this:

def create_inits(**kwargs):
    srcs = []
    for out in get_files(**kwargs):
        src = "{}/__init__.py".format(out)
        srcs.append(srcs)

        copy_file(
            name = "_cp_{}_namespace".format(out),
            src = _TEMPLATE,
            out = src,
            **kwargs
        )

I believe that **kwargs being passed to copy_file(...) is the cause of the error here.

🌍 Your Environment

Operating System:

Ubuntu 22.04 amd64

Output of bazel version:

  
$ bazel version --override_repository=rules_python=$HOME/repos/rules_python
Bazelisk version: development
Build label: 7.2.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Jun 10 13:04:32 2024 (1718024672)
Build timestamp: 1718024672
Build timestamp as int: 1718024672
  

Rules_python version:

  
1.5.0-rc2
  

Anything else relevant?

Not that I can think of.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions