bazel-contrib / bazel-contrib/rules_python

[gazelle] Adjust how `imports` is auto-generated

未关闭
#2,144 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
gazelle help wanted
主要语言
Starlark
星标
688
派生
721
平均合并
15 小时 7 分钟
30 天内合并 PR
76

描述

Discussion moved from an internal doc and discussion with @rickeylev:

> Externally, the Bazel Python rules have an attribute named `imports`. This is a string list of repo-relative paths that should be added to `sys.path`.

@dougthor42 writes in a comment:

> FYI: With gazelle's `python_root` directive, these are autogenerated as package-relative paths, eg `["../../.."]`.
>
> Now that I see [that `imports` is repo-relative], I might submit a PR to change Gazelle to generate repo-relative paths.

@rickeylev replies:

> Hm. Is package-relative better than repo-relative? Quick thought is: they both have pros and cons.
> Which makes me think: is there something that has all pros and no cons?
> To which I think: maybe we can change the logic to more directly express what we're after.
> When src/my_package says "add .. to path", what it really means is: make sure sys.path has a directory with "my_package" as a sub directory.
> So maybe instead we add a top_level_package_name attribute? Under the hood, a quick implementation would be to just do "compute the correct imports attr value automatically". A better impl for the future would be to ensure that some directory with the desired name ends up in sys.path, however that may come to be.
>
> Thanks for the inspiration :)

贡献指南

打开贡献指南

调研方向

该 issue 提到了 Gazelle 的 Python 规则以及生成的 `imports` 属性,但没有提供文件、测试或入口点。首先定位生成 `imports` 的 Gazelle 逻辑及相关测试;对于相关的 `python_root` 情况,预期的路径行为达成一致并得到覆盖后,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
build-system, tooling
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。