Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gazelle failing when executed from within a virtual environment #1599

Closed
psalaberria002 opened this issue Dec 7, 2023 · 6 comments · Fixed by #1895
Closed

Gazelle failing when executed from within a virtual environment #1599

psalaberria002 opened this issue Dec 7, 2023 · 6 comments · Fixed by #1895
Labels
gazelle Gazelle plugin related issues

Comments

@psalaberria002
Copy link

psalaberria002 commented Dec 7, 2023

🐞 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.0

Description

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.

@aignas
Copy link
Collaborator

aignas commented Dec 18, 2023

Just a short message, that I can reproduce the error and I can reproduce it with 3.11.4 and 3.11 toolchains. Not sure yet if this is a problem with how we define toolchains, but for sure it is related to the change in how we include the Python code in gazelle.

@rajukrishnamurthy
Copy link

I do not know if this is related, but I bumped rules_python from v0.25.0 to v.0.31.0 but have not investigate where the issue might have need originated. When I specify a package to run gazelle under, it fails with a similar error as above (I'm not running in venv). So, if I run:

bazel run //:gazelle some/package  # works
bazel run //:gazelle some/package  # rerun fails
bazel run //:gazelle some/otherpackage  # works
bazel run //:gazelle some/otherpackage  # rerun fails

if I don't specify a package, I never get a failure.

github-merge-queue bot pushed a commit that referenced this issue May 20, 2024
Remove gazelle plugin's python deps and make it hermetic. No more
relying on the system interpreter.

Use TreeSitter to parse Python code and use
https://github.com/pypi/stdlib-list to determine whether a module is in
std lib.

Fixes #1825
Fixes #1599
Related #1315
@aignas aignas reopened this May 30, 2024
@aignas
Copy link
Collaborator

aignas commented May 30, 2024

My hope is that #1929 should help with this issue.

@aignas aignas added the gazelle Gazelle plugin related issues label Jun 4, 2024
@aignas aignas closed this as completed Jun 4, 2024
@aignas
Copy link
Collaborator

aignas commented Jun 4, 2024

Closing as the latest code is using golang, so should not be affected by Python virtual envs.

@psalaberria002
Copy link
Author

Closing as the latest code is using golang, so should not be affected by Python virtual envs.

Has the 'fix' been released? In which version?

@aignas
Copy link
Collaborator

aignas commented Jun 4, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gazelle Gazelle plugin related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants