feat(gazelle): pure golang helper (#1895)
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
diff --git a/gazelle/python/python_test.go b/gazelle/python/python_test.go
index 617b3f8..dd8c241 100644
--- a/gazelle/python/python_test.go
+++ b/gazelle/python/python_test.go
@@ -31,7 +31,6 @@
"time"
"github.com/bazelbuild/bazel-gazelle/testtools"
- "github.com/bazelbuild/rules_go/go/runfiles"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/ghodss/yaml"
)
@@ -42,9 +41,8 @@
gazelleBinaryName = "gazelle_binary"
)
-var gazellePath = mustFindGazelle()
-
func TestGazelleBinary(t *testing.T) {
+ gazellePath := mustFindGazelle()
tests := map[string][]bazel.RunfileEntry{}
runfiles, err := bazel.ListRunfiles()
@@ -67,13 +65,12 @@
if len(tests) == 0 {
t.Fatal("no tests found")
}
-
for testName, files := range tests {
- testPath(t, testName, files)
+ testPath(t, gazellePath, testName, files)
}
}
-func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
+func testPath(t *testing.T, gazellePath, name string, files []bazel.RunfileEntry) {
t.Run(name, func(t *testing.T) {
t.Parallel()
var inputs, goldens []testtools.FileSpec
@@ -160,11 +157,6 @@
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Dir = workspaceRoot
- helperScript, err := runfiles.Rlocation("rules_python_gazelle_plugin/python/helper")
- if err != nil {
- t.Fatalf("failed to initialize Python helper: %v", err)
- }
- cmd.Env = append(os.Environ(), "GAZELLE_PYTHON_HELPER="+helperScript)
if err := cmd.Run(); err != nil {
var e *exec.ExitError
if !errors.As(err, &e) {