Automatic dynamic resolution of pip environments
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 技术栈
- python
- 领域
- build-system
调研方向
从链接的 gist 开始,然后跟踪如何为 py_library、py_test 和 py_binary 选择 pip_A 和 pip_B 依赖项。将提议的 pip_dep 行为与 issue 中描述的 string_flag、config_setting 和 transition 方法进行比较。当有文档记录的设计或实现能够在不为每个 target 设置命令行 flags 的情况下解析出正确的环境时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Description
Consider a monorepo with many separate pip environments
- Let py_library
Adepend onnumpyand have an associated pip environment (i.e. requirements.txt.lock file) - Let py_library
Bdepend onAand a specific versionnumpy==Xand also have its own pip environment.
For B, whether we end up using the version of numpy from A or from B's pip environment depends entirely on the order of deps in the definition of B.
py_library(
name = "A",
deps = [pip_A("numpy")],
)
py_library(
name = "B",
deps = [
# If we accidentally swap the order, we are going to use `pip_A("numpy")`
pip_B("numpy"),
"//path/to:A",
],
)
When we have a big monorepo with multiple bazel subpackages and multiple pip environments this very quickly gets out of hand and can a lot of problems.
Describe the solution you'd like
It would be extremely nice if the environment can be automatically resolved. For example, instead of the above, we instead write
py_library(
name = "A",
deps = [pip_dep("numpy")],
)
py_library(
name = "B",
deps = [
pip_dep("numpy"),
"//path/to:A",
],
)
Here pip_dep automatically resolves to the correct environment at build time. For A it resolves to pip_A, for B it resolves to pip_B (this can also be propagated from py_test and py_binary). For this to function correctly the assumption is that pip_B contains all pip_A packages that A requires, but not necessarily the same versions. This can very easily be achieved with proper dependency management across pip environments - either via -r A_requirements.in or by recursive inclusion in pyproject.toml.
The above behavior is theoretically possible today by adding a special macro pip_dep which resolves based on a string_flag and config_setting. However, this is quite far from convenient from an usage perspective, for example:
- The user needs to select and pass the correct flag for any binary or test that he runs
- Simultaneously running the entire suite of tests for the monorepo is not possible since bazel needs to be invoked with a different flag for every subpackage (this also can make things a lot slower)
Ideally the correct environment can be automatically resolved for a given target based on its path in the repo (if we assume all targets under B use pip_B and all targets under A use pip_A, which is IMO a sensible assumption). Then one can enforce the correct environment via transition. On the command line targets can be invoked without any extra configuration arguments (or configuration arguments can overwrite the automatic resolution).
Example implementation https://gist.github.com/nikonikolov/3204c93621c86b6f6d10723f65e7c1b7. Likely very suboptimal and can be improved. I am in no way a bazel expert, I coded it up with the help of Gemini
Describe alternatives you've considered
- Using a single lock file for the entire repo -> most of the time impossible due to conflicting requirements in different subpackages
- Make sure that if B depends on A, it always uses the same versions of the pip packages from A. This means user need to use
-c A_requirements.txt.lockto compileB_requirements.txt.lock. With multiple subpackages and conflicting environments, one would be constantly running into version conflicts which will have to be manually resolved (if at all possible), which is obviously far from desirable (hence the need for tools such asuv pip compileorpip-compile)
- 主要语言
- Starlark
- 星标
- 690
- 派生
- 722
- 平均合并
- 1 天 55 分钟
- 30 天内合并 PR
- 38
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazel-contrib/rules_python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
bazel-contrib/rules_python#4179 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
bazel-contrib/rules_python#4164 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
bazel-contrib/rules_python#3821 ·
-
难度 3/5 1-2 天 新手友好度 45/100
bazel-contrib/rules_python#4181 ·
-
Release 2.4.0 未关闭type: release
难度 4/5 3-5 天 新手友好度 25/100
bazel-contrib/rules_python#4175 · 3 条评论 ·
查看 bazel-contrib/rules_python 的全部 Issue
相似的 Issue
-
core dependencies
难度 1/5 1 小时以内 新手友好度 80/100
-
bug github_actions
难度 2/5 1-3 小时 新手友好度 75/100
registrystack/registry-stack#1393 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
Name consistency 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
eellak/triplestore#65 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 65/100