| commit | ca2c5b2273bcda68c6e2f5ab653501ac849b719b | [log] [tgz] |
|---|---|---|
| author | Richard Levasseur <richardlev@gmail.com> | Wed Dec 17 00:31:23 2025 -0800 |
| committer | GitHub <noreply@github.com> | Wed Dec 17 08:31:23 2025 +0000 |
| tree | 4400f1af2962d26c675f2a7dbf113d662c7fa145 | |
| parent | 10b28efc376d5810a08afa0d3ba873d89f7436a8 [diff] |
refactor: optimize venv creation for nvidia and pkgutil style namespace packages (#3460) When pkgutil style namespace packages are used, multiple distributions provide the same venv path (e.g. `foo/__init__.py`). The venv symlink logic then tries to symlink the `foo/` directory as it looks like the highest linkable directory. When conflict merging logic runs later, it then has to flatten a depset with all the files in the conflicting distributions. To fix, have whl_library() try to guess when a file is a pkgutil namespace package. These are then pass onto py_library's venv building logic so it can treat the directories as not directly linkable. A conflict still occurs, but it only contains the single `__init__.py` file. Along the way, special case the "nvidia" package name and always treat it as a namespace package. This is because nvidia packages aren't strictly correct: each has a blank `__init__.py` file (which marks it as a regular package, not namespace package). Special casing like this is undesirable, but it greatly reduces the number of conflicts if e.g. torch is installed, and I couldn't find any other metadata to indicate it's a namespace package. Along the way, add some hints to AGENTS.md so they understand repository rules better. Fixes https://github.com/bazel-contrib/rules_python/issues/3401 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This repository is the home of the core Python rules -- py_library, py_binary, py_test, py_proto_library, and related symbols that provide the basis for Python support in Bazel. It also contains package installation rules for integrating with PyPI and other indices.
Documentation for rules_python is at https://rules-python.readthedocs.io and in the Bazel Build Encyclopedia.
Examples live in the examples directory.
The core rules are stable. Their implementation is subject to Bazel's backward compatibility policy. This repository aims to follow semantic versioning.
The Bazel community maintains this repository. Neither Google nor the Bazel team provides support for the code. However, this repository is part of the test suite used to vet new Bazel releases. See How to contribute page for information on our development workflow.
For detailed documentation, see https://rules-python.readthedocs.io
See Bzlmod support for more details.