fix(gazelle): migrate to official tree-sitter Go bindings (#4272) Replace the unmaintained `github.com/smacker/go-tree-sitter` dependency with the official `github.com/tree-sitter/go-tree-sitter` and `github.com/tree-sitter/tree-sitter-python` (v0.25.0) modules. This updates the Python grammar so the Gazelle plugin can parse Python 3.14 PEP 758 unparenthesized multi-exception `except` clauses without errors. Because the official bindings include C sources across parent and subdirectory paths that standard `go_repository` Gazelle generation cannot compile directly, fetch both modules via `http_archive` with custom `cc_library` and `go_library` targets in both Bzlmod and WORKSPACE modes. We also remove unneeded go_repository items from `gazelle/deps.bzl`. Generated by Gemini. Tested on our large-scale QuantumAI monorepo. TAG=agy ### Timing I ran the parent commit and this PR on our primary QuantumAI monorepo. This PR might make things a little faster, but I didn't want to wait for 5 or more runs in hyperfine :laughing:. Parent commit: ``` $ git -C ../../oss/bazel-contrib/rules_python rev-parse HEAD b7ec5bd151df5f725ab8f76446fd548ac4fedce1 # agents: require user-visible docs prose and workaround comments (#4271) $ hyperfine --warmup=1 --runs=3 'bazel run --bes_backend= //:gazelle' Benchmark 1: bazel run --bes_backend= //:gazelle Time (mean ± σ): 93.052 s ± 18.023 s [User: 99.884 s, System: 6.302 s] Range (min … max): 82.134 s … 113.855 s 3 runs Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options. ``` This PR: ``` $ git -C ../../oss/bazel-contrib/rules_python rev-parse HEAD bc5b12a5e160e7f91f665fc730b9b305dc3471b4 $ hyperfine --warmup=1 --runs=3 'bazel run --bes_backend= //:gazelle' Benchmark 1: bazel run --bes_backend= //:gazelle Time (mean ± σ): 80.338 s ± 2.570 s [User: 80.271 s, System: 3.808 s] Range (min … max): 78.292 s … 83.223 s 3 runs ``` Fixes #3416
This repository is the home of the core Python rules -- py_library, py_binary, py_test, 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.
requirements.txt is how users have been defining dependencies for a long time. We support this to support legacy usecases or package managers that we don't support directly. Any additional information that we need will be retrieved from the SimpleAPI during the bzlmod extension evaluation phase. Then it will be written to the MODULE.bazel.lock file for future reuse. We have plans to support uv.lock file directly. uv is recommended for generating a fully locked requirements.txt file and we do provide a rule for it.py_binary, py_test rules should scale to large monorepos and we work hard to minimize the work done during analysis and build phase. What is more, the space requirements for should be minimal, so we strive to use symlinks rather than extracting wheels at build time. This means that for different configurations of the same build, we are not extracting the wheel multiple times thus scaling better over the time. From 2.0 onwards we are creating a virtual env for each target by creating an actual minimal virtual environment using symlinks. We plan on creating the traditional site-packages layout in the future by default.rules_python and this has resulted in a few PEPs supported within pure starlark - PEP440, PEP509.Common misconceptions:
rules_python has to keep backwards compatibility with google3. Whilst this might have been true in the past, rules_python is an open source project and any compatibility needs should come from the community - we have no requirement to keep this compatibility and are allowed to make our decisions. However, we do want to keep backwards compatibility as long as possible to not upset users with never ending migrations.rules_python is not caching pip downloads. With 2.0, we use Bazel's downloader by default and rely on bazel to provide the repository caching mechanisms. This means that for simpler setups this should result in transparent and scalable caching with the most recent bazel versions unless there are issues in the bazel itself.For detailed documentation, see https://rules-python.readthedocs.io
See Bzlmod support for more details.