bazel-contrib / bazel-contrib/rules_python

Third-party transitive dependencies seem to be packaged into wheels incorrectly

Đang mở
#2,123 16 bình luận 3 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Starlark
Star
688
Fork
721
Merge trung bình
15 giờ 7 phút
Pull request đã merge (30 ngày)
76

Mô tả

# 🐞 bug report

### Affected Rule

py_wheel

### Is this a regression?

Doubtful

### Description

When building a wheel using `py_wheel`, third-party pip requirements are being installed into an incorrect directory, preventing them from being properly installed/used in Python environments.

## 🔬 Minimal Reproduction

```
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_python//python:packaging.bzl", "py_package", "py_wheel")
load("@python_deps//:requirements.bzl", "requirement")

filegroup(
name = "srcs",
srcs = glob(
[
"**/*.py",
"*.py",
],
exclude = ["tests/**"],
),
)

py_deps = [
requirement("behave"),
]

py_library(
name = "regression_harness",
srcs = [":srcs"],
visibility = ["//bt:__subpackages__"],
deps = py_deps,
)

py_package(
name = "regression_harness_pkg",
deps = [
":regression_harness",
],
)

py_wheel(
name = "regression_harness_wheel",
distribution = "regression_harness",
version = "1.0.0",
deps = [
":regression_harness_pkg",
],
)
```

## 🔥 Exception or Error

The wheel builds as usual, and looks (at least mostly) correct. However, upon installing the wheel, we see the following:



gitpod /workspace/tribe $ ls /tmp/test/lib/python3.8/site-packages/
bin pip-24.1.2.virtualenv site-packages
bt pkg_resources _virtualenv.pth
_distutils_hack __pycache__ _virtualenv.py
distutils-precedence.pth regression_harness-0.0.8940.dist-info wheel
include setuptools wheel-0.43.0.dist-info
lib setuptools-57.4.0.dist-info wheel-0.43.0.virtualenv
pip setuptools-57.4.0.virtualenv
pip-24.1.2.dist-info share

`regression_harness` was in fact installed, and is available, but the third-party transitive dependencies are within a **nested** site-packages directory _within_ the site-packages.



gitpod /workspace/tribe $ ls /tmp/test/lib/python3.8/site-packages/site-packages/
behave parse-1.20.2.dist-info parse_type-0.6.2.dist-info six-1.16.0.dist-info
behave-1.2.6.dist-info parse.py __pycache__ six.py
__init__.py parse_type setuptools_behave.py

Of course, this means that they're not available within the environment, as that directory is not part of the PYTHONPATH.

I have tried stripping the `site-packages` prefix when building the wheel, but this makes the wheel file invalid as it will contain multiple `.dist-info` files.

Am I doing something incorrectly? This seems like a bug to me, but I can't imagine that others wouldn't have seen this.

## 🌍 Your Environment

**Operating System:**

  

Ubuntu Focal

**Output of `bazel version`:**

  

gitpod /workspace/tribe $ bazel version
Bazelisk version: v1.17.0
Build label: 6.2.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jun 2 16:59:58 2023 (1685725198)
Build timestamp: 1685725198
Build timestamp as int: 1685725198

**Rules_python version:**

  

0.27.1
e85ae30de33625a63eca7fc40a94fea845e641888e52f32b6beea91e8b1b2793

**Anything else relevant?**

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với bản tái hiện py_package và py_wheel được cung cấp, đồng thời kiểm tra các đường dẫn và nội dung đã cài đặt của wheel được tạo. So sánh vị trí của các phần phụ thuộc bắc cầu như behave với bố cục cấp cao nhất dự kiến của wheel; issue được hoàn tất khi các phần phụ thuộc đó được cài đặt trực tiếp vào site-packages của môi trường và vẫn là nội dung wheel hợp lệ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
build-system
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.