bazel-contrib / bazel-contrib/rules_python
Third-party transitive dependencies seem to be packaged into wheels incorrectly
- 主要语言
- Starlark
- 星标
- 688
- 派生
- 721
- 平均合并
- 15 小时 7 分钟
- 30 天内合并 PR
- 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?**
贡献指南
调研方向
从提供的 py_package 和 py_wheel 复现开始,检查生成的 wheel 的路径和已安装内容。将 behave 等传递依赖项的放置位置与 wheel 预期的顶层布局进行比较;当这些依赖项直接安装到环境的 site-packages 中,并且仍是有效的 wheel 内容时,该 issue 即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- build-system
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100