bazel-contrib / bazel-contrib/rules_python
Bazel 7 namespace collision
- Langage dominant
- Starlark
- Étoiles
- 688
- Forks
- 721
- Merge moyen
- 15 h 7 min
- PR mergées (30 j)
- 76
Description
# 🐞 bug report
with rules_python 0.31.0 and bazel 7.1.2, there seems to be an issue with naming certain directories with certain names. Wondering if this is expected?
### Description
There is a namespace collision with certain directories
## 🔬 Minimal Reproduction
Build file
example/time/BUILD
```
load("@rules_python//python:defs.bzl", "py_test", "py_library")
py_library(
name = "time_py",
srcs = ["py_test.py"],
)
py_test(
main = "py_test.py",
srcs = [":time_py"],
)
```
`example/time/__init__.py`
```
import time
```
`example/time/py_test.py`
```
import time
```
bazel test //example/time:all --noincompatible_default_to_explicit_init_py will result in an import error
## 🔥 Exception or Error
```
ImportError while importing test module
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../pip_pytest/site-packages/_pytest/python.py:617: in _importtestmodule
mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
../pip_pytest/site-packages/_pytest/pathlib.py:564: in import_path
importlib.import_module(module_name)
/home/ryang/.cache/bazel/_bazel_ryang/7071f3e24af240fa9a28f67dc16192b3/execroot/waabi-av/external/python3/lib/python310.zip/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
:1050: in _gcd_import
???
:1027: in _find_and_load
???
:1001: in _find_and_load_unlocked
???
E ModuleNotFoundError: No module named 'time.py_test'; 'time' is not a package
```
## 🌍 Your Environment
**Operating System:**
ubuntu 20.04
**Output of `bazel version`:**
7.1.2
**Rules_python version:**
0.31.0
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par reproduire l’échec avec example/time/BUILD, example/time/__init__.py et example/time/py_test.py en utilisant la commande de test Bazel et les versions indiquées. Suivez ensuite la manière dont le test Python est empaqueté et importé, puis vérifiez le comportement autour de la collision de l’espace de noms time et confirmez que la reproduction minimale ne déclenche plus le ModuleNotFoundError signalé.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- build-system
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 30/100