commit | 8ff4386335e5c50d9507fe364b4f0cc6a90f02e6 | [log] [tgz] |
---|---|---|
author | Richard Levasseur <rlevasseur@google.com> | Wed Nov 20 20:33:00 2024 -0800 |
committer | GitHub <noreply@github.com> | Thu Nov 21 04:33:00 2024 +0000 |
tree | 3e75ac97715a21a611d1fac173e43df289723e14 | |
parent | 4a55ef4c2363f7ffc1ec9ba511fba7b2547ccefc [diff] |
fix: make sys.executable work with script bootstrap (#2409) When `--bootstrap_impl=script` is used, `PYTHONPATH` is no longer used to set the import paths, which means subprocesses no longer inherit the Bazel paths. This is generally a good thing, but breaks when `sys.executable` is used to directly invoke the interpreter. Such an invocation assumes the interpreter will have the same packages available and works with the system_python bootstrap. To fix, have the script bootstrap use a basic virtual env. This allows it to intercept interpreter startup even when the Bazel executable isn't invoked. Under the hood, there's two pieces to make this work. The first is a binary uses `declare_symlink()` to write a relative-path based symlink that points to the underlying Python interpreter. The second piece is a site init hook (triggered by a `.pth` file using an `import` line) performs sys.path setup as part of site (`import site`) initialization. Fixes https://github.com/bazelbuild/rules_python/issues/2169 --------- Co-authored-by: Ignas Anikevicius <240938+aignas@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.