bazel-contrib / bazel-contrib/rules_python

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

オープン
#2,123 コメント 16 件 リアクション 3 件 担当者 0 名 GitHub で見る
主要言語
Starlark
スター
688
フォーク
721
平均マージ
15時間 7分
マージ済み PR(30日)
76

説明

# 🐞 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?**

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start with the provided py_package and py_wheel reproduction and inspect the generated wheel's paths and installed contents. Compare the placement of transitive requirements such as behave with the wheel's expected top-level layout; the issue is done when those dependencies install directly into the environment's site-packages and remain valid wheel contents.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
build-system
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。