bazel-contrib / bazel-contrib/rules_python
Support importing across repos with bzlmod
- Ngôn ngữ chính
- Starlark
- Star
- 688
- Fork
- 721
- Merge trung bình
- 15 giờ 7 phút
- Pull request đã merge (30 ngày)
- 76
Mô tả
# 🚀 feature request
### Relevant Rules
`py_library` / `py_binary`
### Description
If there is a python library `@foo//bar:baz`, how can I import it from the main repository?
Pre-bzlmod, you could write `from foo.bar import baz`, as it would be in the directory `external/foo/bar/baz`, and the external directory was in your python path. Apparently this was not documented or intended, but nevertheless, people used it, as I don't believe it was ever considered when writing rules_python.
In bzlmod, however, you have repo mapping, where the directory `foo` is actually stored at `external/_main~~foo_ext~foo`, and thus `from foo.bar import baz` fails. This is the direct cause of #1679, and if we solve this, we fix that bug for free.
### Describe the solution you'd like
I'd personally like to make users prefix their imports to external repositories with the name of the workspace (based on the repo mapping). This would allow two python files in different repositories to `import foo.bar.baz` and each get their own `@foo` in the case of a repo name clash (this is how repo mapping is intended to be used, to allow each repo to have their own namespace of repos).
I previously achieved this in ChromeOS via a `sitecustomize.py` (see discussion in #1679).
### Describe alternatives you've considered
I can't really think of a viable alternative. Any solution without including the repo name in the import seems like it will end up in painful corner cases where you have name conflicts.
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách đọc thảo luận trong #1679 và cách tiếp cận sitecustomize.py được tham chiếu. Làm rõ cách repo mapping của bzlmod nên xác định tên import Python giữa các repository, bao gồm cả các xung đột tên. Được xem là hoàn tất khi có một định hướng triển khai đã được thống nhất và được lập tài liệu, hỗ trợ các import giữa repository được yêu cầu và giải quyết lỗi đã báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- build-system
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100