Skip to content

Gazelle plugin crashes if pygame is in user's site-packages #1006

@aptenodytes-forsteri

Description

@aptenodytes-forsteri

🐞 bug report

Affected Rule

Gazelle gazelle/std_modules.py

Is this a regression?

No.

Description

When

🔬 Minimal Reproduction

In this repository, set python toolchain to 3.10.9 in WORKSPACE.

diff --git a/WORKSPACE b/WORKSPACE
index 1d9d5e4..a47d97e 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -30,7 +30,7 @@ load("//python:versions.bzl", "MINOR_MAPPING")
 
 python_register_multi_toolchains(
     name = "python",
-    default_version = MINOR_MAPPING.values()[-1],
+    default_version = "3.10.9",
     python_versions = MINOR_MAPPING.values(),
 )

Install pygame using the python interpreter used by bazel.
~/.cache/bazel/_bazel_<user>/<hash>/execroot/rules_python/bazel-out/k8-fastbuild/bin/gazelle/std_modules.runfiles/python_3_10_9_x86_64-unknown-linux-gnu/bin/python3 -m pip install pygame

Pass pygame to the std_modules script:
echo "pygame" | bazel run //gazelle:std_modules

Expected:

Output should be false.

Actual:

Output is

pygame 2.1.2 (SDL 2.0.16, Python 3.10.9)
Hello from the pygame community. https://www.pygame.org/contribute.html
true

Cause: pygame/pygame#542

However, this could be any module that prints to stdout upon import of the module.

🔥 Exception or Error

Here is the exception gazelle throws:

gazelle: Error checking if standard module:  strconv.ParseBool: parsing "pygame 2.1.2 (SDL 2.0.16, Python 3.10.6)": invalid syntax

🌍 Your Environment

Operating System:

  
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic
  

Output of bazel version:

  
Bazelisk version: v1.10.1
Build label: 5.3.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Sep 19 17:28:49 2022 (1663608529)
Build timestamp: 1663608529
Build timestamp as int: 1663608529

  

Rules_python version:

  
   v0.13.0
  

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions