Skip to content

fix(gazelle): embed default stdlib list for non-Bazel Go builds - #4197

Open
udaya2899 wants to merge 1 commit into
bazel-contrib:mainfrom
udaya2899:fix/gazelle-stdlib-embed
Open

udaya2899 wants to merge 1 commit into
bazel-contrib:mainfrom
udaya2899:fix/gazelle-stdlib-embed

Conversation

@udaya2899

@udaya2899 udaya2899 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

gazelle/python/std_modules.go previously used //go:embed stdlib_list.txt, where stdlib_list.txt only existed as a Bazel copy_file output from @python_stdlib_list.

Building, listing, or testing github.com/bazel-contrib/rules_python/gazelle/python directly with standard Go tooling (go build, go test, go list -deps, or go install for standalone Gazelle binaries in pre-commit hooks) failed with pattern stdlib_list.txt: no matching files found, and running bazel run //:gazelle inside gazelle/ emitted a missing-file warning on std_modules.go.

Check in the default standard library module list at gazelle/python/stdlib_list/default.txt (verified via diff_test against @python_stdlib_list//:stdlib_list/lists/3.14.txt), change the Bazel copy_file output to stdlib_list/selected.txt, and embed stdlib_list/*.txt via embed.FS.

At initialization, loadStdModules prefers stdlib_list/selected.txt when present (preserving Bazel's python_version select() behavior) and falls back to stdlib_list/default.txt for non-Bazel Go builds.

Fixes #3821

`gazelle/python/std_modules.go` previously used `//go:embed stdlib_list.txt`, where `stdlib_list.txt` only existed as a Bazel `copy_file` output from `@python_stdlib_list`. Building, listing, or testing `github.com/bazel-contrib/rules_python/gazelle/python` directly with standard Go tooling (`go build`, `go test`, `go list -deps`, or `go install` for standalone Gazelle binaries in pre-commit/prek hooks) failed with `pattern stdlib_list.txt: no matching files found`, and running `bazel run //:gazelle` inside `gazelle/` emitted a missing-file warning on `std_modules.go`.

Check in the default standard library module list at `gazelle/python/stdlib_list/default.txt` (verified via `diff_test` against `@python_stdlib_list//:stdlib_list/lists/3.14.txt`), change the Bazel `copy_file` output to `stdlib_list/selected.txt`, and embed `stdlib_list/*.txt` via `embed.FS`. At initialization, `loadStdModules` prefers `stdlib_list/selected.txt` when present (preserving Bazel's `python_version` `select()` behavior) and falls back to `stdlib_list/default.txt` for non-Bazel Go builds.

Fixes bazel-contrib#3821
@udaya2899

Copy link
Copy Markdown
Contributor Author

827 lines of this huge looking PR is just the contents of the txt file. For prior art, https://github.com/EngFlow/gazelle_cc/blob/main/language/cc/bzldep-index.json checks-in a huge index json file

@aignas

aignas commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

github.com/bazel-contrib/rules_python/gazelle/python directly with standard Go tooling

What APIs are you using? What are you building? I would have thought that there would be very little need to do this. :)

@udaya2899

Copy link
Copy Markdown
Contributor Author

What APIs are you using? What are you building?

We want to run gazelle pre-push as a hook. We want to make sure people don't push code that doesn't adhere with gazelle. Currently the only way to do it is with bazel run //:gazelle for us, but gazelle being built with Go and having Go based language extensions, we can simply configure a go-based build which is way faster without the bazel setup costs. Fast enough to run pre-push atleast.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

go:embed stdlib_list.txt file in gazelle/python/std_modules.go is missing

2 participants