rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

Implement venv support for bootstrap system_python

Open rickeylev opened this issue 4 months ago • 2 comments

PR https://github.com/bazel-contrib/rules_python/pull/3242 mostly unifies how system_python and script bootstraps work. After that PR, the system_python bootstrap creates a venv-like file structure, except without pyvenv.cfg and bin/python3.

It should be pretty easy to update the code to create a real venv; just remove the codepaths where create_full_venv is false.

This would then make the venv-based implementation the only implementation.

That is overall a net win, however, the raw symlinks and "python home is found via symlink" functionality they rely on have some known friction points:

  • Python 3.9 and earlier don't have the necessary interpreter logic
  • It hasn't been vetted on windows (venv+windows tests are disabled)
  • The runtime_env toolchain can't always detect/activate the venv
  • It requires symlinks being enabled on windows

The fallback work around we have for all of those is to create a temp directory that is run out of. Creating a temp dir at runtime has its own problems (overhead, cleanup, being reaped while running), so I'm hesitant to make it the sole option. Until something like PEP 796 is accepted, things feel a bit dicey.

rickeylev avatar Sep 06 '25 17:09 rickeylev

Just to add my notes from #3117, I think we should also wait until the packaging rules have caught up and support symlinks in tar files, i.e.:

  • Wait for bazelbuild/rules_pkg#929
  • Wait for bazel-contrib/tar.bzl#16

aignas avatar Sep 07 '25 12:09 aignas

FWIW We do support symlinks; you just need to pass preserve_symlinks= True to mtree_mutate to discover symlinks, because it comes with a penalty. See: https://github.com/bazel-contrib/tar.bzl/issues/16#issuecomment-3348166518

thesayyn avatar Sep 29 '25 17:09 thesayyn