From a46b206809812101ce68bcdca66fd52fc02681ae Mon Sep 17 00:00:00 2001 From: hunshcn Date: Fri, 17 May 2024 11:42:30 +0800 Subject: [PATCH] optimize code style, according to review --- gazelle/MODULE.bazel | 4 ++-- gazelle/def.bzl | 8 -------- gazelle/python/extensions.bzl | 5 +++++ gazelle/python/private/BUILD.bazel | 0 gazelle/python/private/extensions.bzl | 9 +++++++++ gazelle/python/python_test.go | 9 +++------ 6 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 gazelle/python/extensions.bzl create mode 100644 gazelle/python/private/BUILD.bazel create mode 100644 gazelle/python/private/extensions.bzl diff --git a/gazelle/MODULE.bazel b/gazelle/MODULE.bazel index 410e932836..1829d248b2 100644 --- a/gazelle/MODULE.bazel +++ b/gazelle/MODULE.bazel @@ -28,9 +28,9 @@ use_repo( "org_golang_x_sync", ) -non_module_deps = use_extension("//:def.bzl", "non_module_deps") +python_stdlib_list = use_extension("//python:extensions.bzl", "python_stdlib_list") use_repo( - non_module_deps, + python_stdlib_list, "python_stdlib_list_3_10", "python_stdlib_list_3_11", "python_stdlib_list_3_12", diff --git a/gazelle/def.bzl b/gazelle/def.bzl index a9fbb0f436..084b5a4a05 100644 --- a/gazelle/def.bzl +++ b/gazelle/def.bzl @@ -15,13 +15,5 @@ """This module contains the Gazelle runtime dependencies for the Python extension. """ -load("@bazel_skylib//lib:modules.bzl", "modules") -load(":deps.bzl", "python_stdlib_list_deps") - GAZELLE_PYTHON_RUNTIME_DEPS = [ ] - -non_module_deps = modules.as_extension( - python_stdlib_list_deps, - doc = "This extension registers python stdlib list dependencies.", -) diff --git a/gazelle/python/extensions.bzl b/gazelle/python/extensions.bzl new file mode 100644 index 0000000000..8d339c0c7b --- /dev/null +++ b/gazelle/python/extensions.bzl @@ -0,0 +1,5 @@ +"python_stdlib_list module extension for use with bzlmod" + +load("//python/private:extensions.bzl", _python_stdlib_list = "python_stdlib_list") + +python_stdlib_list = _python_stdlib_list diff --git a/gazelle/python/private/BUILD.bazel b/gazelle/python/private/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gazelle/python/private/extensions.bzl b/gazelle/python/private/extensions.bzl new file mode 100644 index 0000000000..5de071361c --- /dev/null +++ b/gazelle/python/private/extensions.bzl @@ -0,0 +1,9 @@ +"python_stdlib_list module extension for use with bzlmod" + +load("@bazel_skylib//lib:modules.bzl", "modules") +load("//:deps.bzl", "python_stdlib_list_deps") + +python_stdlib_list = modules.as_extension( + python_stdlib_list_deps, + doc = "This extension registers python stdlib list dependencies.", +) diff --git a/gazelle/python/python_test.go b/gazelle/python/python_test.go index 47b845a5c6..dd8c2411f1 100644 --- a/gazelle/python/python_test.go +++ b/gazelle/python/python_test.go @@ -41,10 +41,8 @@ const ( gazelleBinaryName = "gazelle_binary" ) -var gazellePath string - func TestGazelleBinary(t *testing.T) { - gazellePath = mustFindGazelle() + gazellePath := mustFindGazelle() tests := map[string][]bazel.RunfileEntry{} runfiles, err := bazel.ListRunfiles() @@ -67,13 +65,12 @@ func TestGazelleBinary(t *testing.T) { 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