bazel-contrib / bazel-contrib/rules_python

`runfiles` module name conflicts with PyCharm

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

描述

# 🐞 bug report

### Affected Rule

`runfiles`

### Is this a regression?

No

### Description

PyCharm's Python console adds some stuff to the import path including a `runfiles` module. So when users open a project that supports both Bazel and virtual environments using this console, they run into errors like

```
>>> import mytest
Traceback (most recent call last):
File "", line 1, in
File "/Applications/PyCharm.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/tmp/PythonProject/mytest/__init__.py", line 1, in
from runfiles import Runfiles
ImportError: cannot import name 'Runfiles' from 'runfiles' (/Applications/PyCharm.app/Contents/plugins/python-ce/helpers/pydev/runfiles.py)
```

There doesn't seem to be any way around this other than wrapping `from runfiles import Runfiles` in some `try/except` or similar, which is unfortunate.

What if we had the `bazel-runfiles` package ship its implementation in a `bazel_runfiles` module instead, with `runfiles` remaining and serving as a simple proxy? This would allow affected environments to use

```
from bazel_runfiles import Runfiles
```

which should avoid any naming conflicts.

贡献指南

打开贡献指南

调研方向

首先定位 bazel-runfiles Python 包及其打包入口点。确认如何通过 bazel_runfiles 暴露实现,同时保留 runfiles 作为代理,然后验证所提议的导入方式能够避免与 PyCharm 的冲突,且不会破坏现有用户。

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

评估

技术栈
python
领域
tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

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