Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stripped .py extension from the generated dependency name breaks builds. #895

Closed
rbuckland opened this issue Nov 23, 2022 · 0 comments
Closed

Comments

@rbuckland
Copy link
Contributor

🐞 bug report

Affected Rule

when install_deps(..) is run with rpyc as a requirement(), the Bazel build errors due to duplicate py_binary entries in the generated pip_dependencies set.

Is this a regression?

Have not run a previous version of baxel, with the rpyc dependency.

Description

Issue #702 introduced an edge case bug, where wheels with duplicate console_script entries (by name), differing by the .py extension fail due to duplicate dependencies being generated.

https://github.com/bazelbuild/rules_python/blob/main/python/pip_install/extract_wheels/bazel.py#L399
alters the name by stripping the extension .py

Which in the case of the pip dependency rpyc, creates duplicate py_binary(...) rules.

[console_scripts]
rpyc_classic = rpyc.cli.rpyc_classic:main
rpyc_classic.py = rpyc.cli.rpyc_classic:main
rpyc_registry = rpyc.cli.rpyc_registry:main
rpyc_registry.py = rpyc.cli.rpyc_registry:main

has 4x entries, pairs differeing with a .py extension.

this in turn results in "duplicate" py_binary() rules generated.

(🔥 Exception)

❯ bazel test lib/internal/mylib7/src:mylib7_py 
Loading: 
Loading: 0 packages loaded
Analyzing: target //lib/internal/mylib7/src:mylib7_py (0 packages loaded, 0 targets configured)
ERROR: Traceback (most recent call last):
        File "/home/user8/.cache/bazel/_bazel_user8/09d901cfcd7f772f56461320444edcec/external/pip_dependencies_310_rpyc/BUILD.bazel", line 42, column 10, in <toplevel>
                py_binary(
        File "/home/user8/.cache/bazel/_bazel_user8/09d901cfcd7f772f56461320444edcec/external/rules_python/python/private/reexports.bzl", line 79, column 21, in py_binary
                native.py_binary(**_add_tags(attrs))
Error in py_binary: py_binary rule 'rules_python_wheel_entry_point_rpyc_classic' in package '' conflicts with existing py_binary rule, defined at /home/user8/.cache/bazel/_bazel_user8/09d901cfcd7f772f56461320444edcec/external/pip_dependencies_310_rpyc/BUILD.bazel:33:10
ERROR: /home/user8/projects/svcs.com/acme-eng/main/lib/internal/mylib7/src/BUILD:18:11: Target '@pip_dependencies_310_rpyc//:pkg' contains an error and its package is in error and referenced by '//lib/internal/mylib7/src:mylib7_py'
ERROR: Analysis of target '//lib/internal/mylib7/src:mylib7_py' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.047s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
ERROR: Couldn't start the build. Unable to run tests
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

As per the error, there are indeed two py_binary rules stacked above each other at lines 33 (...pip_dependencies_310_rpyc/BUILD.bazel:33:10)
, and line 42 (...pip_dependencies_310_rpyc/BUILD.bazel", line 42)

#/home/user8/.cache/bazel/_bazel_user8/09d901cfcd7f772f56461320444edcec/external/pip_dependencies_310_rpyc/BUILD.bazel
...
py_binary(
    name = "rules_python_wheel_entry_point_rpyc_classic",
    srcs = ["rules_python_wheel_entry_point_rpyc_classic.py"],
    # This makes this directory a top-level in the python import
    # search path for anything that depends on this.
    imports = ["."],
    deps = ["pkg"],
)

py_binary(
    name = "rules_python_wheel_entry_point_rpyc_classic",
    srcs = ["rules_python_wheel_entry_point_rpyc_classic.py"],
    # This makes this directory a top-level in the python import
    # search path for anything that depends on this.
    imports = ["."],
    deps = ["pkg"],
)
...

🔬 Minimal Reproduction

add rpyc as a dependency in a requirements.txt
add it to the "deps" of a py_library.. e.g.

py_library(
    name = "my_lib",
    srcs = glob(["*.py"]),
    deps = [
        requirement("rpyc"),
    ],
)

and then build that target, when the pip_dependencies are read, the error occurs.

🌍 Your Environment

Operating System:
Linux

Output of bazel version:

  
❯ bazel --version
bazel 5.3.2
  

Rules_python version:

  
http_archive(
    name = "rules_python",
    sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4",
    strip_prefix = "rules_python-0.13.0",
    url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz",
)
  
rbuckland pushed a commit to rbuckland/rules_python that referenced this issue Nov 23, 2022
rbuckland added a commit to rbuckland/rules_python that referenced this issue Nov 23, 2022
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

No branches or pull requests

1 participant