Closed
Description
🐞 bug report
Affected Rule
The issue is caused by the Gazelle Python plugin.Is this a regression?
Yes, the previous version in which this bug was not present was: 0.26.0Description
Gazelle (with the Python plugin enabled) crashes when executed from within a virtual environment.🔬 Minimal Reproduction
A reproduction can be found at https://github.com/psalaberria002/rules_python_gazelle_repro.
$ bazel run //:venv
$ source .venv/bin/activate
$ bazel run //:gazelle
🔥 Exception or Error
$ bazel run gazelle
INFO: Analyzed target //:gazelle (60 packages loaded, 9983 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
bazel-bin/gazelle-runner.bash
bazel-bin/gazelle
INFO: Elapsed time: 2.561s, Critical Path: 2.34s
INFO: 7 processes: 6 internal, 1 linux-sandbox.
INFO: Build completed successfully, 7 total actions
INFO: Running command line: bazel-bin/gazelle
Could not find platform independent libraries
Could not find platform dependent libraries
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 0
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = '/install/lib/python3.11'
sys._base_executable = ''
sys.base_prefix = '/install'
sys.base_exec_prefix = '/install'
sys.platlibdir = 'lib'
sys.executable = ''
sys.prefix = '/install'
sys.exec_prefix = '/install'
sys.path = [
'/install/lib/python311.zip',
'/install/lib/python3.11',
'/install/lib/python3.11/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007faea97d9740 (most recent call first):
gazelle: failed to wait for std_modules: exit status 1
🌍 Your Environment
Operating System:
Operating System: Pop!_OS 22.04 LTS
Kernel: Linux 6.4.6-76060406-generic
Architecture: x86-64
Output of bazel version
:
Bazelisk version: v1.12.0
Build label: 7.0.0rc6
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Dec 4 22:34:51 2023 (1701729291)
Build timestamp: 1701729291
Build timestamp as int: 1701729291
Rules_python version:
0.27.1
Anything else relevant?
It started to break in 1.27.0, and 1.27.1 doesn't solve it.
Running Gazelle from outside the venv works as expected.
I have also tried creating the virtual environment with python -m venv .venv
to rule out any possible issues
with our rules_pyvenv, but it also fails with the same error.