fix: make sys.executable work with script bootstrap#2409
fix: make sys.executable work with script bootstrap#2409rickeylev merged 10 commits intobazel-contrib:mainfrom
Conversation
bd85a4c to
d68262c
Compare
|
FYI, I am curious if the next version of this and #2359 combined could make it easy to have a |
3ea4bcc to
287b7bf
Compare
287b7bf to
028f9d1
Compare
I'm not sure I follow. With this PR, each binary will have its own venv, so an editor could be pointed to that directly. Do you mean something like, you do a one time setup to point your editor to some "well known path", and then run |
|
I think you understood it. I was thinking that you could do either: or tell VSCode or similar that the Python interpreter for We could also symlink it to a well known location using https://github.com/buildbuddy-io/bazel_env.bzl |
|
Ok, ready for review |
rickeylev
left a comment
There was a problem hiding this comment.
Addressed most, still have 1 or 2 left. Thanks!
…o fix.script.boot.sys.exe
Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
…o fix.script.boot.sys.exe
|
❤️ |
|
hi @rickeylev this doesn't seem to be working, Not sure if it is my system or what. |
|
Hmm actually it fails on WSL Ubuntu and is fine on a regular Linux Machine. Says a broken symbolic link |
When
--bootstrap_impl=scriptis used,PYTHONPATHis no longer used to set the importpaths, which means subprocesses no longer inherit the Bazel paths. This is generally a
good thing, but breaks when
sys.executableis 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 arelative-path based symlink that points to the underlying Python interpreter. The second
piece is a site init hook (triggered by a
.pthfile using animportline) performssys.path setup as part of site (
import site) initialization.Fixes #2169